blib/lib/Langertha/Engine/AnthropicBase.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 94.4% 34 / 36 CC 3 SCAR 6.2
CC
3
Cov
96%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« blib/lib/Langertha/Role/ImageGeneration.pm ↑ Summary blib/lib/Langertha/Engine/Mistral.pm »
1 package Langertha::Engine::AnthropicBase;
2 # ABSTRACT: Base class for Anthropic-compatible engines
3 62 our $VERSION = '0.503';
4 62 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 62 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 62 extends 'Langertha::Engine::Remote';
8  
9 62 with 'Langertha::Role::Models',
10 # Role::Chat::content_format defaults to 'openai'; AnthropicCompatible (composed last) supplies 'anthropic'.
11 'Langertha::Role::Chat' => { -excludes => ['content_format'] },
12 'Langertha::Role::Temperature',
13 # Role::ReasoningEffort::_build_reasoning_wire_format defaults to 'openai'; AnthropicCompatible supplies 'anthropic'.
14 'Langertha::Role::ReasoningEffort' => { -excludes => ['_build_reasoning_wire_format'] },
15 # Role::PromptCache::_build_cache_wire_format defaults to 'openai'; AnthropicCompatible supplies 'anthropic'.
16 'Langertha::Role::PromptCache' => { -excludes => ['_build_cache_wire_format'] },
17 'Langertha::Role::ResponseSize',
18 'Langertha::Role::SystemPrompt',
19 'Langertha::Role::ResponseFormat',
20 'Langertha::Role::Streaming',
21 'Langertha::Role::ImageInput',
22 # Role::Tools::_build_tool_wire_format defaults to 'openai'; AnthropicCompatible supplies 'anthropic'.
23 'Langertha::Role::Tools' => { -excludes => ['_build_tool_wire_format'] },
24 'Langertha::Role::AnthropicCompatible';
25  
26 # The Anthropic family has the cache_control enable breakpoint but no OpenAI-style
27 # routing key. Clear the key flag so only the enable flag is advertised (ADR 0002).
28 # Partner direction: Langertha::Engine::OpenAIBase runs the symmetric
29 # correction and deletes prompt_cache, keeping prompt_cache_key. The pair is
30 # canon in L<ADR 0015|docs/adr/0015-role-composition-patterns.md>.
31 1442 ▶around engine_capabilities => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
32 1442 my ( $orig, $self, @rest ) = @_;
33 1442 my $caps = $self->$orig(@rest);
34 1442 delete $caps->{prompt_cache_key};
35 1442 return $caps;
36 62 };
37  
38 # Back-compat: the documented `effort => 'high'` constructor keeps working as an
39 # alias of the new normalized `reasoning_effort`. Both attributes stay readable;
40 # only the wire placement changed (top-level `effort` -> output_config.effort +
41 # thinking:{type:adaptive}, via Langertha::Reasoning).
42 613 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
43 613 my ( $orig, $class, @args ) = @_;
44 613 my $args = $class->$orig(@args);
45 613 ▶ if ( exists $args->{effort} && !exists $args->{reasoning_effort} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args->{"effort"} and not exists $args->{"reasoning_effort"}) 2 611 613
Condition66%2/3
exists $args->{"effort"} and not exists $args->{"reasoning_effort"}
!ll&&!rl&&r
61102
MC/DC50%1/2
exists $args->{"effort"} and not exists $args->{"reasoning_effort"}
exists $args->{"effort"} not exists $args->{"reasoning_effort"}
Truth table66%2/3
A and not(B)
A= exists $args->{"effort"}B= not exists $args->{"reasoning_effort"}
ABresult
0X0
100
111
46 2 $args->{reasoning_effort} = $args->{effort};
47 }
48 613 return $args;
49 62 };
50  
51  
52 1 ▶sub default_model { croak "".(ref $_[0])." requires model to be set" }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
53  
54  
55 62 __PACKAGE__->meta->make_immutable;
56  
57  
58 62 1;
59  
60 __END__
61  
62 =pod
63  
64 =encoding UTF-8
65  
66 =head1 NAME
67  
68 Langertha::Engine::AnthropicBase - Base class for Anthropic-compatible engines
69  
70 =head1 VERSION
71  
72 version 0.503
73  
74 =head1 SYNOPSIS
75  
76 package My::AnthropicCompatible;
77 use Moose;
78  
79 extends 'Langertha::Engine::AnthropicBase';
80  
81 has '+url' => ( default => sub { 'https://api.example.com' } );
82  
83 sub _build_api_key { $ENV{MY_API_KEY} || die "MY_API_KEY required" }
84 sub default_model { 'my-model-v1' }
85  
86 __PACKAGE__->meta->make_immutable;
87  
88 =head1 DESCRIPTION
89  
90 Intermediate base class for engines speaking the Anthropic-compatible
91 C</v1/messages> format. Extends L<Langertha::Engine::Remote> and composes
92 the universal chat/streaming/tool roles plus the Anthropic wire envelope,
93 which lives in L<Langertha::Role::AnthropicCompatible> (parallel to the
94 OpenAI envelope in L<Langertha::Role::OpenAICompatible>). This class is a
95 thin composition shell: the request/response/auth/stream/rate-limit envelope
96 for the Anthropic dialect is owned by the role.
97  
98 Concrete engines extending this class include
99 L<Langertha::Engine::Anthropic>, L<Langertha::Engine::AKIAnthropic>,
100 L<Langertha::Engine::MiniMaxAnthropic>,
101 L<Langertha::Engine::MoonshotAnthropic>, and
102 L<Langertha::Engine::LMStudioAnthropic>.
103  
104 Structured output (C<response_format>) takes one of two wire paths depending on
105 the engine. The first-party L<Langertha::Engine::Anthropic> emits it natively as
106 C<output_config.format> (GA on the Claude Messages API), which streams as
107 ordinary text and needs no post-processing. The legacy C</anthropic> shim
108 engines have no native form and keep the ADR 0005 rewrite: a synthesized tool
109 plus a forced C<tool_choice>, whose C<tool_use> input C<chat_response> lifts
110 back into C<Response.content>. That lift has no streaming counterpart, so on a
111 shim engine C<chat_stream_request> consumes a C<response_format> and croaks
112 instead of silently streaming unstructured text — use
113 L<Langertha::Role::Chat/chat_f> or C<chat_request> there. See ADR 0005.
114  
115 B<THIS API IS WORK IN PROGRESS>
116  
117 =head2 default_model
118  
119 Abstract. Subclasses must override this to return the default model name
120 string. The base implementation croaks with a descriptive error message.
121  
122 sub default_model { 'claude-sonnet-5' }
123  
124 =head1 SEE ALSO
125  
126 =over
127  
128 =item * L<https://status.anthropic.com/> - Anthropic service status
129  
130 =item * L<https://docs.anthropic.com/> - Official Anthropic documentation
131  
132 =item * L<Langertha::Role::AnthropicCompatible> - Anthropic wire envelope role
133  
134 =item * L<Langertha::Role::OpenAICompatible> - The parallel OpenAI envelope role
135  
136 =item * L<Langertha::Role::Chat> - Chat interface methods
137  
138 =item * L<Langertha::Role::Tools> - MCP tool calling interface
139  
140 =item * L<Langertha::Role::Streaming> - Streaming support (SSE format)
141  
142 =item * L<Langertha::Engine::Gemini> - Another non-OpenAI-compatible engine
143  
144 =back
145  
146 =head1 SUPPORT
147  
148 =head2 Issues
149  
150 Please report bugs and feature requests on GitHub at
151 L<https://github.com/Getty/langertha/issues>.
152  
153 =head2 IRC
154  
155 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
156  
157 =head1 CONTRIBUTING
158  
159 Contributions are welcome! Please fork the repository and submit a pull request.
160  
161 =head1 AUTHOR
162  
163 Torsten Raudssus <getty@cpan.org>
164  
165 =head1 COPYRIGHT AND LICENSE
166  
167 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
168  
169 This is free software; you can redistribute it and/or modify it under
170 the same terms as the Perl 5 programming language system itself.
171  
172 =cut
« blib/lib/Langertha/Role/ImageGeneration.pm ↑ Summary blib/lib/Langertha/Engine/Mistral.pm »