Langertha
view release on metacpan or search on metacpan
lib/Langertha/Engine/AnthropicBase.pm view on Meta::CPAN
has inference_geo => (
is => 'ro',
isa => 'Str',
predicate => 'has_inference_geo',
);
sub update_request {
my ( $self, $request ) = @_;
$request->header('x-api-key', $self->api_key);
$request->header('content-type', 'application/json');
$request->header('anthropic-version', $self->api_version);
}
sub default_model { croak "".(ref $_[0])." requires model to be set" }
sub chat_request {
my ( $self, $messages, %extra ) = @_;
# Anthropic has no native response_format. Translate json_object /
# json_schema response_format hashes into a synthesized tool + forced
lib/Langertha/Engine/Gemini.pm view on Meta::CPAN
return $self->generate_http_request(
POST => $url,
sub { $self->chat_response(shift) },
%request_body,
%extra,
);
}
sub update_request {
my ( $self, $request ) = @_;
$request->header('content-type', 'application/json');
}
sub chat_response {
my ( $self, $response ) = @_;
my $data = $self->parse_response($response);
# Gemini response format: candidates[0].content.parts[].text
my $candidates = $data->{candidates} || [];
my $text = '';
my $finish_reason;
t/10_engine_hierarchy.t view on Meta::CPAN
ok(Langertha::Engine::Anthropic->does('Langertha::Role::Streaming'), 'Anthropic does Streaming');
ok(Langertha::Engine::Anthropic->does('Langertha::Role::Tools'), 'Anthropic does Tools');
ok(!Langertha::Engine::Anthropic->does('Langertha::Role::OpenAICompatible'), 'Anthropic does NOT OpenAICompatible');
{
my $a = Langertha::Engine::Anthropic->new(api_key => 'test-key');
is($a->url, 'https://api.anthropic.com', 'Anthropic url defaults correctly');
is($a->default_model, 'claude-sonnet-4-6', 'Anthropic default_model');
my $req = $a->chat('hello');
is($req->header('x-api-key'), 'test-key', 'Anthropic uses x-api-key header');
is($req->header('content-type'), 'application/json', 'Anthropic sets content-type');
like($req->uri, qr{/v1/messages$}, 'Anthropic chat endpoint');
}
# --- Gemini ---
use Langertha::Engine::Gemini;
ok(Langertha::Engine::Gemini->isa('Langertha::Engine::Remote'), 'Gemini isa Remote');
ok(!Langertha::Engine::Gemini->isa('Langertha::Engine::OpenAIBase'), 'Gemini is NOT OpenAIBase');
ok(Langertha::Engine::Gemini->does('Langertha::Role::Chat'), 'Gemini does Chat');
( run in 0.842 second using v1.01-cache-2.11-cpan-524268b4103 )