| 1 | package Langertha::Engine::Mistral; | ||||||||||||||||||||
| 2 | # ABSTRACT: Mistral API | ||||||||||||||||||||
| 3 | 17 | our $VERSION = '0.505'; | |||||||||||||||||||
| 4 | 17 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 17 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 17 | ▶ | use File::ShareDir::ProjectDistDir qw( :all ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 17 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 17 | extends 'Langertha::Engine::OpenAIBase'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 17 | with map { 'Langertha::Role::'.$_ } qw( | |||||||||||||||||||
| 12 | Embedding | ||||||||||||||||||||
| 13 | Transcription | ||||||||||||||||||||
| 14 | Tools | ||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | has '+url' => ( | ||||||||||||||||||||
| 19 | lazy => 1, | ||||||||||||||||||||
| 20 | 14 | ▶ | default => sub { 'https://api.mistral.ai' }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 17 | ); | |||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | sub _build_api_key { | ||||||||||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=7.2
| |||||||||||||||||||||
| 24 | 1 | my ( $self ) = @_; | |||||||||||||||||||
| 25 | return $ENV{LANGERTHA_MISTRAL_API_KEY} | ||||||||||||||||||||
| 26 | 1 | ▶ | || croak "".(ref $self)." requires LANGERTHA_MISTRAL_API_KEY or api_key set"; | ||||||||||||||||||
|
Condition50%1/2
$ENV{'LANGERTHA_MISTRAL_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_MISTRAL_API_KEY or api_key set')
MC/DC0%0/1
$ENV{'LANGERTHA_MISTRAL_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_MISTRAL_API_KEY or api_key set')
$ENV{'LANGERTHA_MISTRAL_API_KEY'}
Truth table50%1/2
A
A= $ENV{'LANGERTHA_MISTRAL_API_KEY'}
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | sub openapi_file { yaml => dist_file('Langertha','mistral.yaml') }; | ||||||||||||||||||
|
Subroutine
openapi_file: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 25 | ▶ | sub _build_openapi_operations { | ||||||||||||||||||
|
Subroutine
_build_openapi_operations: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 25 | return use_module('Langertha::Spec::Mistral')->data; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 17 | ▶ | sub default_model { 'mistral-small-latest' } | ||||||||||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # image_input (k266, ADR 0019 k266 Update): Mistral serves text-only and vision | ||||||||||||||||||||
| 38 | # models side by side (llm-advisor, docs only, 2026-09-25), so the catch-all | ||||||||||||||||||||
| 39 | # first row clears the flag and the vision models re-assert it: the | ||||||||||||||||||||
| 40 | # small/medium/large -latest aliases, Pixtral, Small >= 3.1 (2503 on, Small 4 = | ||||||||||||||||||||
| 41 | # 2603), Medium 3.x (2505 on), Large 3 (2512 on) and Ministral 3 (2512 on). | ||||||||||||||||||||
| 42 | # Codestral, Nemo, Large 2407/2411, Ministral 2410 and Small 2409/2501 are | ||||||||||||||||||||
| 43 | # text-only and fall to the catch-all. Confirmed against the model cards | ||||||||||||||||||||
| 44 | # (llm-advisor, docs only, read 2026-09-25; the vision guide itself is stale): | ||||||||||||||||||||
| 45 | # mistral-small-latest -> mistral-small-2603 (Small 4, text+image); Medium 3.5 | ||||||||||||||||||||
| 46 | # = mistral-medium-3-5 / mistral-medium-3 / mistral-medium-latest (no dated | ||||||||||||||||||||
| 47 | # id on the card); Large 3 = mistral-large-2512 / mistral-large-latest; | ||||||||||||||||||||
| 48 | # Ministral 3 = ministral-{3,8,14}b-2512 / ministral-{3,8,14}b-latest. The | ||||||||||||||||||||
| 49 | # retired Pixtral, Small 2503/2506 and Medium 2505/2508 rows stay (harmless). | ||||||||||||||||||||
| 50 | 147 | ▶ | sub model_capability_corrections { | ||||||||||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 51 | return ( | ||||||||||||||||||||
| 52 | 147 | qr/\A/ => { image_input => 0 }, | |||||||||||||||||||
| 53 | qr/\Amistral-(?:small|medium|large)-latest\z/ => { image_input => 1 }, | ||||||||||||||||||||
| 54 | qr/\Apixtral-/ => { image_input => 1 }, | ||||||||||||||||||||
| 55 | qr/\Amistral-small-(?:250[3-9]|251\d|2[6-9]\d\d)/ => { image_input => 1 }, | ||||||||||||||||||||
| 56 | qr/\Amistral-medium-(?:250[5-9]|251\d|2[6-9]\d\d)/ => { image_input => 1 }, | ||||||||||||||||||||
| 57 | qr/\Amistral-large-(?:251[2-9]|2[6-9]\d\d)/ => { image_input => 1 }, | ||||||||||||||||||||
| 58 | qr/\Aministral-\d+b-(?:251[2-9]|2[6-9]\d\d)/ => { image_input => 1 }, | ||||||||||||||||||||
| 59 | qr/\Amistral-medium-3(?:-5)?\z/ => { image_input => 1 }, | ||||||||||||||||||||
| 60 | qr/\Aministral-\d+b-latest\z/ => { image_input => 1 }, | ||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 35 | ▶ | sub chat_operation_id { 'chat_completion_v1_chat_completions_post' } | ||||||||||||||||||
|
Subroutine
chat_operation_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 7 | ▶ | sub list_models_path { '/v1/models' } | ||||||||||||||||||
|
Subroutine
list_models_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | # The static table above is the answer until the caller probes: /v1/models | ||||||||||||||||||||
| 69 | # states capabilities.vision per model and alias, and a probed fact wins over | ||||||||||||||||||||
| 70 | # the table for the models it describes (ADR 0032). | ||||||||||||||||||||
| 71 | 10 | ▶ | sub model_metadata_format { 'mistral' } | ||||||||||||||||||
|
Subroutine
model_metadata_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 72 | 5 | ▶ | sub model_metadata_url { $_[0]->url . $_[0]->list_models_path } | ||||||||||||||||||
|
Subroutine
model_metadata_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | 5 | ▶ | sub embedding_operation_id { 'embeddings_v1_embeddings_post' } | ||||||||||||||||||
|
Subroutine
embedding_operation_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | # Mistral's embedding model; the OpenAI role's text-embedding-3-large is not | ||||||||||||||||||||
| 77 | # served here (k291). | ||||||||||||||||||||
| 78 | 2 | ▶ | sub default_embedding_model { 'mistral-embed' } | ||||||||||||||||||
|
Subroutine
default_embedding_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | # Mistral spells it output_dimension (EmbeddingRequest is | ||||||||||||||||||||
| 81 | # additionalProperties:false) and documents it for codestral-embed only (k319). | ||||||||||||||||||||
| 82 | 4 | ▶ | sub _embedding_dimensions_field { | ||||||||||||||||||
|
Subroutine
_embedding_dimensions_field: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 83 | 4 | my ( $self ) = @_; | |||||||||||||||||||
| 84 | 4 | ▶ | return ( $self->embedding_model // '' ) =~ /\Acodestral-embed/ ? 'output_dimension' : undef; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->embedding_model // ""
MC/DC0%0/1
$self->embedding_model // ""
$self->embedding_model
Truth table50%1/2
A
A= $self->embedding_model
| |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 6 | ▶ | sub transcription_operation_id { 'audio_api_v1_transcriptions_post' } | ||||||||||||||||||
|
Subroutine
transcription_operation_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 2 | ▶ | sub default_transcription_model { 'voxtral-mini-latest' } | ||||||||||||||||||
|
Subroutine
default_transcription_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | # Mistral reads its list-valued form fields as repeated parts under the plain | ||||||||||||||||||||
| 92 | # name, no [] (its SDKs' Speakeasy "standard" multipart format and its curl | ||||||||||||||||||||
| 93 | # docs); OpenAI's name[] key (k286) risks a silent no-op there. The [] spelling | ||||||||||||||||||||
| 94 | # is accepted and normalized too. -- karr k309, k315 | ||||||||||||||||||||
| 95 | 6 | ▶ | around transcription_request => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 96 | 6 | my ( $orig, $self, $file, %extra ) = @_; | |||||||||||||||||||
| 97 | 6 | for my $field (qw( timestamp_granularities context_bias )) { | |||||||||||||||||||
| 98 | 12 | ▶ | my $value = exists $extra{"${field}[]"} ? delete $extra{"${field}[]"} : $extra{$field}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 99 | 12 | ▶ | next unless ref $value eq 'ARRAY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 100 | 4 | $extra{$field} = { repeated => $value }; | |||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | 6 | return $self->$orig( $file, %extra ); | |||||||||||||||||||
| 103 | 17 | }; | |||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 17 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 17 | 1; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||