| 1 | package Sim::Agent::LLM::Ollama; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | sub call_model | ||||||||||
| 7 | 0 | ▶ | { | ||||||||
|
Subroutine
call_model: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||
| 8 | |||||||||||
| 9 | 0 | my (%args) = @_; | |||||||||
| 10 | |||||||||||
| 11 | 0 | ▶ | my $model = $args{model} or die "model required"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 12 | 0 | ▶ | my $prompt = $args{prompt} or die "prompt required"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | 0 | ▶ | my $agent_dir = $args{agent_dir} or die "agent_dir required"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | ▶ | my $call_id = $args{call_id} or die "call_id required"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | |||||||||||
| 16 | # SECURITY: validate model | ||||||||||
| 17 | 0 | ▶ | die "Invalid model name" | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | unless $model =~ /^[\w\.\:\-]+$/; | ||||||||||
| 19 | |||||||||||
| 20 | 0 | my $prompt_file = sprintf("%s/%03d_prompt.txt", $agent_dir, $call_id); | |||||||||
| 21 | 0 | my $output_file = sprintf("%s/%03d_output.txt", $agent_dir, $call_id); | |||||||||
| 22 | |||||||||||
| 23 | 0 | ▶ | open my $pfh, '>', $prompt_file | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | or die "Cannot write $prompt_file"; | ||||||||||
| 25 | 0 | print {$pfh} $prompt; | |||||||||
| 26 | 0 | close $pfh; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $cmd = "ollama run $model < $prompt_file > $output_file"; | |||||||||
| 29 | |||||||||||
| 30 | 0 | my $exit = system($cmd); | |||||||||
| 31 | 0 | ▶ | die "Ollama call failed (exit=$exit)" if $exit != 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | open my $ofh, '<', $output_file | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | or die "Cannot read $output_file"; | ||||||||||
| 35 | 0 | local $/; | |||||||||
| 36 | 0 | my $output = <$ofh>; | |||||||||
| 37 | 0 | close $ofh; | |||||||||
| 38 | |||||||||||
| 39 | 0 | return $output; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 1 | 1; | |||||||||
| 43 | |||||||||||
| 44 | =pod | ||||||||||
| 45 | |||||||||||
| 46 | =head1 NAME | ||||||||||
| 47 | |||||||||||
| 48 | Sim::Agent::LLM::Ollama - LLM adapter using the 'ollama' CLI | ||||||||||
| 49 | |||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||
| 51 | |||||||||||
| 52 | Invokes C<ollama run MODEL> using prompt/output text files stored under the run directory. | ||||||||||
| 53 | |||||||||||
| 54 | This adapter is intentionally minimal and avoids SDK dependencies. | ||||||||||
| 55 | |||||||||||
| 56 | See L<Sim::Agent>. | ||||||||||
| 57 | |||||||||||
| 58 | =head1 AUTHOR | ||||||||||
| 59 | |||||||||||
| 60 | Gian Luca Brunetti (2026), gianluca.brunetti@gmail.com | ||||||||||
| 61 | |||||||||||
| 62 | =head1 LICENSE | ||||||||||
| 63 | |||||||||||
| 64 | The GNU General Public License v3.0 | ||||||||||
| 65 | |||||||||||
| 66 | =cut | ||||||||||
| 67 | |||||||||||