Langertha/Engine/Replicate.pm

filter: Statementstmt 100% 17 / 17 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 86.2% 25 / 29 CC 2 SCAR 3.1
CC
2
Cov
90%
_build_api_key
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Langertha/Engine/OpenRouter.pm ↑ Summary Langertha/Engine/Scaleway.pm »
1 package Langertha::Engine::Replicate;
2 # ABSTRACT: Replicate API
3 3 our $VERSION = '0.502';
4 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 extends 'Langertha::Engine::OpenAIBase';
8  
9 3 with 'Langertha::Role::Tools';
10  
11  
12 has '+url' => (
13 lazy => 1,
14 2 ▶ default => sub { 'https://api.replicate.com/v1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 3 );
16  
17 sub _build_api_key {
18 1 ▶ my ( $self ) = @_;
Subroutine _build_api_key: called CC=2 SCAR=8.1
19 return $ENV{LANGERTHA_REPLICATE_API_KEY}
20 1 ▶ || croak "".(ref $self)." requires LANGERTHA_REPLICATE_API_KEY or api_key set";
Condition33%1/3
$ENV{'LANGERTHA_REPLICATE_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_REPLICATE_API_KEY or api_key set')
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'LANGERTHA_REPLICATE_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_REPLICATE_API_KEY or api_key set')
$ENV{'LANGERTHA_REPLICATE_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_REPLICATE_API_KEY or api_key set')
Truth table33%1/3
A || B
A= $ENV{'LANGERTHA_REPLICATE_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_REPLICATE_API_KEY or api_key set')
ABresult
1X1
011
000
21 }
22  
23 1 ▶sub default_model { croak "".(ref $_[0])." requires model to be set" }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
24  
25 1 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
26 createChatCompletion
27 )]}
28  
29 3 __PACKAGE__->meta->make_immutable;
30  
31  
32 3 1;
33  
34 __END__
35  
36 =pod
37  
38 =encoding UTF-8
39  
40 =head1 NAME
41  
42 Langertha::Engine::Replicate - Replicate API
43  
44 =head1 VERSION
45  
46 version 0.502
47  
48 =head1 SYNOPSIS
49  
50 use Langertha::Engine::Replicate;
51  
52 my $replicate = Langertha::Engine::Replicate->new(
53 api_key => $ENV{REPLICATE_API_TOKEN},
54 model => 'meta/llama-4-maverick',
55 );
56  
57 print $replicate->simple_chat('Hello from Perl!');
58  
59 # Streaming
60 $replicate->simple_chat_stream(sub {
61 print shift->content;
62 }, 'Write a Perl haiku');
63  
64 =head1 DESCRIPTION
65  
66 Provides access to Replicate's OpenAI-compatible chat endpoint. Replicate
67 hosts thousands of open-source models with pay-per-use pricing.
68  
69 Model names use C<owner/model> format (e.g., C<meta/llama-4-maverick>,
70 C<meta/llama-4-scout>). No default model is set; C<model> must be specified
71 explicitly.
72  
73 Supports chat, streaming, and MCP tool calling via the OpenAI-compatible
74 endpoint at C<https://api.replicate.com/v1>. Embeddings and transcription
75 are not supported through this interface.
76  
77 Get your API token at L<https://replicate.com/account/api-tokens> and set
78 C<LANGERTHA_REPLICATE_API_KEY> in your environment.
79  
80 B<THIS API IS WORK IN PROGRESS>
81  
82 =head1 SEE ALSO
83  
84 =over
85  
86 =item * L<https://www.replicatestatus.com/> - Replicate service status
87  
88 =item * L<https://replicate.com/docs/topics/openai-compatibility> - Replicate OpenAI compatibility docs
89  
90 =item * L<https://replicate.com/explore> - Browse available models
91  
92 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role
93  
94 =back
95  
96 =head1 SUPPORT
97  
98 =head2 Issues
99  
100 Please report bugs and feature requests on GitHub at
101 L<https://github.com/Getty/langertha/issues>.
102  
103 =head2 IRC
104  
105 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
106  
107 =head1 CONTRIBUTING
108  
109 Contributions are welcome! Please fork the repository and submit a pull request.
110  
111 =head1 AUTHOR
112  
113 Torsten Raudssus <getty@cpan.org>
114  
115 =head1 COPYRIGHT AND LICENSE
116  
117 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
118  
119 This is free software; you can redistribute it and/or modify it under
120 the same terms as the Perl 5 programming language system itself.
121  
122 =cut
« Langertha/Engine/OpenRouter.pm ↑ Summary Langertha/Engine/Scaleway.pm »