| 1 | package Langertha::Engine::Cerebras; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Cerebras Inference API | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | our $VERSION = '0.505'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | 14 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | extends 'Langertha::Engine::OpenAIBase'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | with 'Langertha::Role::Tools'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | has '+url' => ( | ||||||||||||||||||||||||||||||||||||||||||
| 13 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 8 | ▶ | default => sub { 'https://api.cerebras.ai/v1' }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 14 | ); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub _build_api_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_api_key: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 19 | return $ENV{LANGERTHA_CEREBRAS_API_KEY} | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | || croak "".(ref $self)." requires LANGERTHA_CEREBRAS_API_KEY or api_key set"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'LANGERTHA_CEREBRAS_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_CEREBRAS_API_KEY or api_key set')
MC/DC0%0/1
$ENV{'LANGERTHA_CEREBRAS_API_KEY'} || croak('' . ref($self) . ' requires LANGERTHA_CEREBRAS_API_KEY or api_key set')
$ENV{'LANGERTHA_CEREBRAS_API_KEY'}
Truth table50%1/2
A
A= $ENV{'LANGERTHA_CEREBRAS_API_KEY'}
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 19 | ▶ | sub default_model { 'gpt-oss-120b' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
default_model: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # Image inputs are base64 data URLs only | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # (inference-docs.cerebras.ai/capabilities/image-inputs), karr k267. | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | sub _content_inline_images_only { 1 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content_inline_images_only: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 19 | ▶ | sub _build_supported_operations {[qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_supported_operations: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | createChatCompletion | ||||||||||||||||||||||||||||||||||||||||||
| 31 | )]} | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # karr #148: the Cerebras API rejects a request that carries both tools and a | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # structured-output response_format of EITHER type (json_object or json_schema) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # with an opaque HTTP 400. Its docs make this per-model, but every model this | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # engine currently serves (gpt-oss-120b default, zai-glm-4.7) rejects the | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # combination, so an all-models matcher (qr//) expresses the platform-wide | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # reality on the model-scoped exclusion seam (Langertha::Role::Chat). There is no | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # shared gpt-oss base rule (removed k184); this all-models rule is Cerebras's only | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # exclusion and refuses both json_object and json_schema alongside tools. Consulted | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # by chat_f and chat_stream_realtime_f. | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 11 | ▶ | sub model_capability_exclusions { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_capability_exclusions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 11 | qr// => \&_exclude_tools_with_any_response_format, | |||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 11 | ▶ | sub _exclude_tools_with_any_response_format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exclude_tools_with_any_response_format: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 11 | my ( $self, %request ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 11 | my $rf = $request{response_format}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 11 | ▶ | my $type = ( ref $rf eq 'HASH' ) ? ( $rf->{type} // '' ) : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$rf{"type"} // ""
MC/DC0%0/1
$$rf{"type"} // ""
$$rf{"type"}
Truth table50%1/2
A
A= $$rf{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | return unless $request{has_tools} | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | ▶ | && ( $type eq 'json_object' || $type eq 'json_schema' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$request{"has_tools"} and $type eq "json_object" || $type eq "json_schema"
$type eq "json_object" or $type eq "json_schema"
MC/DC100%3/3
$request{"has_tools"} and $type eq "json_object" || $type eq "json_schema"
$request{"has_tools"}
$type eq "json_object"
$type eq "json_schema"
Truth table100%4/4
A and B or C
A= $request{"has_tools"}B= $type eq "json_object"C= $type eq "json_schema"
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | croak "".(ref $self)." cannot combine tools and response_format in one " | |||||||||||||||||||||||||||||||||||||||||
| 55 | ."request: the Cerebras API rejects this combination with HTTP 400. Send " | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ."tools or response_format, not both (run the tools first, then a second " | ||||||||||||||||||||||||||||||||||||||||||
| 57 | ."structured-output turn)."; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | # image_input (k266, ADR 0019 k266 Update): only the vision models take image | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # input (inference-docs.cerebras.ai/capabilities/image-inputs, public preview, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | # base64 PNG/JPEG only -- URL images are inlined by _content_inline_images_only; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | # llm-advisor, docs only, 2026-09-25). The catch-all first row clears the flag, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # so the default gpt-oss-120b and unknown ids make no claim. | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 117 | ▶ | sub model_capability_corrections { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
model_capability_corrections: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 117 | qr/\A/ => { image_input => 0 }, | |||||||||||||||||||||||||||||||||||||||||
| 68 | qr/\A(?:qwen-3\.8-27b|gemma-4-31b|kimi-k2\.7-code)/ => { image_input => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||||||||||||||||