File Coverage

blib/lib/SignalWire/Agents/Skills/Builtin/ApiNinjasTrivia.pm
Criterion Covered Total %
statement 20 23 86.9
branch n/a
condition 5 6 83.3
subroutine 7 8 87.5
pod 0 3 0.0
total 32 40 80.0


line stmt bran cond sub pod time code
1             package SignalWire::Agents::Skills::Builtin::ApiNinjasTrivia;
2 3     3   21 use strict;
  3         8  
  3         116  
3 3     3   17 use warnings;
  3         5  
  3         219  
4 3     3   40 use Moo;
  3         5  
  3         24  
5             extends 'SignalWire::Agents::Skills::SkillBase';
6              
7 3     3   1407 use SignalWire::Agents::Skills::SkillRegistry;
  3         6  
  3         1484  
8             SignalWire::Agents::Skills::SkillRegistry->register_skill('api_ninjas_trivia', __PACKAGE__);
9              
10             has '+skill_name' => (default => sub { 'api_ninjas_trivia' });
11             has '+skill_description' => (default => sub { 'Get trivia questions from API Ninjas' });
12             has '+supports_multiple_instances' => (default => sub { 1 });
13              
14             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     6 0 2535 sub setup { 1 }
22              
23             sub register_tools {
24 5     5 0 633 my ($self) = @_;
25 5   100     40 my $tool_name = $self->params->{tool_name} // 'get_trivia';
26 5   50     31 my $api_key = $self->params->{api_key} // '';
27 5   100     45 my $categories = $self->params->{categories} // [@ALL_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             handler => sub {
44 0     0   0 my ($args, $raw) = @_;
45 0         0 require SignalWire::Agents::SWAIG::FunctionResult;
46 0         0 return SignalWire::Agents::SWAIG::FunctionResult->new(
47             response => "Trivia category: $args->{category} (API call would be made with key)"
48             );
49             },
50 5         98 );
51             }
52              
53             sub get_parameter_schema {
54             return {
55 1     1 0 4809 %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema },
  1         6  
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             1;