| 1 | package Langertha::Manifest::Builder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Build a provider manifest from configured engines (offline, never copies a secret) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Carp qw( carp croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Scalar::Util qw( blessed ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use Langertha::Manifest; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | has provider_id => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | writer => '_set_provider_id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | predicate => 'has_provider_id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | has issuer => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | writer => '_set_issuer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | predicate => 'has_issuer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 35 | ▶ | has extensions => ( is => 'ro', isa => 'HashRef', default => sub { {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 35 | ▶ | has _endpoints => ( is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 35 | ▶ | has _auth => ( is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 35 | ▶ | has _models => ( is => 'ro', default => sub { [] } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # The capabilities a model entry may claim: exactly those that describe a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # CHAT CALL to that model at that endpoint -- what the request may carry and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # what the reply can be. Everything else engine_capabilities reports is left | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # out on purpose: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # - other operations of the engine (embedding, transcription, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # image_generation) are not facts about a chat model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # - client-side or server-management features (runtime_metrics is | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Langertha's own Prometheus scrape, prefix_caching the self-hosted | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # cache knobs, keep_alive Ollama's model residency, cached_content | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Gemini's cache-resource lifecycle, context_size Ollama's server-side | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # num_ctx allocation) are not provider claims about a model either, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # would be wrong behind a proxy's public URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # - stream_usage says Langertha's own stream request asks for the usage | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # (stream_options.include_usage, ADR 0038): a request-builder fact, and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # behind a proxy whether a stream reports usage is the proxy's behavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # - tool_result_images / tool_result_pdf say how Langertha serializes a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # tool's image or PDF on the engine's own wire (ADR 0039): behind a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # proxy's public URL that is the proxy's behavior too. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # A capability added to %ROLE_TO_CAPS later is NOT published until it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # added here (t/96_manifest_builder.t forces that decision). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 6 | my @MODEL_CAPABILITIES = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | chat | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | streaming | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | tools_native tools_hermes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | tool_choice_auto tool_choice_any tool_choice_none tool_choice_named | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | parallel_tool_use | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | response_format_json_object response_format_json_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | reasoning_effort thinking_budget | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | temperature seed | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | system_prompt response_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | prompt_cache prompt_cache_key | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | server_tools | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | image_input | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | my %MODEL_CAPABILITY = map { $_ => 1 } @MODEL_CAPABILITIES; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub model_capabilities { return @MODEL_CAPABILITIES } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_capabilities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # Most specific first: OpenAIResponses isa OpenAI isa OpenAIBase. A code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # value decides within a family. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | my @DIALECT_BY_CLASS = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | [ 'Langertha::Engine::Perplexity' => 'perplexity-agent' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | [ 'Langertha::Engine::OpenAIResponses' => 'responses' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | [ 'Langertha::Engine::OpenAIBase' => 'openai-chat' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # Same Messages envelope, two wire variants: first-party Anthropic sends | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # structured output as native output_config.format, the /anthropic shims | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # emulate it with a synthetic tool + forced tool_choice. The engine's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # predicate (Role::AnthropicCompatible) tells them apart. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 11 | ▶ | [ 'Langertha::Engine::AnthropicBase' => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | $_[0]->_native_structured_output ? 'anthropic' : 'anthropic-compat' } ], | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | [ 'Langertha::Engine::Gemini' => 'gemini' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | [ 'Langertha::Engine::Ollama' => 'ollama' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | [ 'Langertha::Engine::AKI' => 'aki' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | [ 'Langertha::Engine::LMStudio' => 'lmstudio' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 52 | ▶ | sub dialect_for_engine { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dialect_for_engine: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 52 | my ( $class, $engine ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 52 | for my $row (@DIALECT_BY_CLASS) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 184 | my ( $isa, $dialect ) = @$row; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 184 | ▶ | next unless $engine->isa($isa); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 52 | ▶ | return ref $dialect eq 'CODE' ? $dialect->($engine) : $dialect; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # The inverse of @DIALECT_BY_CLASS: per dialect the one generic class that | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # takes the endpoint's base_url as its `url` (not a vendor subclass). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | my %ENGINE_CLASS_BY_DIALECT = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 'openai-chat' => 'Langertha::Engine::OpenAI', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 'responses' => 'Langertha::Engine::OpenAIResponses', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 'perplexity-agent' => 'Langertha::Engine::Perplexity', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 'anthropic' => 'Langertha::Engine::Anthropic', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 'anthropic-compat' => 'Langertha::Engine::AnthropicBase', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 'gemini' => 'Langertha::Engine::Gemini', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 'ollama' => 'Langertha::Engine::Ollama', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 'aki' => 'Langertha::Engine::AKI', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 'lmstudio' => 'Langertha::Engine::LMStudio', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 20 | ▶ | sub engine_class_for_dialect { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
engine_class_for_dialect: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | my ( $class, $dialect ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 20 | ▶ | return undef unless defined $dialect; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 19 | ▶ | my $engine_class = $ENGINE_CLASS_BY_DIALECT{$dialect} or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 18 | return use_module($engine_class); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Validation errors from the value objects are "...\n" strings without a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # location; re-raise them from the caller's perspective. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | sub _reraise { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reraise: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | my ($error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $message = blessed($error) && $error->can('message') ? $error->message : "$error"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($error) and $error->can("message")
MC/DC0%0/2
builtin::blessed($error) and $error->can("message")
builtin::blessed($error)
$error->can("message")
Truth table0%0/3
A and B
A= builtin::blessed($error)B= $error->can("message")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $message =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | croak $message; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 31 | ▶ | sub from_engine { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_engine: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 31 | my ( $class, $engine, %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | my $self = $class->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 31 | ▶ | map { exists $opt{$_} ? ( $_ => delete $opt{$_} ) : () } qw( provider_id issuer extensions ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 31 | $self->add_engine( $engine, %opt ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 28 | return $self->manifest; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 38 | ▶ | sub add_engine { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_engine: called CC=31 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 38 | my ( $self, $engine, %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 38 | ▶ | croak 'Langertha::Manifest::Builder: add_engine needs a chat engine (an object' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%4/8
builtin::blessed($engine) and $engine->can("does") and $engine->does("Langertha::Role::Chat")
builtin::blessed($engine) and $engine->can("does")
ref $engine || 'a non-object'
MC/DC33%1/3
builtin::blessed($engine) and $engine->can("does") and $engine->does("Langertha::Role::Chat")
builtin::blessed($engine)
$engine->can("does")
$engine->does("Langertha::Role::Chat")
MC/DC0%0/1
ref $engine || 'a non-object'
ref $engine
Truth table50%2/4
A and B and C
A= builtin::blessed($engine)B= $engine->can("does")C= $engine->does("Langertha::Role::Chat")
Truth table50%1/2
A
A= ref $engine
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | . ' composing Langertha::Role::Chat); ' . ( ref($engine) || 'a non-object' ) . ' is not one' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | unless blessed($engine) && $engine->can('does') && $engine->does('Langertha::Role::Chat'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 36 | ▶ | my $dialect = $opt{dialect} // $self->dialect_for_engine($engine); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{"dialect"} // $self->dialect_for_engine($engine)
MC/DC0%0/2
$opt{"dialect"} // $self->dialect_for_engine($engine)
$opt{"dialect"}
$self->dialect_for_engine($engine)
Truth table33%1/3
A // B
A= $opt{"dialect"}B= $self->dialect_for_engine($engine)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 36 | ▶ | croak 'Langertha::Manifest::Builder: ' . ref($engine) . ' has no manifest dialect;' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | . ' pass dialect => ... to name one' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | unless defined $dialect; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 36 | ▶ | my $base_url = $opt{base_url} // ( $engine->can('url') ? $engine->url : undef ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$opt{"base_url"} // ($engine->can("url") ? $engine->url : undef)
MC/DC0%0/2
$opt{"base_url"} // ($engine->can("url") ? $engine->url : undef)
$opt{"base_url"}
($engine->can("url") ? $engine->url : undef)
Truth table66%2/3
A // B
A= $opt{"base_url"}B= ($engine->can("url") ? $engine->url : undef)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 36 | ▶ | croak 'Langertha::Manifest::Builder: ' . ref($engine) . ' has no url; pass base_url => ...' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | unless defined $base_url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # Everything lazy is read from a clone, so the caller's engine keeps its | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # unbuilt slots (and a model-less engine with `models` given never runs its | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # croaking default_model). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 36 | my $probe = _capability_clone($engine); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 36 | my @model_ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 36 | ▶ | if ( $opt{models} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 24 | @model_ids = @{ $opt{models} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 12 | my $model_id = eval { $probe->chat_model }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 12 | ▶ | croak 'Langertha::Manifest::Builder: cannot determine a model for ' . ref($engine) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | . '; pass models => [...]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # "default" is the self-hosted engines' placeholder for "whatever the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # server loaded" -- not a model id worth publishing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | ▶ | @model_ids = grep { defined && length && $_ ne 'default' } $model_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
defined $_ && length $_ && $_ ne 'default'
defined $_ and length $_
MC/DC33%1/3
defined $_ && length $_ && $_ ne 'default'
defined $_
length $_
$_ ne 'default'
Truth table50%2/4
A and B && C
A= defined $_B= length $_C= $_ ne 'default'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | carp 'Langertha::Manifest::Builder: ' . ref($engine) . ' has only the placeholder model ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 11 | ▶ | . q{'} . ( $model_id // '' ) . q{'} . "; endpoint '" . ( $opt{endpoint_id} // 'chat' ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$model_id // ""
$opt{"endpoint_id"} // "chat"
MC/DC0%0/1
$model_id // ""
$model_id
MC/DC0%0/1
$opt{"endpoint_id"} // "chat"
$opt{"endpoint_id"}
Truth table50%1/2
A
A= $model_id
Truth table50%1/2
A
A= $opt{"endpoint_id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | . q{' is published without models (pass models => [...] to list them)} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | unless @model_ids; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 35 | ▶ | my $auth_type = $opt{auth} // _auth_type_for($probe); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opt{"auth"} // _auth_type_for($probe)
MC/DC0%0/2
$opt{"auth"} // _auth_type_for($probe)
$opt{"auth"}
_auth_type_for($probe)
Truth table66%2/3
A // B
A= $opt{"auth"}B= _auth_type_for($probe)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 35 | my ( $auth_ref, $new_auth ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 35 | ▶ | if ( $auth_type ne 'none' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 28 | ▶ | $auth_ref = $opt{auth_id} // 'api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{"auth_id"} // "api"
MC/DC0%0/1
$opt{"auth_id"} // "api"
$opt{"auth_id"}
Truth table50%1/2
A
A= $opt{"auth_id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 28 | my ($existing) = grep { $_->id eq $auth_ref } @{ $self->_auth }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 28 | ▶ | if ($existing) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | croak "Langertha::Manifest::Builder: auth id '$auth_ref' already has type '" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | . $existing->type . q{'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | unless $existing->type eq $auth_type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 26 | ▶ | $new_auth = eval { Langertha::Manifest::Auth->new( id => $auth_ref, type => $auth_type ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 35 | ▶ | my $endpoint_id = $opt{endpoint_id} // 'chat'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{"endpoint_id"} // "chat"
MC/DC100%1/1
$opt{"endpoint_id"} // "chat"
$opt{"endpoint_id"}
Truth table100%2/2
A
A= $opt{"endpoint_id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 35 | ▶ | my $endpoint = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 35 | ▶ | Langertha::Manifest::Endpoint->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | id => $endpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | dialect => $dialect, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | base_url => $base_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ( defined $auth_ref ? ( auth_ref => $auth_ref ) : () ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 35 | $self->_check_new_endpoint($endpoint); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 33 | my @models; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 33 | for my $model_id (@model_ids) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 44 | ▶ | my $model = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 44 | Langertha::Manifest::Model->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | id => $model_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | endpoint_ref => $endpoint_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | capabilities => _capabilities_for( $engine, $model_id ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 44 | $self->_check_new_model( $model, @models ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 43 | push @models, $model; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # All checks passed: commit. A croak above leaves the builder unchanged. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 32 | ▶ | push @{ $self->_auth }, $new_auth if $new_auth; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 32 | push @{ $self->_endpoints }, $endpoint; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 32 | push @{ $self->_models }, @models; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 32 | ▶ | $self->_set_provider_id( _provider_id_for( ref $engine ) ) unless $self->has_provider_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 32 | ▶ | $self->_set_issuer( _origin_of($base_url) ) unless $self->has_issuer; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 32 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 37 | ▶ | sub _check_new_endpoint { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_new_endpoint: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 37 | my ( $self, $endpoint ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | croak "Langertha::Manifest::Builder: duplicate endpoint id '" . $endpoint->id . q{'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 37 | ▶ | if grep { $_->id eq $endpoint->id } @{ $self->_endpoints }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 35 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 46 | ▶ | sub _check_new_model { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_check_new_model: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 46 | my ( $self, $model, @pending ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | croak "Langertha::Manifest::Builder: duplicate model '" . $model->id . "' on endpoint '" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | . $model->endpoint_ref . q{'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 18 | ▶ | if grep { $_->id eq $model->id && $_->endpoint_ref eq $model->endpoint_ref } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->id eq $model->id && $_->endpoint_ref eq $model->endpoint_ref
MC/DC100%2/2
$_->id eq $model->id && $_->endpoint_ref eq $model->endpoint_ref
$_->id eq $model->id
$_->endpoint_ref eq $model->endpoint_ref
Truth table100%3/3
A && B
A= $_->id eq $model->idB= $_->endpoint_ref eq $model->endpoint_ref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 46 | ▶ | @{ $self->_models }, @pending; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 44 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 2 | ▶ | sub add_endpoint { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_endpoint: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | my $endpoint = eval { Langertha::Manifest::Endpoint->new(%args) } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 2 | $self->_check_new_endpoint($endpoint); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | push @{ $self->_endpoints }, $endpoint; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | sub add_auth { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_auth: called CC=3 SCAR=12.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | ▶ | my $auth = eval { Langertha::Manifest::Auth->new(%args) } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | croak "Langertha::Manifest::Builder: duplicate auth id '" . $auth->id . q{'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | ▶ | if grep { $_->id eq $auth->id } @{ $self->_auth }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | push @{ $self->_auth }, $auth; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | sub add_model { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_model: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 2 | ▶ | my $model = eval { Langertha::Manifest::Model->new(%args) } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | $self->_check_new_model($model); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | push @{ $self->_models }, $model; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 33 | ▶ | sub manifest { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
manifest: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 33 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 33 | ▶ | croak 'Langertha::Manifest::Builder: no provider_id (add an engine or pass provider_id)' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | unless $self->has_provider_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 33 | ▶ | croak 'Langertha::Manifest::Builder: no issuer (add an engine or pass issuer)' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | unless $self->has_issuer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 33 | ▶ | my $manifest = eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | Langertha::Manifest->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | provider_id => $self->provider_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | issuer => $self->issuer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 33 | endpoints => [ @{ $self->_endpoints } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 33 | auth => [ @{ $self->_auth } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 33 | models => [ @{ $self->_models } ], | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | extensions => $self->extensions, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } or _reraise($@); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 33 | return $manifest; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 29 | ▶ | sub _provider_id_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_provider_id_for: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 29 | my ($class_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 29 | ( my $name = $class_name ) =~ s/\A.*::Engine:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 29 | $name =~ s/\A.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 29 | return lc $name; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 29 | ▶ | sub _origin_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_origin_of: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 29 | my ($url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 29 | my $uri = URI->new($url); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 29 | ▶ | return $url unless $uri->can('host') && $uri->can('port'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$uri->can("host") and $uri->can("port")
MC/DC0%0/2
$uri->can("host") and $uri->can("port")
$uri->can("host")
$uri->can("port")
Truth table33%1/3
A and B
A= $uri->can("host")B= $uri->can("port")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 29 | my $origin = $uri->scheme . '://' . $uri->host; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 29 | ▶ | $origin .= ':' . $uri->port if $uri->port != $uri->default_port; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 29 | return $origin; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # $probe is a clone: reading the lazy api_key builds it there, not on the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # caller's engine. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 34 | ▶ | sub _auth_type_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_auth_type_for: called CC=7 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 34 | my ($probe) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 34 | ▶ | return 'api_key' if $probe->can('api_key_required') && $probe->api_key_required; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$probe->can("api_key_required") and $probe->api_key_required
MC/DC50%1/2
$probe->can("api_key_required") and $probe->api_key_required
$probe->can("api_key_required")
$probe->api_key_required
Truth table66%2/3
A and B
A= $probe->can("api_key_required")B= $probe->api_key_required
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Optional key: announce the mechanism only when one is configured. Only | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # definedness is inspected; the value is dropped on the spot. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 13 | ▶ | return 'none' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$probe->can("api_key_env") and defined $probe->api_key_env and $probe->can("api_key")
$probe->can("api_key_env") and defined $probe->api_key_env
MC/DC0%0/3
$probe->can("api_key_env") and defined $probe->api_key_env and $probe->can("api_key")
$probe->can("api_key_env")
defined $probe->api_key_env
$probe->can("api_key")
Truth table25%1/4
A and B and C
A= $probe->can("api_key_env")B= defined $probe->api_key_envC= $probe->can("api_key")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | unless $probe->can('api_key_env') && defined $probe->api_key_env && $probe->can('api_key'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 13 | my $configured = defined( scalar eval { $probe->api_key } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 13 | ▶ | return $configured ? 'api_key' : 'none'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 44 | ▶ | sub _capabilities_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capabilities_for: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 44 | my ( $engine, $model_id ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # engine_capabilities is model-scoped (ADR 0019 layer 3 and model-aware | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # `around engine_capabilities`, e.g. Gemini): evaluate it on an in-memory | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # clone whose chat_model is this model. The caller's engine is not read | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # for its chat_model and not touched. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 44 | my $probe = _capability_clone( $engine, chat_model => $model_id ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 44 | my $caps = $probe->engine_capabilities; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 44 | ▶ | return { map { $_ => 1 } grep { $caps->{$_} && $MODEL_CAPABILITY{$_} } keys %$caps }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$$caps{$_} && $MODEL_CAPABILITY{$_}
MC/DC50%1/2
$$caps{$_} && $MODEL_CAPABILITY{$_}
$$caps{$_}
$MODEL_CAPABILITY{$_}
Truth table66%2/3
A && B
A= $$caps{$_}B= $MODEL_CAPABILITY{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # clone_object copies every slot already set, so a tool_wire_format the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # builder made for the source engine's chat_model would ride along into a | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # probe for another model (karr k251). The probe drops a builder-made tag and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # resolves it again for its own chat_model; a constructor tag is kept. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 80 | ▶ | sub _capability_clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_capability_clone: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 80 | my ( $engine, %params ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 80 | my $probe = $engine->meta->clone_object( $engine, %params ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 80 | ▶ | $probe->_reset_derived_tool_wire_format if $probe->can('_reset_derived_tool_wire_format'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 80 | return $probe; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||