| 1 | package Langertha::Role::KeepAlive; | ||||||||||
| 2 | # ABSTRACT: Role for engines that support keep-alive duration | ||||||||||
| 3 | 57 | our $VERSION = '0.505'; | |||||||||
| 4 | 57 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 57 | has keep_alive => ( | |||||||||
| 7 | isa => 'Str', | ||||||||||
| 8 | is => 'ro', | ||||||||||
| 9 | predicate => 'has_keep_alive', | ||||||||||
| 10 | ); | ||||||||||
| 11 | |||||||||||
| 12 | |||||||||||
| 13 | 57 | has no_keep_alive => ( | |||||||||
| 14 | isa => 'Bool', | ||||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | default => 0, | ||||||||||
| 17 | ); | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | 139 | ▶ | sub get_keep_alive { | ||||||||
|
Subroutine
get_keep_alive: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||
| 21 | 139 | my ( $self ) = @_; | |||||||||
| 22 | 139 | ▶ | return 0 if $self->no_keep_alive; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 135 | ▶ | return undef unless $self->has_keep_alive; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 57 | 1; | |||||||||
| 33 | |||||||||||
| 34 | __END__ | ||||||||||