blib/lib/Langertha/Engine/OpenAIBase.pm

filter: Statementstmt 100% 22 / 22 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 29 / 29 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Langertha/Engine/vLLM.pm ↑ Summary blib/lib/Langertha/Result.pm »
1 package Langertha::Engine::OpenAIBase;
2 # ABSTRACT: Base class for OpenAI-compatible engines
3 154 our $VERSION = '0.503';
4 154 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 154 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 154 ▶use Module::Runtime qw( use_module );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 154 extends 'Langertha::Engine::Remote';
9  
10 154 with map { 'Langertha::Role::'.$_ } qw(
11 OpenAICompatible
12 OpenAPI
13 Models
14 Temperature
15 ReasoningEffort
16 PromptCache
17 ResponseSize
18 SystemPrompt
19 ResponseFormat
20 Streaming
21 Chat
22 ImageInput
23 );
24  
25 1396 ▶sub _build_openapi_operations {
Subroutine _build_openapi_operations: called CC=1 SCAR=0.0
26 1396 return use_module('Langertha::Spec::OpenAI')->data;
27 }
28  
29 # The OpenAI family caches automatically — there is no request-side enable
30 # breakpoint, only the prompt_cache_key routing hint. Clear the Anthropic-style
31 # enable flag here so the whole family advertises only the key (ADR 0002).
32 # Partner direction: Langertha::Engine::AnthropicBase runs the symmetric
33 # correction and deletes prompt_cache_key, keeping prompt_cache. The pair is
34 # canon in L<ADR 0015|docs/adr/0015-role-composition-patterns.md>.
35 5801 ▶around engine_capabilities => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
36 5801 my ( $orig, $self, @rest ) = @_;
37 5801 my $caps = $self->$orig(@rest);
38 5801 delete $caps->{prompt_cache};
39 5801 return $caps;
40 154 };
41  
42  
43 # The tools + structured-output response_format conflict is a property of the
44 # serving STACK, not of the gpt-oss model: Groq and Cerebras enforce it
45 # stack-wide (each via its own model_capability_exclusions override), while
46 # AKI's gpt-oss-120b serves tools + a json_schema response_format at HTTP 200
47 # (live-verified 2026-09-19, karr #184). So it is NOT gated here on the shared
48 # OpenAI base — doing so was a false-positive on the AKIOpenAI / TSystems
49 # defaults and aggregator routes. This base composes no exclusion rule and
50 # inherits the Langertha::Role::Chat no-op; the per-model
51 # model_capability_exclusions seam stays and Groq/Cerebras carry the rule
52 # (ADR 0024).
53  
54 1 ▶sub default_model { croak "".(ref $_[0])." requires model to be set" }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
55  
56  
57 154 __PACKAGE__->meta->make_immutable;
58  
59  
60 154 1;
61  
62 __END__
63  
64 =pod
65  
66 =encoding UTF-8
67  
68 =head1 NAME
69  
70 Langertha::Engine::OpenAIBase - Base class for OpenAI-compatible engines
71  
72 =head1 VERSION
73  
74 version 0.503
75  
76 =head1 SYNOPSIS
77  
78 package My::CompatibleEngine;
79 use Moose;
80  
81 extends 'Langertha::Engine::OpenAIBase';
82  
83 has '+url' => ( default => 'https://api.example.com/v1' );
84  
85 sub _build_api_key {
86 return $ENV{MY_API_KEY} || die "MY_API_KEY required";
87 }
88  
89 sub default_model { 'my-model-v1' }
90  
91 __PACKAGE__->meta->make_immutable;
92  
93 =head1 DESCRIPTION
94  
95 Intermediate base class for all engines that speak the OpenAI
96 C</chat/completions> API format. Extends L<Langertha::Engine::Remote> and
97 composes the full set of OpenAI-compatible roles:
98 L<Langertha::Role::OpenAICompatible>, L<Langertha::Role::OpenAPI>,
99 L<Langertha::Role::Models>, L<Langertha::Role::Temperature>,
100 L<Langertha::Role::ResponseSize>, L<Langertha::Role::SystemPrompt>,
101 L<Langertha::Role::Streaming>, and L<Langertha::Role::Chat>.
102  
103 Subclasses must override C<default_model> to return their default model name.
104 They also typically override C<_build_api_key> to read from an environment
105 variable, and C<has '+url'> to supply a default API endpoint.
106  
107 Concrete engines that extend this class:
108  
109 =over 4
110  
111 =item * Cloud providers — L<Langertha::Engine::OpenAI>, L<Langertha::Engine::DeepSeek>,
112 L<Langertha::Engine::Groq>, L<Langertha::Engine::Hetzner>,
113 L<Langertha::Engine::MiniMax>, L<Langertha::Engine::Mistral>,
114 L<Langertha::Engine::Moonshot>, L<Langertha::Engine::XAI>,
115 L<Langertha::Engine::Cerebras>, L<Langertha::Engine::NousResearch>,
116 L<Langertha::Engine::OpenRouter>, L<Langertha::Engine::Replicate>,
117 L<Langertha::Engine::HuggingFace>, L<Langertha::Engine::Perplexity>,
118 L<Langertha::Engine::AKIOpenAI>, L<Langertha::Engine::TSystems>,
119 L<Langertha::Engine::Scaleway>
120  
121 =item * Self-hosted — L<Langertha::Engine::OllamaOpenAI>,
122 L<Langertha::Engine::vLLM>, L<Langertha::Engine::SGLang>,
123 L<Langertha::Engine::LlamaCpp>, L<Langertha::Engine::LMStudioOpenAI>
124  
125 =back
126  
127 For transcription-only engines (Whisper-style) see
128 L<Langertha::Engine::TranscriptionBase>; that base does I<not>
129 compose Chat/Tools/Embedding/ImageGeneration so callers get a focused
130 audio-transcription handle.
131  
132 =head2 default_model
133  
134 Abstract. Subclasses must override this to return the default model name
135 string. The base implementation croaks with a descriptive error message.
136  
137 sub default_model { 'gpt-4o-mini' }
138  
139 =head1 SEE ALSO
140  
141 =over
142  
143 =item * L<Langertha::Engine::Remote> - Parent base class
144  
145 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format (chat, embeddings, tools, streaming)
146  
147 =item * L<Langertha::Role::Chat> - C<simple_chat>, C<simple_chat_f>, streaming methods
148  
149 =item * L<Langertha::Role::Models> - C<model>, C<models>, C<list_models>
150  
151 =item * L<Langertha::Role::Temperature> - C<temperature> attribute
152  
153 =item * L<Langertha::Role::ResponseSize> - C<response_size> / C<max_tokens>
154  
155 =item * L<Langertha::Role::SystemPrompt> - C<system_prompt> attribute
156  
157 =item * L<Langertha::Role::Streaming> - SSE stream parsing
158  
159 =item * L<Langertha::Engine::OpenAI> - Canonical OpenAI engine
160  
161 =item * L<Langertha::Engine::Groq> - Groq ultra-fast inference
162  
163 =item * L<Langertha::Engine::DeepSeek> - DeepSeek reasoning models
164  
165 =item * L<Langertha::Engine::OllamaOpenAI> - Ollama OpenAI-compatible endpoint
166  
167 =item * L<Langertha::Engine::vLLM> - vLLM high-throughput inference server
168  
169 =item * L<Langertha::Engine::SGLang> - SGLang OpenAI-compatible endpoint
170  
171 =back
172  
173 =head1 SUPPORT
174  
175 =head2 Issues
176  
177 Please report bugs and feature requests on GitHub at
178 L<https://github.com/Getty/langertha/issues>.
179  
180 =head2 IRC
181  
182 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
183  
184 =head1 CONTRIBUTING
185  
186 Contributions are welcome! Please fork the repository and submit a pull request.
187  
188 =head1 AUTHOR
189  
190 Torsten Raudssus <getty@cpan.org>
191  
192 =head1 COPYRIGHT AND LICENSE
193  
194 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
195  
196 This is free software; you can redistribute it and/or modify it under
197 the same terms as the Perl 5 programming language system itself.
198  
199 =cut
« blib/lib/Langertha/Engine/vLLM.pm ↑ Summary blib/lib/Langertha/Result.pm »