Langertha/Engine/Perplexity.pm

filter: Statementstmt 100% 18 / 18 Branchbran n/a Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 87.1% 27 / 31 CC 2 SCAR 2.7
CC
2
Cov
90%
_build_api_key
2.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.3
« Langertha/Engine/Mistral.pm ↑ Summary Langertha/Engine/Remote.pm »
1 package Langertha::Engine::Perplexity;
2 # ABSTRACT: Perplexity Sonar API
3 4 our $VERSION = '0.502';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 extends 'Langertha::Engine::OpenAIBase';
8  
9 4 with 'Langertha::Role::StaticModels';
10  
11  
12 2 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
13 createChatCompletion
14 )]}
15  
16 has '+url' => (
17 lazy => 1,
18 1 ▶ default => sub { 'https://api.perplexity.ai' },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 4 );
20  
21 sub _build_api_key {
22 1 ▶ my ( $self ) = @_;
Subroutine _build_api_key: called CC=2 SCAR=8.1
23 return $ENV{LANGERTHA_PERPLEXITY_API_KEY}
24 1 ▶ || croak "".(ref $self)." requires LANGERTHA_PERPLEXITY_API_KEY or api_key set";
Condition33%1/3
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
l!l&&r!l&&!r
100
MC/DC0%0/2
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
$ENV{'LANGERTHA_PERPLEXITY_API_KEY'} croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
Truth table33%1/3
A || B
A= $ENV{'LANGERTHA_PERPLEXITY_API_KEY'}B= croak('' . ref($self) . ' requires LANGERTHA_PERPLEXITY_API_KEY or api_key set')
ABresult
1X1
011
000
25 }
26  
27 1 ▶sub default_model { 'sonar' }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
28  
29 sub _build_static_models {[
30 1 ▶ { id => 'sonar' },
Subroutine _build_static_models: called CC=1 SCAR=0.0
31 { id => 'sonar-pro' },
32 { id => 'sonar-reasoning' },
33 { id => 'sonar-reasoning-pro' },
34 ]}
35  
36 4 __PACKAGE__->meta->make_immutable;
37  
38  
39 4 1;
40  
41 __END__
42  
43 =pod
44  
45 =encoding UTF-8
46  
47 =head1 NAME
48  
49 Langertha::Engine::Perplexity - Perplexity Sonar API
50  
51 =head1 VERSION
52  
53 version 0.502
54  
55 =head1 SYNOPSIS
56  
57 use Langertha::Engine::Perplexity;
58  
59 my $perplexity = Langertha::Engine::Perplexity->new(
60 api_key => $ENV{PERPLEXITY_API_KEY},
61 model => 'sonar-pro',
62 );
63  
64 print $perplexity->simple_chat('What are the latest Perl releases?');
65  
66 # Streaming
67 $perplexity->simple_chat_stream(sub {
68 print shift->content;
69 }, 'Summarize recent Perl news');
70  
71 # Async with Future::AsyncAwait
72 use Future::AsyncAwait;
73 my $response = await $perplexity->simple_chat_f('What is new in Perl?');
74  
75 =head1 DESCRIPTION
76  
77 Provides access to Perplexity's Sonar API. Composes
78 L<Langertha::Role::OpenAICompatible> with Perplexity's endpoint
79 (C<https://api.perplexity.ai>). Perplexity models are search-augmented
80 LLMs with real-time web access; responses include citations alongside
81 generated text.
82  
83 Available models: C<sonar> (default, fast), C<sonar-pro> (deeper analysis),
84 C<sonar-reasoning> (chain-of-thought), C<sonar-reasoning-pro> (most capable).
85  
86 Limitations: tool calling, embeddings, and transcription are not supported.
87 Only chat and streaming are available.
88  
89 Get your API key at L<https://www.perplexity.ai/settings/api> and set
90 C<LANGERTHA_PERPLEXITY_API_KEY>.
91  
92 B<THIS API IS WORK IN PROGRESS>
93  
94 =head1 SEE ALSO
95  
96 =over
97  
98 =item * L<https://status.perplexity.com/> - Perplexity service status
99  
100 =item * L<https://docs.perplexity.ai/> - Official Perplexity API documentation
101  
102 =item * L<Langertha::Role::OpenAICompatible> - OpenAI API format role
103  
104 =item * L<Langertha::Engine::DeepSeek> - Another search-augmented engine (web-aware reasoning)
105  
106 =back
107  
108 =head1 SUPPORT
109  
110 =head2 Issues
111  
112 Please report bugs and feature requests on GitHub at
113 L<https://github.com/Getty/langertha/issues>.
114  
115 =head2 IRC
116  
117 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
118  
119 =head1 CONTRIBUTING
120  
121 Contributions are welcome! Please fork the repository and submit a pull request.
122  
123 =head1 AUTHOR
124  
125 Torsten Raudssus <getty@cpan.org>
126  
127 =head1 COPYRIGHT AND LICENSE
128  
129 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
130  
131 This is free software; you can redistribute it and/or modify it under
132 the same terms as the Perl 5 programming language system itself.
133  
134 =cut
« Langertha/Engine/Mistral.pm ↑ Summary Langertha/Engine/Remote.pm »