blib/lib/Langertha/Role/ImageGeneration.pm

filter: Statementstmt 90.5% 48 / 53 Branchbran 41.6% 5 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 3 / 3 totaltotal 83.3% 65 / 78 CC 8 SCAR 10.9
CC
8
Cov
82%
_build_image_model
5.9
_build_image_model
5.9
simple_image_result
2.0
CRAP 3.0
« blib/lib/Langertha/Engine/Cerebras.pm ↑ Summary blib/lib/Langertha/Engine/OpenRouter.pm »
1 package Langertha::Role::ImageGeneration;
2 # ABSTRACT: Role for engines that support image generation
3 113 our $VERSION = '0.505';
4 113 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 113 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 113 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 113 ▶use Time::HiRes qw( gettimeofday tv_interval );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 113 ▶use Langertha::CallResult;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # simple_image_f sends through the engine's async backend (k292): injected
11 # client > Net::Async::HTTP > the sync LWP shim (ADR 0027).
12 113 with 'Langertha::Role::AsyncHTTP';
13  
14  
15 113 requires 'image_request';
16 113 requires 'simple_image';
17  
18 113 has image_model => (
19 is => 'ro',
20 isa => 'Maybe[Str]',
21 lazy_build => 1,
22 );
23 23 ▶sub _build_image_model {
Subroutine _build_image_model: called CC=3 SCAR=17.8
24 0 ▶ my ( $self ) = @_;
Subroutine _build_image_model: not called CC=3 SCAR=17.8
25 0 ▶ croak "".(ref $self)." can't handle models!" unless $self->does('Langertha::Role::Models');
Branch: 2 branches
BranchTrueFalseTotal
unless $self->does("Langertha::Role::Models") 0 23 23
unless $self->does("Langertha::Role::Models") 0 0 0
26 0 ▶ return $self->default_image_model if $self->can('default_image_model');
Branch: 2 branches
BranchTrueFalseTotal
if $self->can("default_image_model") 23 0 23
if $self->can("default_image_model") 0 0 0
27 0 return $self->model;
28 }
29  
30  
31 9 ▶async sub simple_image_f {
Subroutine simple_image_f: called CC=1 SCAR=0.0
Pod documented
32 9 my ( $self, $prompt, %extra ) = @_;
33 9 my $request = $self->image_request($prompt, %extra);
34 9 my $response = await $self->_async_do_request_f( request => $request );
35 8 return $request->response_call->($response);
36 113 }
37  
38  
39 2 ▶sub simple_image_result {
Subroutine simple_image_result: called CC=2 SCAR=7.0
Pod documented
40 2 my ( $self, $prompt, %extra ) = @_;
41 2 ▶ my $model = exists $extra{model} ? $extra{model} : $self->image_model;
Branch: 1 branch
BranchTrueFalseTotal
exists $extra{'model'} ? : 0 2 2
42 2 my $request = $self->image_request($prompt, %extra);
43 2 my $t0 = [gettimeofday];
44 2 my $response = $self->user_agent->request($request);
45 2 my $elapsed = tv_interval($t0);
46 2 my $value = $request->response_call->($response);
47 2 return Langertha::CallResult->from_http_response( $self, $response,
48 value => $value, model => $model, total_seconds => $elapsed );
49 }
50  
51  
52 7 ▶async sub simple_image_result_f {
Subroutine simple_image_result_f: called CC=2 SCAR=6.9
Pod documented
53 7 my ( $self, $prompt, %extra ) = @_;
54 7 ▶ my $model = exists $extra{model} ? $extra{model} : $self->image_model;
Branch: 1 branch
BranchTrueFalseTotal
exists $extra{'model'} ? : 2 5 7
55 7 my $request = $self->image_request($prompt, %extra);
56 7 my $t0 = [gettimeofday];
57 7 my $response = await $self->_async_do_request_f( request => $request );
58 7 my $elapsed = tv_interval($t0);
59 7 my $value = $request->response_call->($response);
60 6 return Langertha::CallResult->from_http_response( $self, $response,
61 value => $value, model => $model, total_seconds => $elapsed );
62 113 }
63  
64  
65  
66 113 1;
67  
68 __END__
« blib/lib/Langertha/Engine/Cerebras.pm ↑ Summary blib/lib/Langertha/Engine/OpenRouter.pm »