| 1 | package Langertha::ModelProbe; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Reads model-scoped capability facts from a provider's own model metadata | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 180 | our $VERSION = '0.503'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 180 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 180 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 180 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # The capabilities a probe may learn. Metadata that states more (Ollama's | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # "tools" / "thinking", OpenRouter's supported_parameters, LM Studio's | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # trained_for_tool_use) is deliberately not read yet: those flags drive the | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # chat_f rewrite matrix (ADR 0005), image_input is advisory (ADR 0032). | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 180 | my @PROBED_CAPABILITIES = qw( image_input ); | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 76 | ▶ | sub probed_capabilities { return @PROBED_CAPABILITIES } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
probed_capabilities: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 180 | my %FORMAT = ( | |||||||||||||||||||||||||||||||||||||||||
| 19 | openrouter => { method => 'GET', extract => \&_extract_openrouter, catalogue => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | mistral => { method => 'GET', extract => \&_extract_mistral, catalogue => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | lmstudio => { method => 'GET', extract => \&_extract_lmstudio, catalogue => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | tsystems => { method => 'GET', extract => \&_extract_tsystems, catalogue => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ollama => { method => 'POST', extract => \&_extract_ollama, per_model => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | llamacpp => { method => 'GET', extract => \&_extract_llamacpp }, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 257 | ▶ | sub _format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 257 | my ( $class, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 257 | ▶ | croak "Langertha::ModelProbe: format must be a string, not a reference" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | if ref $format; | ||||||||||||||||||||||||||||||||||||||||||
| 31 | croak "Langertha::ModelProbe: unknown model_metadata_format '" | ||||||||||||||||||||||||||||||||||||||||||
| 32 | . ( $format // '(undef)' ) . q{'} | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 257 | ▶ | unless defined $format && $FORMAT{$format}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
defined $format and $FORMAT{$format}
$format // "(undef)"
MC/DC50%1/2
defined $format and $FORMAT{$format}
defined $format
$FORMAT{$format}
MC/DC0%0/1
$format // "(undef)"
$format
Truth table66%2/3
A and B
A= defined $formatB= $FORMAT{$format}
Truth table50%1/2
A
A= $format
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 256 | return $FORMAT{$format}; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 59 | ▶ | sub is_known_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_known_format: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 59 | my ( $class, $format ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 59 | ▶ | return defined $format && !ref $format && exists $FORMAT{$format} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $format and not ref $format and exists $FORMAT{$format}
defined $format and not ref $format
MC/DC0%0/3
defined $format and not ref $format and exists $FORMAT{$format}
defined $format
not ref $format
exists $FORMAT{$format}
Truth table25%1/4
A and not(B) and C
A= defined $formatB= not ref $formatC= exists $FORMAT{$format}
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 59 | ▶ | sub http_method { return $_[0]->_format( $_[1] )->{method} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
http_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 59 | ▶ | sub per_model { return $_[0]->_format( $_[1] )->{per_model} ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
per_model: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 13 | ▶ | sub is_catalogue { return $_[0]->_format( $_[1] )->{catalogue} ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_catalogue: called CC=2 SCAR=6.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 63 | ▶ | sub extract { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 63 | my ( $class, $format, $data, $models ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 63 | my $spec = $class->_format($format); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 62 | ▶ | return {} unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 61 | ▶ | my $facts = $spec->{extract}->( $data, [ grep { _id_ok($_) } @{ ref $models eq q{ARRAY} ? $models : [] } ] ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 61 | return $facts; | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 91 | ▶ | sub server_root_url { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server_root_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 91 | my ( $class, $url ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 91 | my $uri = URI->new($url); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 91 | my $path = $uri->path; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 91 | $path =~ s{/v1/?\z}{}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 91 | $path =~ s{/\z}{}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 91 | $uri->path($path); | |||||||||||||||||||||||||||||||||||||||||
| 65 | 91 | return $uri->as_string; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 63 | ▶ | sub lookup_ids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lookup_ids: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 63 | my ( $class, $format, $model ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 63 | $class->_format($format); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 63 | ▶ | return () unless _id_ok($model); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 63 | my @ids = ($model); | |||||||||||||||||||||||||||||||||||||||||
| 74 | 63 | ▶ | if ( $format eq 'ollama' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Ollama names without a tag mean :latest (llava == llava:latest). | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 10 | ▶ | if ( $model =~ /\A(.+):latest\z/ ) { push @ids, $1 } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | elsif ( $model !~ /:/ ) { push @ids, "$model:latest" } | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ( $format eq 'openrouter' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | # A routing variant (:online, :free, :nitro, :floor, :thinking, ...) is | ||||||||||||||||||||||||||||||||||||||||||
| 81 | # the base model's capabilities; used only when the variant itself is | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # not listed. | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 21 | ▶ | push @ids, $1 if $model =~ m{\A([^:]+/[^:]+):[A-Za-z0-9._-]+\z}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 63 | return @ids; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | # Only a non-empty plain string is a model id; a reference or an empty | ||||||||||||||||||||||||||||||||||||||||||
| 90 | # string is never a store key. | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 237 | ▶ | sub _id_ok { return defined $_[0] && !ref $_[0] && length $_[0] ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_id_ok: called CC=4 SCAR=13.9
Branch: 1 branch
Condition100%6/6
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0] and not ref $_[0]
MC/DC100%3/3
defined $_[0] and not ref $_[0] and length $_[0]
defined $_[0]
not ref $_[0]
length $_[0]
Truth table100%4/4
A and not(B) and C
A= defined $_[0]B= not ref $_[0]C= length $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 90 | ▶ | sub _bool { return $_[0] ? 1 : 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bool: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 16 | ▶ | sub _extract_openrouter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_openrouter: called CC=9 SCAR=22.3
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | 16 | my ( $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | 16 | my %facts; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 16 | ▶ | for my $model ( @{ ref $data->{data} eq 'ARRAY' ? $data->{data} : [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 25 | ▶ | next unless ref $model eq 'HASH' && ref $model->{architecture} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $model eq "HASH" and ref $model->{"architecture"} eq "HASH"
MC/DC50%1/2
ref $model eq "HASH" and ref $model->{"architecture"} eq "HASH"
ref $model eq "HASH"
ref $model->{"architecture"} eq "HASH"
Truth table66%2/3
A and B
A= ref $model eq "HASH"B= ref $model->{"architecture"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 22 | my $in = $model->{architecture}{input_modalities}; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 22 | ▶ | next unless ref $in eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 22 | ▶ | my $vision = _bool( grep { defined && $_ eq 'image' } @$in ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ eq 'image'
MC/DC50%1/2
defined $_ && $_ eq 'image'
defined $_
$_ eq 'image'
Truth table66%2/3
A && B
A= defined $_B= $_ eq 'image'
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 22 | for my $id ( grep { _id_ok($_) } $model->{id}, $model->{canonical_slug} ) { | |||||||||||||||||||||||||||||||||||||||||
| 104 | 41 | ▶ | $facts{$id} //= { image_input => $vision }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$facts{$id} //= {"image_input", $vision}
MC/DC100%1/1
$facts{$id} //= {"image_input", $vision}
$facts{$id}
Truth table100%2/2
A
A= $facts{$id}
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | 16 | return \%facts; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub _extract_mistral { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_mistral: called CC=11 SCAR=26.1
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | my ( $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | my ( %by_id, %by_alias ); | |||||||||||||||||||||||||||||||||||||||||
| 113 | 6 | ▶ | for my $model ( @{ ref $data->{data} eq 'ARRAY' ? $data->{data} : [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 17 | ▶ | next unless ref $model eq 'HASH' && ref $model->{capabilities} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $model eq "HASH" and ref $model->{"capabilities"} eq "HASH"
MC/DC0%0/2
ref $model eq "HASH" and ref $model->{"capabilities"} eq "HASH"
ref $model eq "HASH"
ref $model->{"capabilities"} eq "HASH"
Truth table33%1/3
A and B
A= ref $model eq "HASH"B= ref $model->{"capabilities"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 17 | ▶ | next unless exists $model->{capabilities}{vision}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 17 | my $fact = { image_input => _bool( $model->{capabilities}{vision} ) }; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 17 | ▶ | $by_id{ $model->{id} } = $fact if _id_ok( $model->{id} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 17 | ▶ | for my $alias ( @{ ref $model->{aliases} eq 'ARRAY' ? $model->{aliases} : [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 17 | ▶ | $by_alias{$alias} //= { %$fact } if _id_ok($alias); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$by_alias{$alias} //= {%$fact}
MC/DC0%0/1
$by_alias{$alias} //= {%$fact}
$by_alias{$alias}
Truth table50%1/2
A
A= $by_alias{$alias}
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | return { %by_alias, %by_id }; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 10 | ▶ | sub _extract_lmstudio { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_lmstudio: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 10 | my ( $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | my %facts; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 10 | ▶ | for my $model ( @{ ref $data->{models} eq 'ARRAY' ? $data->{models} : [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 30 | ▶ | next unless ref $model eq 'HASH' && ref $model->{capabilities} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $model eq "HASH" and ref $model->{"capabilities"} eq "HASH"
MC/DC50%1/2
ref $model eq "HASH" and ref $model->{"capabilities"} eq "HASH"
ref $model eq "HASH"
ref $model->{"capabilities"} eq "HASH"
Truth table66%2/3
A and B
A= ref $model eq "HASH"B= ref $model->{"capabilities"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 20 | ▶ | next unless exists $model->{capabilities}{vision}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 20 | my $vision = _bool( $model->{capabilities}{vision} ); | |||||||||||||||||||||||||||||||||||||||||
| 132 | my @ids = ( $model->{key}, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | ▶ | map { ref $_ eq 'HASH' ? $_->{id} : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 20 | ▶ | @{ ref $model->{loaded_instances} eq 'ARRAY' ? $model->{loaded_instances} : [] } ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 20 | ▶ | $facts{$_} //= { image_input => $vision } for grep { _id_ok($_) } @ids; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$facts{$_} //= {"image_input", $vision}
MC/DC100%1/1
$facts{$_} //= {"image_input", $vision}
$facts{$_}
Truth table100%2/2
A
A= $facts{$_}
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 10 | return \%facts; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 4 | ▶ | sub _extract_tsystems { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_tsystems: called CC=10 SCAR=24.1
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 4 | my ( $data ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 4 | my %facts; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 4 | ▶ | for my $model ( @{ ref $data->{data} eq 'ARRAY' ? $data->{data} : [] } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 24 | ▶ | next unless ref $model eq 'HASH' && ref $model->{meta_data} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $model eq "HASH" and ref $model->{"meta_data"} eq "HASH"
MC/DC50%1/2
ref $model eq "HASH" and ref $model->{"meta_data"} eq "HASH"
ref $model eq "HASH"
ref $model->{"meta_data"} eq "HASH"
Truth table66%2/3
A and B
A= ref $model eq "HASH"B= ref $model->{"meta_data"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 20 | my $in = $model->{meta_data}{input_modalities}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 20 | ▶ | next unless ref $in eq 'ARRAY' && _id_ok( $model->{id} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $in eq "ARRAY" and _id_ok($model->{"id"})
MC/DC50%1/2
ref $in eq "ARRAY" and _id_ok($model->{"id"})
ref $in eq "ARRAY"
_id_ok($model->{"id"})
Truth table66%2/3
A and B
A= ref $in eq "ARRAY"B= _id_ok($model->{"id"})
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 12 | ▶ | my $vision = _bool( grep { defined && !ref && lc eq 'image' } @$in ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
defined $_ && !ref($_) && lc $_ eq 'image'
defined $_ and not ref $_
MC/DC33%1/3
defined $_ && !ref($_) && lc $_ eq 'image'
defined $_
not ref $_
lc $_ eq 'image'
Truth table50%2/4
A and not(B) && C
A= defined $_B= not ref $_C= lc $_ eq 'image'
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 12 | ▶ | $facts{ $model->{id} } //= { image_input => $vision }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$facts{$model->{"id"}} //= {"image_input", $vision}
MC/DC0%0/1
$facts{$model->{"id"}} //= {"image_input", $vision}
$facts{$model->{"id"}}
Truth table50%1/2
A
A= $facts{$model->{"id"}}
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | return \%facts; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 19 | ▶ | sub _extract_ollama { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_ollama: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 19 | my ( $data, $models ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 19 | my $caps = $data->{capabilities}; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 19 | ▶ | return {} unless ref $caps eq 'ARRAY' && @$models; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $caps eq "ARRAY" and @$models
MC/DC50%1/2
ref $caps eq "ARRAY" and @$models
ref $caps eq "ARRAY"
@$models
Truth table66%2/3
A and B
A= ref $caps eq "ARRAY"B= @$models
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 15 | ▶ | my $vision = _bool( grep { defined && $_ eq 'vision' } @$caps ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_ && $_ eq 'vision'
MC/DC50%1/2
defined $_ && $_ eq 'vision'
defined $_
$_ eq 'vision'
Truth table66%2/3
A && B
A= defined $_B= $_ eq 'vision'
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 15 | return { map { $_ => { image_input => $vision } } @$models }; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 6 | ▶ | sub _extract_llamacpp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_llamacpp: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 6 | my ( $data, $models ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 6 | my $modalities = $data->{modalities}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | ▶ | return {} unless ref $modalities eq 'HASH' && exists $modalities->{vision} && @$models; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $modalities eq "HASH" and exists $modalities->{"vision"} and @$models
ref $modalities eq "HASH" and exists $modalities->{"vision"}
MC/DC33%1/3
ref $modalities eq "HASH" and exists $modalities->{"vision"} and @$models
ref $modalities eq "HASH"
exists $modalities->{"vision"}
@$models
Truth table50%2/4
A and B and C
A= ref $modalities eq "HASH"B= exists $modalities->{"vision"}C= @$models
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 4 | my $vision = _bool( $modalities->{vision} ); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 4 | return { map { $_ => { image_input => $vision } } @$models }; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 180 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 180 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | Langertha::ModelProbe - Reads model-scoped capability facts from a provider's own model metadata | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | version 0.503 | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | # Normally reached through the engine (ADR 0032): | ||||||||||||||||||||||||||||||||||||||||||
| 191 | my $learned = await $engine->probe_model_capabilities_f; | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # { 'google/gemma-4-26b-a4b' => { image_input => 1 }, ... } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | # The inbound door itself, for a metadata document already in hand: | ||||||||||||||||||||||||||||||||||||||||||
| 195 | my $facts = Langertha::ModelProbe->extract( lmstudio => $data, \@models ); | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | The inbound door for B<model metadata>: it reads what a provider's own | ||||||||||||||||||||||||||||||||||||||||||
| 200 | metadata endpoint says about a model and turns it into capability facts in the | ||||||||||||||||||||||||||||||||||||||||||
| 201 | L<Langertha::Role::Capabilities> vocabulary. It is keyed by a per-concern | ||||||||||||||||||||||||||||||||||||||||||
| 202 | format tag, the engine's C<model_metadata_format> (ADR 0032), the same way the | ||||||||||||||||||||||||||||||||||||||||||
| 203 | tool value objects are keyed by C<tool_wire_format> (ADR 0001): | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | =item * C<openrouter> - C<GET /models>, C<data[].architecture.input_modalities> | ||||||||||||||||||||||||||||||||||||||||||
| 208 | (C<image> in the list means the model sees images). Facts are keyed by C<id> | ||||||||||||||||||||||||||||||||||||||||||
| 209 | and C<canonical_slug>. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | =item * C<mistral> - C<GET /v1/models>, C<data[].capabilities.vision>. Facts | ||||||||||||||||||||||||||||||||||||||||||
| 212 | are keyed by C<id> and by each entry of C<aliases>; an entry's own C<id> wins | ||||||||||||||||||||||||||||||||||||||||||
| 213 | over another entry's alias. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | =item * C<lmstudio> - LM Studio's native C<GET /api/v1/models>, | ||||||||||||||||||||||||||||||||||||||||||
| 216 | C<models[].capabilities.vision>. Facts are keyed by C<key> and by the C<id> of | ||||||||||||||||||||||||||||||||||||||||||
| 217 | each C<loaded_instances> entry. Entries without C<capabilities> (embedding | ||||||||||||||||||||||||||||||||||||||||||
| 218 | models) give no fact. | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | =item * C<tsystems> - T-Systems AI Foundation Services C<GET /v2/models>, | ||||||||||||||||||||||||||||||||||||||||||
| 221 | C<data[].meta_data.input_modalities>, a nullable array of strings; C<image> in | ||||||||||||||||||||||||||||||||||||||||||
| 222 | it, matched case-insensitively because the spelling is not documented, means | ||||||||||||||||||||||||||||||||||||||||||
| 223 | the model sees images. Facts are keyed by C<id>. An entry without | ||||||||||||||||||||||||||||||||||||||||||
| 224 | C<meta_data> or with a missing or null C<input_modalities> gives no fact. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | Shaped from the provider's public OpenAPI document only: no key exists to | ||||||||||||||||||||||||||||||||||||||||||
| 226 | verify it live. | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | =item * C<ollama> - C<POST /api/show> with C<{ model }>, one request per model; | ||||||||||||||||||||||||||||||||||||||||||
| 229 | the C<capabilities> array (C<vision> in it means the model sees images). A | ||||||||||||||||||||||||||||||||||||||||||
| 230 | server too old to report C<capabilities> gives no fact. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | =item * C<llamacpp> - C<GET /props>, C<modalities.vision>. llama.cpp serves one | ||||||||||||||||||||||||||||||||||||||||||
| 233 | model whatever id the request names, so the fact is keyed by every model id the | ||||||||||||||||||||||||||||||||||||||||||
| 234 | probe was asked about. A server without C<modalities> gives no fact. | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | Only capabilities the metadata states outright are read, and in this version | ||||||||||||||||||||||||||||||||||||||||||
| 239 | that is C<image_input> alone (L</probed_capabilities>). A document that does | ||||||||||||||||||||||||||||||||||||||||||
| 240 | not carry the field yields no fact for that model, never a false one. | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | This class has no instances; all methods are class methods. It does no network | ||||||||||||||||||||||||||||||||||||||||||
| 243 | I/O: the engine sends the request (L<Langertha::Role::Capabilities/probe_model_capabilities_f>). | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | =head2 probed_capabilities | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | my @caps = Langertha::ModelProbe->probed_capabilities; # ('image_input') | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | The capability names a probe can learn. Everything else stays with the static | ||||||||||||||||||||||||||||||||||||||||||
| 250 | layers of L<Langertha::Role::Capabilities/engine_capabilities>. | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | =head2 is_known_format | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | Langertha::ModelProbe->is_known_format('ollama'); # 1 | ||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | =head2 http_method | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | my $method = Langertha::ModelProbe->http_method('ollama'); # 'POST' | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | =head2 per_model | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | True when the format answers for one model per request (C<ollama>: the request | ||||||||||||||||||||||||||||||||||||||||||
| 263 | body names the model); false when one request answers for the whole server. | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | =head2 is_catalogue | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | Langertha::ModelProbe->is_catalogue('openrouter'); # 1 | ||||||||||||||||||||||||||||||||||||||||||
| 268 | Langertha::ModelProbe->is_catalogue('llamacpp'); # 0 | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | True when one document names every model it describes (C<openrouter>, | ||||||||||||||||||||||||||||||||||||||||||
| 271 | C<mistral>, C<lmstudio>, C<tsystems>), so a single probe can learn the whole catalogue | ||||||||||||||||||||||||||||||||||||||||||
| 272 | (C<< models => 'all' >>). False for C<ollama> (one model per request) and | ||||||||||||||||||||||||||||||||||||||||||
| 273 | C<llamacpp> (the document does not name its model). | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | =head2 extract | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | my $facts = Langertha::ModelProbe->extract( $format, $data, \@models ); | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | Reads a decoded metadata document and returns | ||||||||||||||||||||||||||||||||||||||||||
| 280 | C<< { $model_id => { image_input => 0|1 } } >>. C<\@models> are the ids the | ||||||||||||||||||||||||||||||||||||||||||
| 281 | probe asked about: the C<ollama> and C<llamacpp> documents do not name the | ||||||||||||||||||||||||||||||||||||||||||
| 282 | model, so their fact is keyed by these. Croaks on an unknown format; a | ||||||||||||||||||||||||||||||||||||||||||
| 283 | document of an unexpected shape gives an empty HashRef. | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | =head2 server_root_url | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | Langertha::ModelProbe->server_root_url('http://localhost:11434/v1'); | ||||||||||||||||||||||||||||||||||||||||||
| 288 | # http://localhost:11434 | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | Strips a trailing C</v1> (and slash) from an OpenAI-compatible base URL, for | ||||||||||||||||||||||||||||||||||||||||||
| 291 | the self-hosted servers whose metadata lives beside C</v1> (Ollama C</api/show>, | ||||||||||||||||||||||||||||||||||||||||||
| 292 | LM Studio C</api/v1/models>, llama.cpp C</props>). | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | =head2 lookup_ids | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | my @ids = Langertha::ModelProbe->lookup_ids( ollama => 'llava' ); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | # ('llava', 'llava:latest') | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | The store keys, in order, under which a fact for C<$model> may have been | ||||||||||||||||||||||||||||||||||||||||||
| 300 | learned: the exact id first, then the format's equivalent spelling. For | ||||||||||||||||||||||||||||||||||||||||||
| 301 | C<ollama> a missing tag is C<:latest> (C<llava> and C<llava:latest> find each | ||||||||||||||||||||||||||||||||||||||||||
| 302 | other). For C<openrouter> a routing variant suffix (C<openai/gpt-4o:online>, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | C<:free>, C<:nitro>, ...) falls back to the base id when the variant itself was | ||||||||||||||||||||||||||||||||||||||||||
| 304 | not listed. Other formats match exactly. A non-string or empty id gives an | ||||||||||||||||||||||||||||||||||||||||||
| 305 | empty list. | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | =item * L<Langertha::Role::Capabilities> - C<probe_model_capabilities_f> and the learned layer | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | =item * L<Langertha::Role::ImageInput> - The C<image_input> flag | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | =head2 Issues | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | Please report bugs and feature requests on GitHub at | ||||||||||||||||||||||||||||||||||||||||||
| 322 | L<https://github.com/Getty/langertha/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | =head2 IRC | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | Join C<#langertha> on C<irc.perl.org> or message Getty directly. | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | =head1 CONTRIBUTING | ||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | Contributions are welcome! Please fork the repository and submit a pull request. | ||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | Torsten Raudssus <getty@cpan.org> | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>. | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 341 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | =cut | ||||||||||||||||||||||||||||||||||||||||||