AI-Anthropic
view release on metacpan or search on metacpan
lib/AI/Anthropic.pm view on Meta::CPAN
use AI::Anthropic;
my $claude = AI::Anthropic->new;
print $claude->message("Hello, Claude!");
=head2 With image (vision)
my $response = $claude->chat(
messages => [
{
role => 'user',
content => [
{ type => 'text', text => 'What is in this image?' },
{ type => 'image', path => '/path/to/image.jpg' },
],
},
],
);
=head2 Tool use (function calling)
my $response = $claude->chat(
messages => [
{ role => 'user', content => 'What is the weather in London?' },
],
tools => [
{
name => 'get_weather',
description => 'Get current weather for a location',
input_schema => {
type => 'object',
properties => {
location => {
type => 'string',
description => 'City name',
},
},
required => ['location'],
},
},
],
);
=head2 Streaming
$claude->chat(
messages => [ { role => 'user', content => 'Tell me a story' } ],
stream => sub {
my ($chunk) = @_;
print $chunk;
STDOUT->flush;
},
);
=head1 ENVIRONMENT
=over 4
=item ANTHROPIC_API_KEY
Your Anthropic API key. Can be set instead of passing api_key to new().
=back
=head1 SEE ALSO
L<https://docs.anthropic.com/> - Anthropic API documentation
L<OpenAI::API> - Similar module for OpenAI
=head1 AUTHOR
Your Name <your@email.com>
=head1 LICENSE
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
( run in 1.482 second using v1.01-cache-2.11-cpan-d8267643d1d )