Langertha/Role/Embedding.pm

filter: Statementstmt 75.0% 18 / 24 Branchbran 50.0% 2 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 64.2% 27 / 42 CC 5 SCAR 16.2
CC
5
Cov
62%
simple_embedding
12.0
_build_embedding_model
3.5
BEGIN
1.0
CRAP 5.0
« Langertha/Role/ParallelToolUse.pm ↑ Summary Langertha/Input/Tools.pm »
1 package Langertha::Role::Embedding;
2 # ABSTRACT: Role for APIs with embedding functionality
3 28 our $VERSION = '0.502';
4 28 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 28 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6 28 ▶use Log::Any qw( $log );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 28 requires qw(
9 embedding_request
10 embedding_response
11 );
12  
13 28 has embedding_model => (
14 is => 'ro',
15 isa => 'Maybe[Str]',
16 lazy_build => 1,
17 );
18 sub _build_embedding_model {
19 1 ▶ my ( $self ) = @_;
Subroutine _build_embedding_model: called CC=3 SCAR=12.5
20 1 ▶ croak "".(ref $self)." can't handle models!" unless $self->does('Langertha::Role::Models');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->does("Langertha::Role::Models") 0 1 1
21 1 ▶ return $self->default_embedding_model if $self->can('default_embedding_model');
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("default_embedding_model") 1 0 1
22 0 return $self->model;
23 }
24  
25  
26 sub embedding {
27 2 ▶ my ( $self, $text ) = @_;
Subroutine embedding: called CC=1 SCAR=0.0
Pod documented
28 2 return $self->embedding_request($text);
29 }
30  
31  
32 sub simple_embedding {
33 0 ▶ my ( $self, $text ) = @_;
Subroutine simple_embedding: not called CC=3 SCAR=24.8
Pod documented
34 0 ▶ $log->debugf("[%s] simple_embedding, model=%s, input_length=%d",
Condition0%0/4
$self->embedding_model // "default"
l!l
00
$text // ""
l!l
00
MC/DC0%0/1
$self->embedding_model // "default"
$self->embedding_model
MC/DC0%0/1
$text // ""
$text
Truth table0%0/2
A
A= $self->embedding_model
Aresult
11
00
Truth table0%0/2
A
A= $text
Aresult
11
00
35 ref $self, $self->embedding_model // 'default', length($text // ''));
36 0 my $request = $self->embedding($text);
37 0 my $response = $self->user_agent->request($request);
38 0 return $request->response_call->($response);
39 }
40  
41  
42  
43 28 1;
44  
45 __END__
46  
47 =pod
48  
49 =encoding UTF-8
50  
51 =head1 NAME
52  
53 Langertha::Role::Embedding - Role for APIs with embedding functionality
54  
55 =head1 VERSION
56  
57 version 0.502
58  
59 =head2 embedding_model
60  
61 The model name to use for embedding requests. Lazily defaults to
62 C<default_embedding_model> if the engine provides it, otherwise falls back
63 to the general C<model> attribute from L<Langertha::Role::Models>.
64  
65 =head2 embedding
66  
67 my $request = $engine->embedding($text);
68  
69 Builds and returns an embedding HTTP request object for the given C<$text>.
70 Use L</simple_embedding> to execute the request and get the result directly.
71  
72 =head2 simple_embedding
73  
74 my $vector = $engine->simple_embedding($text);
75  
76 Sends an embedding request for C<$text> and returns the embedding vector.
77 Blocks until the request completes.
78  
79 =head1 SEE ALSO
80  
81 =over
82  
83 =item * L<Langertha::Role::HTTP> - HTTP transport layer
84  
85 =item * L<Langertha::Role::Models> - Model selection (provides C<embedding_model>)
86  
87 =back
88  
89 =head1 SUPPORT
90  
91 =head2 Issues
92  
93 Please report bugs and feature requests on GitHub at
94 L<https://github.com/Getty/langertha/issues>.
95  
96 =head2 IRC
97  
98 Join C<#langertha> on C<irc.perl.org> or message Getty directly.
99  
100 =head1 CONTRIBUTING
101  
102 Contributions are welcome! Please fork the repository and submit a pull request.
103  
104 =head1 AUTHOR
105  
106 Torsten Raudssus <getty@cpan.org>
107  
108 =head1 COPYRIGHT AND LICENSE
109  
110 This software is copyright (c) 2026 by Torsten Raudssus L<https://raudssus.de/>.
111  
112 This is free software; you can redistribute it and/or modify it under
113 the same terms as the Perl 5 programming language system itself.
114  
115 =cut
« Langertha/Role/ParallelToolUse.pm ↑ Summary Langertha/Input/Tools.pm »