| 1 | package Langertha::Engine::LMStudioOpenAI; | ||||||||||||
| 2 | # ABSTRACT: LM Studio via OpenAI-compatible API | ||||||||||||
| 3 | 12 | our $VERSION = '0.505'; | |||||||||||
| 4 | 12 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 12 | extends 'Langertha::Engine::OpenAIBase'; | |||||||||||
| 7 | |||||||||||||
| 8 | 12 | with 'Langertha::Role::Embedding', 'Langertha::Role::Tools'; | |||||||||||
| 9 | |||||||||||||
| 10 | |||||||||||||
| 11 | has '+url' => ( | ||||||||||||
| 12 | lazy => 1, | ||||||||||||
| 13 | 2 | ▶ | default => sub { 'http://localhost:1234/v1' }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 12 | ); | |||||||||||
| 15 | |||||||||||||
| 16 | 11 | ▶ | sub _build_api_key { | ||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=6.9
| |||||||||||||
| 17 | 11 | ▶ | return $ENV{LANGERTHA_LMSTUDIO_API_KEY} || 'lmstudio'; | ||||||||||
|
Condition100%2/2
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'} || 'lmstudio'
MC/DC100%1/1
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'} || 'lmstudio'
$ENV{'LANGERTHA_LMSTUDIO_API_KEY'}
Truth table100%2/2
A
A= $ENV{'LANGERTHA_LMSTUDIO_API_KEY'}
| |||||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | |||||||||||||
| 21 | 21 | ▶ | sub default_model { 'default' } | ||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 22 | # No fixed embedding model: the caller's model, else no model field (k297). | ||||||||||||
| 23 | 4 | ▶ | sub default_embedding_model { undef } | ||||||||||
|
Subroutine
default_embedding_model: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 24 | |||||||||||||
| 25 | # LM Studio documents no dimensions field for /v1/embeddings (k319). | ||||||||||||
| 26 | 2 | ▶ | sub _embedding_dimensions_field { undef } | ||||||||||
|
Subroutine
_embedding_dimensions_field: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | |||||||||||||
| 28 | # Shares the LM Studio key with the native engine (derivation would name the | ||||||||||||
| 29 | # protocol variant); optional, the local server accepts the 'lmstudio' dummy. | ||||||||||||
| 30 | 2 | ▶ | sub api_key_env { 'LANGERTHA_LMSTUDIO_API_KEY' } | ||||||||||
|
Subroutine
api_key_env: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 31 | 2 | ▶ | sub api_key_required { 0 } | ||||||||||
|
Subroutine
api_key_required: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 22 | ▶ | sub _build_supported_operations {[qw( | ||||||||||
|
Subroutine
_build_supported_operations: called CC=1 SCAR=0.0
| |||||||||||||
| 35 | createChatCompletion | ||||||||||||
| 36 | createEmbedding | ||||||||||||
| 37 | )]} | ||||||||||||
| 38 | |||||||||||||
| 39 | # LM Studio documents a closed parameter list for /v1/chat/completions | ||||||||||||
| 40 | # (lmstudio.ai/docs/developer/openai-compat/chat-completions) and | ||||||||||||
| 41 | # prompt_cache_key is not on it (checked 2026-09-25, karr #200), so the | ||||||||||||
| 42 | # OpenAI cache-routing hint is not advertised (ADR 0002 layer 2). | ||||||||||||
| 43 | 92 | ▶ | around engine_capabilities => sub { | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 44 | 92 | my ( $orig, $self, @rest ) = @_; | |||||||||||
| 45 | 92 | my $caps = $self->$orig(@rest); | |||||||||||
| 46 | 92 | delete $caps->{prompt_cache_key}; | |||||||||||
| 47 | 92 | return $caps; | |||||||||||
| 48 | 12 | }; | |||||||||||
| 49 | |||||||||||||
| 50 | # image_input (k266, ADR 0019): self-hosted: the served model is launch state | ||||||||||||
| 51 | # the client cannot see, so no static claim. A layer-3 catch-all rather than a | ||||||||||||
| 52 | # layer-2 delete, so a fact probed from the server's native /api/v1/models | ||||||||||||
| 53 | # (capabilities.vision) can answer per model (ADR 0032). | ||||||||||||
| 54 | 92 | ▶ | sub model_capability_corrections { | ||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 55 | 92 | return ( qr/\A/ => { image_input => 0 } ); | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | 4 | ▶ | sub model_metadata_format { 'lmstudio' } | ||||||||||
|
Subroutine
model_metadata_format: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 59 | 4 | ▶ | sub model_metadata_url { | ||||||||||
|
Subroutine
model_metadata_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 60 | 4 | return Langertha::ModelProbe->server_root_url( $_[0]->url ) . '/api/v1/models'; | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 12 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 64 | |||||||||||||
| 65 | |||||||||||||
| 66 | |||||||||||||
| 67 | 12 | 1; | |||||||||||
| 68 | |||||||||||||
| 69 | __END__ | ||||||||||||