blib/lib/Langertha/Engine/XAI.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 33.3% 1 / 3 totaltotal 90.9% 40 / 44 CC 3 SCAR 3.2
CC
3
Cov
97%
_build_api_key
2.1
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« blib/lib/Langertha/Manifest/Auth.pm ↑ Summary blib/lib/Langertha/Content.pm »
1 package Langertha::Engine::XAI;
2 # ABSTRACT: xAI Grok API
3 12 our $VERSION = '0.505';
4 12 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use Carp qw( carp croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 extends 'Langertha::Engine::OpenAIBase';
8  
9 # StreamUsage: ChatRequest.stream_options.include_usage is in the OpenAPI spec
10 # (docs.x.ai/openapi.json, ADR 0038).
11 12 with map { 'Langertha::Role::'.$_ } qw(
12 ImageGeneration
13 Tools
14 StreamUsage
15 );
16  
17  
18 38 ▶sub _build_supported_operations {[qw(
Subroutine _build_supported_operations: called CC=1 SCAR=0.0
19 createChatCompletion
20 createImage
21 )]}
22  
23 has '+url' => (
24 lazy => 1,
25 27 ▶ default => sub { 'https://api.x.ai/v1' },
Subroutine __ANON__: called CC=1 SCAR=0.0
26 12 );
27  
28 1 ▶sub _build_api_key {
Subroutine _build_api_key: called CC=2 SCAR=7.2
29 1 my ( $self ) = @_;
30 return $ENV{LANGERTHA_XAI_API_KEY}
31 1 ▶ || croak "".(ref $self)." requires LANGERTHA_XAI_API_KEY or api_key set";
Condition50%1/2
$ENV{'LANGERTHA_XAI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_XAI_API_KEY or api_key set')
l!l
10
MC/DC0%0/1
$ENV{'LANGERTHA_XAI_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_XAI_API_KEY or api_key set')
$ENV{'LANGERTHA_XAI_API_KEY'}
Truth table50%1/2
A
A= $ENV{'LANGERTHA_XAI_API_KEY'}
Aresult
11
00
32 }
33  
34 16 ▶sub default_model { 'grok-4.7' }
Subroutine default_model: called CC=1 SCAR=0.0
Pod documented
35  
36 # image_input (k266, k280, ADR 0019 k266 Update): every grok-4 chat model in
37 # the docs.x.ai catalogue lists text+image input -- grok-4.3, 4.5, 4.6, 4.7,
38 # the grok-4.20 family and grok-build-0.1 (aliases grok-code-fast-1 /
39 # grok-code-fast); retired grok-4-0709 / grok-4-fast-* / grok-4-1-fast-*
40 # redirect to grok-4.3 (llm-advisor, docs only, read 2026-09-25). Other
41 # families are unchecked, so the catch-all first row clears the flag.
42 142 ▶sub model_capability_corrections {
Subroutine model_capability_corrections: called CC=1 SCAR=0.0
Pod undocumented
43 return (
44 142 qr/\A/ => { image_input => 0 },
45 qr/\Agrok-4(?:[.-]|\z)/ => { image_input => 1 },
46 qr/\Agrok-(?:build-|code-fast)/ => { image_input => 1 },
47 );
48 }
49  
50 2 ▶sub default_image_model { 'grok-imagine-image-2.0' }
Subroutine default_image_model: called CC=1 SCAR=0.0
Pod undocumented
51  
52 # xAI's /v1/images/generations takes aspect_ratio and resolution in place of
53 # OpenAI's size / quality / style and does not accept those; one passed in
54 # (Langertha::ImageGen forwards size and quality) is dropped with a warning,
55 # as k308 drops response_format for gpt-image. -- karr k309
56 4 ▶around image_request => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
57 4 my ( $orig, $self, $prompt, %extra ) = @_;
58 4 ▶ if ( my @unsupported = grep { exists $extra{$_} } qw( quality size style ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@unsupported) = grep({exists $extra{$_};} "quality", "size", "style")) 2 2 4
59 2 delete @extra{@unsupported};
60 2 carp "".(ref $self)." image_request: xAI does not take "
61 . join( ', ', @unsupported ) . " (use aspect_ratio / resolution); dropped";
62 }
63 4 return $self->$orig( $prompt, %extra );
64 12 };
65  
66  
67 12 __PACKAGE__->meta->make_immutable;
68  
69  
70 12 1;
71  
72 __END__
« blib/lib/Langertha/Manifest/Auth.pm ↑ Summary blib/lib/Langertha/Content.pm »