blib/lib/Langertha/Engine/AKIOpenAI.pm

filter: Statementstmt 100% 24 / 24 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 66.6% 2 / 3 totaltotal 87.8% 36 / 41 CC 2 SCAR 2.2
CC
2
Cov
93%
_build_api_key
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Langertha/Engine/LMStudioAnthropic.pm ↑ Summary blib/lib/Langertha/Role/Seed.pm »
1 package Langertha::Engine::AKIOpenAI;
2 # ABSTRACT: AKI.IO via OpenAI-compatible API
3 15 our $VERSION = '0.503';
4 15 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 15 extends 'Langertha::Engine::OpenAIBase';
8  
9 # Native OpenAI tool calling, live-verified 2026-09-01 against
10 # /openai/v1/chat/completions: a native `tools` array is accepted and answered
11 # with a native `tool_calls` block, arguments intact — verified on
12 # llama3-chat-8b, one model AKI's own table rates only "Basic Support".
13 # So no Role::HermesTools and no tool_wire_format override: the `openai` default
14 # of Langertha::Role::Tools is the wire reality. -- karr k102
15 15 with 'Langertha::Role::Tools';
16  
17 # AKI.IO ships the model's chain-of-thought under the bare `reasoning` key on
18 # the OpenAI-compatible message. That spelling is now read by the shared
19 # Role::OpenAICompatible::chat_response (reasoning_content, else bare
20 # `reasoning`), so no AKI-scoped lift is needed here. -- karr k127, k129
21  
22  
23 # AKI.IO's OpenAI-compatibility docs are internally inconsistent about the base
24 # path: prose mentions /v1, but every working example (curl, Python SDK,
25 # machine-readable config, /models discovery) uses /openai/v1. We follow the
26 # working examples. See https://aki.io/docs/compatibility/openai-api-compatibility/
27 has '+url' => (
28 lazy => 1,
29 6 ▶ default => sub { 'https://aki.io/openai/v1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 15 );
31  
32 1 ▶sub _build_api_key {
Subroutine _build_api_key: called CC=2 SCAR=8.1
33 1 my ( $self ) = @_;
34 return $ENV{LANGERTHA_AKI_API_KEY}
35 1 ▶ || croak "".(ref $self)." requires LANGERTHA_AKI_API_KEY or api_key set";
Condition33%1/3
$ENV{'LANGERTHA_AKI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'LANGERTHA_AKI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
$ENV{'LANGERTHA_AKI_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
Truth table33%1/3
A || B
A= $ENV{'LANGERTHA_AKI_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_AKI_API_KEY or api_key set')
ABresult
1X1
011
000
36 }
37  
38  
39 # gpt-oss-120b replaces the EOL llama3-chat-8b (AKI.IO end-of-life 2026-09-30)
40 # as the default. AKI.IO exposes MiniMax M3 only on its native endpoint, so a
41 # current non-MiniMax model AKI's own table rates "Supported" is the shim
42 # default. Verified live 2026-09-10: the /openai/v1 shim answers gpt-oss-120b
43 # and echoes it back as $response->model (unknown ids are rejected loudly here,
44 # not silently substituted). -- karr k132
45 19 ▶sub default_model { 'gpt-oss-120b' }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
46  
47  
48 1 ▶sub api_key_env { 'LANGERTHA_AKI_API_KEY' }
Subroutine api_key_env: called CC=1 SCAR=0.0
Pod documented
49  
50 18 ▶sub _build_supported_operations {[qw( createChatCompletion )]}
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
51  
52 # AKI.IO's OpenAI-compatibility page documents no parallel_tool_calls (nor
53 # tools). One live probe (2026-09-25, gpt-oss-120b, two independent tools,
54 # parallel_tool_calls=false) answered 200 with one tool call: the field is
55 # accepted, but one call cannot show it is honored. Clear parallel_tool_use
56 # until the docs or more evidence say otherwise (karr k242).
57 88 ▶around engine_capabilities => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
58 88 my ( $orig, $self, @rest ) = @_;
59 88 my $caps = $self->$orig(@rest);
60 88 delete $caps->{parallel_tool_use};
61 88 return $caps;
62 15 };
63  
64 # image_input (k266/k271, ADR 0019 k266 Update): AKI.IO documents no image
65 # input on this face and /models carries no modality field, so the catch-all
66 # row clears the flag (the default gpt-oss-120b makes no claim). Live probe
67 # 2026-09-25 (k271): an 8x8 solid-red base64 PNG sent as an image_url part to
68 # qwen3.6-chat-35b answered "Red", its reasoning describing "a solid, uniform
69 # block of color" (t/data/akiopenai_qwen36_image_response.json). Follow-up
70 # probe 2026-09-25 (k272), same image and prompt, max_tokens 2048:
71 # gemma4-chat-26b and qwen3.8-27b both answered "Red", each reasoning about a
72 # uniform red field (t/data/akiopenai_{gemma4,qwen38}_image_response.json).
73 # Each row claims the probed model's family, as k271 did for qwen3.6-35b:
74 # gemma4-26b is claimed with gemma4-chat-26b but was not called itself.
75 # Every other id (gpt-oss, llama3, apertus, mistral4, deepseek, glm) stays
76 # unclaimed: not probed as of 2026-09-25.
77 88 ▶sub model_capability_corrections {
Subroutine model_capability_corrections: called CC=1 SCAR=0.0
Pod undocumented
78 return (
79 88 qr/\A/ => { image_input => 0 },
80 qr/\Aqwen3\.6(?!\d)/ => { image_input => 1 },
81 qr/\Aqwen3\.8(?!\d)/ => { image_input => 1 },
82 qr/\Agemma4(?!\d)/ => { image_input => 1 },
83 );
84 }
85  
86 15 __PACKAGE__->meta->make_immutable;
87  
88  
89 15 1;
90  
91 __END__
92  
93 =pod
94  
95 =encoding UTF-8
96  
97 =head1 NAME
98  
99 Langertha::Engine::AKIOpenAI - AKI.IO via OpenAI-compatible API
100  
101 =head1 VERSION
102  
103 version 0.503
104  
105 =head1 SYNOPSIS
106  
107 use Langertha::Engine::AKIOpenAI;
108  
109 # Direct construction (use /v1 model names, NOT native AKI names)
110 my $aki = Langertha::Engine::AKIOpenAI->new(
111 api_key => $ENV{AKI_API_KEY},
112 model => 'gpt-oss-120b',
113 );
114  
115 print $aki->simple_chat('Hello!');
116  
117 # Streaming
118 $aki->simple_chat_stream(sub {
119 print shift->content;
120 }, 'Tell me about Perl');
121  
122 # Via AKI's openai() method (uses default model)
123 use Langertha::Engine::AKI;
124  
125 my $aki_native = Langertha::Engine::AKI->new(
126 api_key => $ENV{AKI_API_KEY},
127 model => 'llama3_8b_chat',
128 );
129 my $oai = $aki_native->openai; # warns: model not mapped, uses default
130 print $oai->simple_chat('Hello via OpenAI format!');
131  
132 =head1 DESCRIPTION
133  
134 Provides access to AKI.IO's OpenAI-compatible API at C<https://aki.io/openai/v1>.
135 Composes L<Langertha::Role::OpenAICompatible> for the standard OpenAI format.
136  
137 AKI.IO is a European AI model hub (Germany) — fully GDPR-compliant with all
138 inference on EU infrastructure. Supports chat completions (with SSE streaming),
139 dynamic model listing, and native OpenAI-standard tool calling: tools go out as
140 the C<tools> array and come back as a C<tool_calls> block, the shared default of
141 L<Langertha::Role::Tools>. Verified live against C<llama3-chat-8b>, one model
142 AKI's own support table rates only "Basic Support", so the weakest documented
143 case works — earlier releases routed this engine through
144 L<Langertha::Role::HermesTools> instead, which is no longer necessary.
145  
146 Embeddings and transcription are not supported. For native AKI.IO API features
147 (C<top_k>, C<top_p>, C<max_gen_tokens>), use L<Langertha::Engine::AKI>.
148  
149 B<Chain-of-thought:> AKI.IO returns the model's reasoning under the bare
150 C<reasoning> key on the message. The shared OpenAI-compatible path reads that
151 spelling (canonical C<reasoning_content> first, then bare C<reasoning>) onto
152 L<Langertha::Response/thinking>, so C<< $response->thinking >> is populated.
153  
154 B<Vision:> images in C<content> go out as C<image_url> parts.
155 C<< supports('image_input') >> is true only for the C<qwen3.6-*>,
156 C<qwen3.8-*> and C<gemma4-*> models, the families verified to see an image on
157 this endpoint; other models make no claim, which never stops an image from
158 being sent.
159  
160 B<Client errors arrive as HTTP 529:> AKI.IO returns some B<caller-side> errors
161 as C<529> C<overloaded_error> — notably a token budget too small to finish a
162 tool call (C<"Response finished before tool_call was completed! Try to raise
163 max_gen_tokens">). That condition is deterministic and fixed by raising
164 C<response_size> / C<max_tokens>, B<not> transient server overload: do not treat
165 an AKI C<529> as a wait-and-retry signal, and read
166 C<< $error->{error}{message} >> for the real diagnostic.
167  
168 Get your API key at L<https://aki.io/> and set C<LANGERTHA_AKI_API_KEY>.
169  
170 B<THIS API IS WORK IN PROGRESS>
171  
172 =head2 api_key
173  
174 The AKI.IO API key. If not provided, reads from C<LANGERTHA_AKI_API_KEY>
175 environment variable. Sent as a Bearer token in the C<Authorization> HTTP
176 header. Required.
177  
178 =head2 default_model
179  
180 Returns C<gpt-oss-120b>, a current-generation non-MiniMax model AKI.IO rates
181 "Supported", replacing C<llama3-chat-8b>, which AKI.IO marks end-of-life
182 2026-09-30. AKI.IO exposes MiniMax M3 only on its native endpoint, not this
183 shim; the shim's only MiniMax id (C<minimax-m2.5-230b>) is the older
184 generation.
185  
186 =head1 SEE ALSO
187  
188 =over
189  
190 =item * L<Langertha::Engine::AKI> - Native AKI.IO API (with top_k, top_p, max_gen_tokens)
191  
192 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role composed by this engine
193  
194 =item * L<https://aki.io/docs> - AKI.IO API documentation
195  
196 =back
197  
198 =head1 SUPPORT
199  
200 =head2 Issues
201  
202 Please report bugs and feature requests on GitHub at
203 L<https://github.com/Getty/langertha/issues>.
204  
205 =head2 IRC
206  
207 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
208  
209 =head1 CONTRIBUTING
210  
211 Contributions are welcome! Please fork the repository and submit a pull request.
212  
213 =head1 AUTHOR
214  
215 Torsten Raudssus <getty@cpan.org>
216  
217 =head1 COPYRIGHT AND LICENSE
218  
219 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
220  
221 This is free software; you can redistribute it and/or modify it under
222 the same terms as the Perl 5 programming language system itself.
223  
224 =cut
« blib/lib/Langertha/Engine/LMStudioAnthropic.pm ↑ Summary blib/lib/Langertha/Role/Seed.pm »