File Coverage

blib/lib/Sim/Agent/LLM/Ollama.pm
Criterion Covered Total %
statement 6 26 23.0
branch 0 16 0.0
condition n/a
subroutine 2 3 66.6
pod 0 1 0.0
total 8 46 17.3


line stmt bran cond sub pod time code
1             package Sim::Agent::LLM::Ollama;
2              
3 1     1   7 use strict;
  1         3  
  1         39  
4 1     1   5 use warnings;
  1         3  
  1         600  
5              
6             sub call_model
7             {
8              
9 0     0 0   my (%args) = @_;
10              
11 0 0         my $model = $args{model} or die "model required";
12 0 0         my $prompt = $args{prompt} or die "prompt required";
13 0 0         my $agent_dir = $args{agent_dir} or die "agent_dir required";
14 0 0         my $call_id = $args{call_id} or die "call_id required";
15              
16             # SECURITY: validate model
17 0 0         die "Invalid model name"
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 0         open my $pfh, '>', $prompt_file
24             or die "Cannot write $prompt_file";
25 0           print {$pfh} $prompt;
  0            
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 0         die "Ollama call failed (exit=$exit)" if $exit != 0;
32              
33 0 0         open my $ofh, '<', $output_file
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;
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 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.
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