blib/lib/Langertha/Engine/Replicate.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 88.8% 32 / 36 CC 2 SCAR 2.7
CC
2
Cov
92%
_build_api_key
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Langertha/Role/Models.pm ↑ Summary blib/lib/Langertha/Engine/LMStudioAnthropic.pm »
1 package Langertha::Engine::Replicate;
2 # ABSTRACT: Replicate API
3 7 our $VERSION = '0.503';
4 7 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 7 extends 'Langertha::Engine::OpenAIBase';
8  
9 7 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 7 );
16  
17 1 ▶sub _build_api_key {
Subroutine _build_api_key: called CC=2 SCAR=8.1
18 1 my ( $self ) = @_;
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 12 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
26 createChatCompletion
27 )]}
28  
29 # Replicate's OpenAPI (api.replicate.com/openapi.json) has no chat/completions
30 # path, so nothing documents parallel_tool_calls: clear parallel_tool_use
31 # (karr k242, docs only; the endpoint question itself is karr k243).
32 54 ▶around engine_capabilities => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 54 my ( $orig, $self, @rest ) = @_;
34 54 my $caps = $self->$orig(@rest);
35 54 delete $caps->{parallel_tool_use};
36 # image_input (k266, ADR 0019): a gateway: the model behind it is unknown to the client, so no claim.
37 54 delete $caps->{image_input};
38 54 return $caps;
39 7 };
40  
41 7 __PACKAGE__->meta->make_immutable;
42  
43  
44 7 1;
45  
46 __END__
47  
48 =pod
49  
50 =encoding UTF-8
51  
52 =head1 NAME
53  
54 Langertha::Engine::Replicate - Replicate API
55  
56 =head1 VERSION
57  
58 version 0.503
59  
60 =head1 SYNOPSIS
61  
62 use Langertha::Engine::Replicate;
63  
64 my $replicate = Langertha::Engine::Replicate->new(
65 api_key => $ENV{REPLICATE_API_TOKEN},
66 model => 'meta/llama-4-maverick',
67 );
68  
69 print $replicate->simple_chat('Hello from Perl!');
70  
71 # Streaming
72 $replicate->simple_chat_stream(sub {
73 print shift->content;
74 }, 'Write a Perl haiku');
75  
76 =head1 DESCRIPTION
77  
78 Replicate hosts thousands of open-source models with pay-per-use pricing.
79 This engine speaks the OpenAI C</chat/completions> wire format and, by
80 default, POSTs to C<https://api.replicate.com/v1/chat/completions>.
81  
82 B<Unverified against the hosted API.> Replicate's official OpenAPI document
83 (C<https://api.replicate.com/openapi.json>, checked 2026-09-25) lists no
84 C</chat/completions> path, only C</predictions>, C</models/{owner}/{name}/predictions>,
85 C</deployments/...> and similar, and its documentation index
86 (C<https://replicate.com/docs/llms.txt>) has no OpenAI-compatibility page. The
87 OpenAI-compatible examples on Replicate model pages are for a Cog container run
88 locally. The project has no Replicate key, so whether the hosted endpoint
89 answers has never been tested. To talk to a locally run Cog container or an
90 OpenAI-compatible proxy in front of Replicate, set C<url> to that server's
91 base URL (for example C<http://localhost:5000/v1>).
92  
93 Model names use C<owner/model> format (e.g., C<meta/llama-4-maverick>,
94 C<meta/llama-4-scout>). No default model is set; C<model> must be specified
95 explicitly.
96  
97 Chat, streaming, and MCP tool calling use the OpenAI wire format as above.
98 Embeddings and transcription are not supported through this interface.
99  
100 Get your API token at L<https://replicate.com/account/api-tokens> and set
101 C<LANGERTHA_REPLICATE_API_KEY> in your environment.
102  
103 B<THIS API IS WORK IN PROGRESS>
104  
105 =head1 SEE ALSO
106  
107 =over
108  
109 =item * L<https://www.replicatestatus.com/> - Replicate service status
110  
111 =item * L<https://replicate.com/explore> - Browse available models
112  
113 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role
114  
115 =back
116  
117 =head1 SUPPORT
118  
119 =head2 Issues
120  
121 Please report bugs and feature requests on GitHub at
122 L<https://github.com/Getty/langertha/issues>.
123  
124 =head2 IRC
125  
126 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
127  
128 =head1 CONTRIBUTING
129  
130 Contributions are welcome! Please fork the repository and submit a pull request.
131  
132 =head1 AUTHOR
133  
134 Torsten Raudssus <getty@cpan.org>
135  
136 =head1 COPYRIGHT AND LICENSE
137  
138 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
139  
140 This is free software; you can redistribute it and/or modify it under
141 the same terms as the Perl 5 programming language system itself.
142  
143 =cut
« blib/lib/Langertha/Role/Models.pm ↑ Summary blib/lib/Langertha/Engine/LMStudioAnthropic.pm »