| 1 | package SignalWire::Agents::Skills::Builtin::ApiNinjasTrivia; | ||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | extends 'SignalWire::Agents::Skills::SkillBase'; | |||||||||||
| 6 | |||||||||||||
| 7 | 3 | ▶ | use SignalWire::Agents::Skills::SkillRegistry; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 3 | SignalWire::Agents::Skills::SkillRegistry->register_skill('api_ninjas_trivia', __PACKAGE__); | |||||||||||
| 9 | |||||||||||||
| 10 | 10 | ▶ | has '+skill_name' => (default => sub { 'api_ninjas_trivia' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 10 | ▶ | has '+skill_description' => (default => sub { 'Get trivia questions from API Ninjas' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 10 | ▶ | has '+supports_multiple_instances' => (default => sub { 1 }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 3 | my @ALL_CATEGORIES = qw( | |||||||||||
| 15 | artliterature language sciencenature general fooddrink | ||||||||||||
| 16 | peopleplaces geography historyholidays entertainment | ||||||||||||
| 17 | toysgames music mathematics religionmythology | ||||||||||||
| 18 | sportsleisure | ||||||||||||
| 19 | ); | ||||||||||||
| 20 | |||||||||||||
| 21 | 6 | ▶ | sub setup { 1 } | ||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 22 | |||||||||||||
| 23 | 5 | ▶ | sub register_tools { | ||||||||||
|
Subroutine
register_tools: called CC=4 SCAR=14.8
Pod
undocumented
| |||||||||||||
| 24 | 5 | my ($self) = @_; | |||||||||||
| 25 | 5 | ▶ | my $tool_name = $self->params->{tool_name} // 'get_trivia'; | ||||||||||
|
Condition100%2/2
$self->params->{"tool_name"} // "get_trivia"
MC/DC100%1/1
$self->params->{"tool_name"} // "get_trivia"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
| |||||||||||||
| 26 | 5 | ▶ | my $api_key = $self->params->{api_key} // ''; | ||||||||||
|
Condition50%1/2
$self->params->{"api_key"} // ""
MC/DC0%0/1
$self->params->{"api_key"} // ""
$self->params->{"api_key"}
Truth table50%1/2
A
A= $self->params->{"api_key"}
| |||||||||||||
| 27 | 5 | ▶ | my $categories = $self->params->{categories} // [@ALL_CATEGORIES]; | ||||||||||
|
Condition100%2/2
$self->params->{"categories"} // [@ALL_CATEGORIES]
MC/DC100%1/1
$self->params->{"categories"} // [@ALL_CATEGORIES]
$self->params->{"categories"}
Truth table100%2/2
A
A= $self->params->{"categories"}
| |||||||||||||
| 28 | |||||||||||||
| 29 | $self->define_tool( | ||||||||||||
| 30 | name => $tool_name, | ||||||||||||
| 31 | description => "Get trivia questions for $tool_name", | ||||||||||||
| 32 | parameters => { | ||||||||||||
| 33 | type => 'object', | ||||||||||||
| 34 | properties => { | ||||||||||||
| 35 | category => { | ||||||||||||
| 36 | type => 'string', | ||||||||||||
| 37 | description => 'The trivia category', | ||||||||||||
| 38 | enum => $categories, | ||||||||||||
| 39 | }, | ||||||||||||
| 40 | }, | ||||||||||||
| 41 | required => ['category'], | ||||||||||||
| 42 | }, | ||||||||||||
| 43 | 0 | ▶ | handler => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 44 | 0 | my ($args, $raw) = @_; | |||||||||||
| 45 | 0 | require SignalWire::Agents::SWAIG::FunctionResult; | |||||||||||
| 46 | 0 | return SignalWire::Agents::SWAIG::FunctionResult->new( | |||||||||||
| 47 | response => "Trivia category: $args->{category} (API call would be made with key)" | ||||||||||||
| 48 | ); | ||||||||||||
| 49 | }, | ||||||||||||
| 50 | 5 | ); | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | sub get_parameter_schema { | ||||||||||
|
Subroutine
get_parameter_schema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 54 | return { | ||||||||||||
| 55 | 1 | %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, | |||||||||||
| 56 | api_key => { type => 'string', required => 1, hidden => 1 }, | ||||||||||||
| 57 | categories => { type => 'array', default => [@ALL_CATEGORIES] }, | ||||||||||||
| 58 | tool_name => { type => 'string', default => 'get_trivia' }, | ||||||||||||
| 59 | }; | ||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 3 | 1; | |||||||||||