blib/lib/Langertha/Role/KeepAlive.pm

filter: Statementstmt 100% 12 / 12 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod 100% 1 / 1 totaltotal 100% 21 / 21 CC 4 SCAR 12.2
CC
4
Cov
100%
get_keep_alive
4.0
BEGIN
1.0
CRAP 3.4
« blib/lib/Langertha/Role/HermesTools.pm ↑ Summary blib/lib/Langertha/PromptCache.pm »
1 package Langertha::Role::KeepAlive;
2 # ABSTRACT: Role for engines that support keep-alive duration
3 53 our $VERSION = '0.503';
4 53 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 53 has keep_alive => (
7 isa => 'Str',
8 is => 'ro',
9 predicate => 'has_keep_alive',
10 );
11  
12  
13 53 has no_keep_alive => (
14 isa => 'Bool',
15 is => 'ro',
16 default => 0,
17 );
18  
19  
20 131 ▶sub get_keep_alive {
Subroutine get_keep_alive: called CC=4 SCAR=13.9
Pod documented
21 131 my ( $self ) = @_;
22 131 ▶ return 0 if $self->no_keep_alive;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_keep_alive 4 127 131
23 127 ▶ return undef unless $self->has_keep_alive;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_keep_alive 93 34 127
24 34 my $keep_alive = $self->keep_alive;
25 # Ollama reads a JSON number as seconds (negative = forever) but parses a
26 # JSON string as a Go duration, which needs a unit: "-1" is a 400 (k333).
27 34 ▶ return $keep_alive =~ /\A-?\d+(?:\.\d+)?\z/ ? 0 + $keep_alive : $keep_alive;
Branch: 1 branch
BranchTrueFalseTotal
$keep_alive =~ /\A-?\d+(?:\.\d+)?\z/ ? : 20 14 34
28 }
29  
30  
31  
32 53 1;
33  
34 __END__
35  
36 =pod
37  
38 =encoding UTF-8
39  
40 =head1 NAME
41  
42 Langertha::Role::KeepAlive - Role for engines that support keep-alive duration
43  
44 =head1 VERSION
45  
46 version 0.503
47  
48 =head2 keep_alive
49  
50 keep_alive => '5m'
51 keep_alive => -1 # keep forever
52 keep_alive => 300 # seconds
53  
54 Controls how long the engine keeps the model loaded in memory after a request.
55 Accepts a duration string with a unit such as C<5m> or C<1h>, or a plain
56 number of seconds (C<300> or C<'300'>; a negative number such as C<-1> keeps
57 the model loaded forever). A plain number, also when given as a string, is
58 sent as a JSON number; a duration string stays a string. When not set, the
59 engine uses its own default.
60  
61 See also C<no_keep_alive> for explicitly unloading the model after each request.
62  
63 =head2 no_keep_alive
64  
65 no_keep_alive => 1
66  
67 When true, the model is unloaded from memory immediately after each request.
68 Equivalent to setting C<keep_alive =E<gt> 0> but more explicit.
69  
70 =head2 get_keep_alive
71  
72 Returns the effective keep-alive value: the number C<0> if C<no_keep_alive> is
73 set, the C<keep_alive> value if provided (a plain number as a number, see
74 L</keep_alive>), or C<undef> if neither is set (letting the engine use its
75 default).
76  
77 Composing this role advertises the C<keep_alive> capability, so callers can
78 dispatch on C<< $engine->supports('keep_alive') >> — see
79 L<Langertha::Role::Capabilities>.
80  
81 =head1 SEE ALSO
82  
83 =over
84  
85 =item * L<Langertha::Engine::Ollama> - Engine that composes this role
86  
87 =item * L<Langertha::Role::Capabilities> - Registry that turns this role into the C<keep_alive> flag
88  
89 =back
90  
91 =head1 SUPPORT
92  
93 =head2 Issues
94  
95 Please report bugs and feature requests on GitHub at
96 L<https://github.com/Getty/langertha/issues>.
97  
98 =head2 IRC
99  
100 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
101  
102 =head1 CONTRIBUTING
103  
104 Contributions are welcome! Please fork the repository and submit a pull request.
105  
106 =head1 AUTHOR
107  
108 Torsten Raudssus <getty@cpan.org>
109  
110 =head1 COPYRIGHT AND LICENSE
111  
112 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
113  
114 This is free software; you can redistribute it and/or modify it under
115 the same terms as the Perl 5 programming language system itself.
116  
117 =cut
« blib/lib/Langertha/Role/HermesTools.pm ↑ Summary blib/lib/Langertha/PromptCache.pm »