Chroma/UA.pm

filter: Statementstmt 41.1% 21 / 51 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 26.6% 4 / 15 Podpod 0.0% 0 / 5 totaltotal 24.0% 25 / 104 CC 13 SCAR 22.3
CC
13
Cov
27%
__ANON__
20.0
__ANON__
12.0
__ANON__
12.0
CRAP 9.3
« Chroma/Collection.pm ↑ Summary Chroma/Embeddings/Ollama.pm »
1 package WebService::Chroma::UA;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Module::Load;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 has base_url => (
9 is => 'ro',
10 );
11  
12 has embeddings_model => (
13 is => 'rw',
14 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
15 0 ▶ if ($_[1] && $_[0]->embeddings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] and $_[0]->embeddings) 0 0 0
Condition0%0/3
$_[1] and $_[0]->embeddings
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] and $_[0]->embeddings
$_[1] $_[0]->embeddings
Truth table0%0/3
A and B
A= $_[1]B= $_[0]->embeddings
ABresult
0X0
100
111
16 0 $_[0]->embeddings->model($_[1]);
17 }
18 }
19 1 );
20  
21 has embeddings_api_key => (
22 is => 'rw',
23 lazy => 1,
24 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
25 0 ▶ if ($_[1] && $_[0]->embeddings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] and $_[0]->embeddings) 0 0 0
Condition0%0/3
$_[1] and $_[0]->embeddings
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] and $_[0]->embeddings
$_[1] $_[0]->embeddings
Truth table0%0/3
A and B
A= $_[1]B= $_[0]->embeddings
ABresult
0X0
100
111
26 0 $_[0]->embeddings->api_key($_[1]);
27 }
28 }
29 1 );
30  
31 has embeddings_base_url => (
32 is => 'rw',
33 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
34 0 ▶ if ($_[1] && $_[0]->embeddings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] and $_[0]->embeddings) 0 0 0
Condition0%0/3
$_[1] and $_[0]->embeddings
!ll&&!rl&&r
000
MC/DC0%0/2
$_[1] and $_[0]->embeddings
$_[1] $_[0]->embeddings
Truth table0%0/3
A and B
A= $_[1]B= $_[0]->embeddings
ABresult
0X0
100
111
35 0 $_[0]->embeddings->base_url($_[1]);
36 }
37 }
38 1 );
39  
40 has embeddings_class => (
41 is => 'ro',
42 0 ▶ trigger => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
43 0 ▶ return unless $_[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[1] 0 0 0
44 0 my $class = 'WebService::Chroma::Embeddings::' . $_[1];
45 0 load $class;
46 0 ▶ $_[0]->embeddings(
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->embeddings_model ? : 0 0 0
$_[0]->embeddings_api_key ? : 0 0 0
47 $class->new(
48 ($_[0]->embeddings_model ? (model => $_[0]->embeddings_model) : ()),
49 ($_[0]->embeddings_api_key ? (api_key => $_[0]->embeddings_api_key) : ()),
50 )
51 );
52 }
53 1 );
54  
55 1 has embeddings => (
56 is => 'rw',
57 );
58  
59 has ua => (
60 is => 'ro',
61 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 0 LWP::UserAgent->new();
63 }
64 1 );
65  
66 has json => (
67 is => 'ro',
68 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 0 JSON->new;
70 }
71 1 );
72  
73 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod undocumented
74 shift->request(
75 0 type => 'GET',
76 @_
77 );
78 }
79  
80 0 ▶sub post {
Subroutine post: not called CC=1 SCAR=6.9
Pod undocumented
81 shift->request(
82 0 type => 'POST',
83 @_
84 );
85 }
86  
87 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
88 shift->request(
89 0 type => 'DELETE',
90 @_
91 );
92 }
93  
94 0 ▶sub request {
Subroutine request: not called CC=3 SCAR=24.8
Pod undocumented
95 0 my ($self, %params) = @_;
96 0 my $url = URI->new($self->base_url . $params{url});
97 0 my $res;
98 0 ▶ if ($params{type} eq 'GET') {
Branch: 2 branches
BranchTrueFalseTotal
if ($params{'type'} eq 'GET') { } 0 0 0
elsif ($params{'type'} eq 'DELETE') { } 0 0 0
99 0 $url->query_form($params{data});
100 0 $res = $self->ua->get($url);
101 } elsif ($params{type} eq 'DELETE') {
102 0 $url->query_form($params{data});
103 0 $res = $self->ua->delete($url);
104 } else {
105 $res = $self->ua->post(
106 $url,
107 0 content => $self->json->encode($params{data}),
108 'Content-Type' => 'application/json'
109 );
110 }
111 0 return $self->response($res);
112 }
113  
114 0 ▶sub response {
Subroutine response: not called CC=2 SCAR=17.9
Pod undocumented
115 0 my ($self, $res) = @_;
116  
117 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) 0 0 0
118 0 my $content = $self->json->decode($res->decoded_content);
119 0 return $content;
120 }
121
122 0 die $res->decoded_content;
123 }
124  
125 1 1;
« Chroma/Collection.pm ↑ Summary Chroma/Embeddings/Ollama.pm »