AI-Anthropic
view release on metacpan or search on metacpan
],
);
# From URL
my $response = $claude->chat(
messages => [
{
role => 'user',
content => [
{ type => 'text', text => 'Describe this image' },
{ type => 'image', url => 'https://example.com/image.png' },
],
},
],
);
```
## Tool Use (Function Calling)
```perl
my $response = $claude->chat(
lib/AI/Anthropic.pm view on Meta::CPAN
# Load image from file
push @parts, $self->_image_from_file($part->{path});
} elsif ($part->{type} eq 'image' && $part->{url}) {
# Load image from URL
push @parts, $self->_image_from_url($part->{url});
} elsif ($part->{type} eq 'image' && $part->{base64}) {
push @parts, {
type => 'image',
source => {
type => 'base64',
media_type => $part->{media_type} // 'image/png',
data => $part->{base64},
},
};
} else {
push @parts, $part;
}
}
push @normalized, { role => $msg->{role}, content => \@parts };
} else {
push @normalized, $msg;
lib/AI/Anthropic.pm view on Meta::CPAN
sub _image_from_file {
my ($self, $path) = @_;
open my $fh, '<:raw', $path
or croak "Cannot open image file '$path': $!";
local $/;
my $data = <$fh>;
close $fh;
# Detect media type
my $media_type = 'image/png';
if ($path =~ /\.jpe?g$/i) {
$media_type = 'image/jpeg';
} elsif ($path =~ /\.gif$/i) {
$media_type = 'image/gif';
} elsif ($path =~ /\.webp$/i) {
$media_type = 'image/webp';
}
return {
type => 'image',
( run in 1.997 second using v1.01-cache-2.11-cpan-df04353d9ac )