blib/lib/Langertha/Engine/Anthropic.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 85.7% 6 / 7 Podpod 50.0% 1 / 2 totaltotal 70.9% 22 / 31 CC 2 SCAR 8.1
CC
2
Cov
75%
_build_api_key
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« blib/lib/Langertha/Plugin.pm ↑ Summary blib/lib/Langertha/Engine/MoonshotAnthropic.pm »
1 package Langertha::Engine::Anthropic;
2 # ABSTRACT: Anthropic API
3 54 our $VERSION = '0.503';
4 54 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 54 extends 'Langertha::Engine::AnthropicBase';
8  
9  
10 has '+url' => (
11 lazy => 1,
12 103 ▶ default => sub { 'https://api.anthropic.com' },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 54 );
14  
15 0 ▶sub _build_api_key {
Subroutine _build_api_key: not called CC=2 SCAR=17.9
16 0 my ( $self ) = @_;
17 return $ENV{LANGERTHA_ANTHROPIC_API_KEY}
18 0 ▶ || croak "".(ref $self)." requires LANGERTHA_ANTHROPIC_API_KEY or api_key set";
Condition0%0/3
$ENV{'LANGERTHA_ANTHROPIC_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_ANTHROPIC_API_KEY or api_key set')
l!l&&r!l&&!r
000
MC/DC0%0/2
$ENV{'LANGERTHA_ANTHROPIC_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_ANTHROPIC_API_KEY or api_key set')
$ENV{'LANGERTHA_ANTHROPIC_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_ANTHROPIC_API_KEY or api_key set')
Truth table0%0/3
A || B
A= $ENV{'LANGERTHA_ANTHROPIC_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_ANTHROPIC_API_KEY or api_key set')
ABresult
1X1
011
000
19 }
20  
21 24 ▶sub default_model { 'claude-sonnet-5' }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
22  
23 # The first-party Claude Messages API has native structured output
24 # (output_config.format, GA — ADR 0005 amendment), so response_format is emitted
25 # natively here rather than through the legacy synthesized-tool rewrite that the
26 # /anthropic shim engines still use.
27 213 ▶sub _native_structured_output { 1 }
Subroutine _native_structured_output: called CC=1 SCAR=0.0
28  
29 # Per-model wire corrections (k138 / ADR 0002 amendment). The tool /
30 # structured-output / sampling wire reality on the Claude API is per-MODEL, not
31 # per-engine, so it lives here rather than in `around engine_capabilities`.
32 519 ▶sub model_capability_corrections {
Subroutine model_capability_corrections: called CC=1 SCAR=0.0
Pod undocumented
33 return (
34 # k135 point 1: temperature / top_p / top_k are deprecated on the Messages
35 # API and return a 400 with a non-default value on a GROWING set of models.
36 # The ticket named Opus 4.7/4.8; the verified set (Anthropic thinking/effort
37 # reference, read 2026-09) is broader — every model below rejects them,
38 # while Opus 4.6 / Sonnet 4.6 / Haiku 4.5 and older still accept them.
39 # Clearing the capability makes AnthropicCompatible drop temperature from
40 # the wire for these models (attribute or per-request alike).
41 519 qr/\Aclaude-opus-4-7/ => { temperature => 0 },
42 qr/\Aclaude-opus-4-8/ => { temperature => 0 },
43 qr/\Aclaude-opus-5/ => { temperature => 0 },
44 qr/\Aclaude-sonnet-5/ => { temperature => 0 },
45 qr/\Aclaude-fable-5/ => { temperature => 0 }, # fable-5 and fable-5-1
46 qr/\Aclaude-mythos-5/ => { temperature => 0 }, # mythos-5 and mythos-5-1
47 # k133 point 2: forced tool use (tool_choice type `any` / `tool`) returns a
48 # 400 on Fable 5.1 and Mythos 5.1 only (their 5.0 siblings still allow it).
49 # Clearing the forced-tool caps makes chat_f's auto-rewrite (ADR 0005) route
50 # a forced named tool through native structured output (output_config.format)
51 # instead of emitting a tool_choice the model rejects. tool_choice_auto /
52 # tool_choice_none stay — only `any` and `tool` 400.
53 qr/\Aclaude-fable-5-1/ => { tool_choice_named => 0, tool_choice_any => 0 },
54 qr/\Aclaude-mythos-5-1/ => { tool_choice_named => 0, tool_choice_any => 0 },
55 # image_input (k266, ADR 0019 k266 Update): every Claude 3+ model on the
56 # first-party Messages API takes image blocks (llm-advisor, docs only,
57 # 2026-09-25), so the family keeps the role-derived flag; only the
58 # text-only pre-3 generation clears it.
59 qr/\Aclaude-(?:2|instant)/ => { image_input => 0 },
60 );
61 }
62  
63 54 __PACKAGE__->meta->make_immutable;
64  
65  
66 54 1;
67  
68 __END__
69  
70 =pod
71  
72 =encoding UTF-8
73  
74 =head1 NAME
75  
76 Langertha::Engine::Anthropic - Anthropic API
77  
78 =head1 VERSION
79  
80 version 0.503
81  
82 =head1 SYNOPSIS
83  
84 use Langertha::Engine::Anthropic;
85  
86 my $claude = Langertha::Engine::Anthropic->new(
87 api_key => $ENV{ANTHROPIC_API_KEY},
88 model => 'claude-sonnet-5',
89 );
90  
91 print $claude->simple_chat('Generate Perl Moose classes for GeoJSON');
92  
93 =head1 DESCRIPTION
94  
95 Concrete Anthropic engine for Claude models. Inherits shared
96 Anthropic-compatible behavior from L<Langertha::Engine::AnthropicBase> and
97 provides Anthropic cloud defaults (URL, API key env var, default model).
98  
99 B<THIS API IS WORK IN PROGRESS>
100  
101 =head1 SEE ALSO
102  
103 =over
104  
105 =item * L<Langertha::Engine::AnthropicBase> - Shared Anthropic-compatible implementation
106  
107 =item * L<Langertha::Engine::MiniMax> - Anthropic-compatible MiniMax engine
108  
109 =item * L<Langertha::Engine::LMStudioAnthropic> - Anthropic-compatible LM Studio engine
110  
111 =back
112  
113 =head1 SUPPORT
114  
115 =head2 Issues
116  
117 Please report bugs and feature requests on GitHub at
118 L<https://github.com/Getty/langertha/issues>.
119  
120 =head2 IRC
121  
122 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
123  
124 =head1 CONTRIBUTING
125  
126 Contributions are welcome! Please fork the repository and submit a pull request.
127  
128 =head1 AUTHOR
129  
130 Torsten Raudssus <getty@cpan.org>
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
135  
136 This is free software; you can redistribute it and/or modify it under
137 the same terms as the Perl 5 programming language system itself.
138  
139 =cut
« blib/lib/Langertha/Plugin.pm ↑ Summary blib/lib/Langertha/Engine/MoonshotAnthropic.pm »