« blib/lib/SignalWire/Agents/Skills/Builtin/McpGateway.pm
↑ Summary
blib/lib/SignalWire/Agents/Prefabs/FAQBot.pm »
| 1 | package SignalWire::Agents::Skills::Builtin::WeatherApi; | ||||||||||||
| 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('weather_api', __PACKAGE__); | |||||||||||
| 9 | |||||||||||||
| 10 | 7 | ▶ | has '+skill_name' => (default => sub { 'weather_api' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 7 | ▶ | has '+skill_description' => (default => sub { 'Get current weather information from WeatherAPI.com' }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 7 | ▶ | has '+supports_multiple_instances' => (default => sub { 0 }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | |||||||||||||
| 14 | 6 | ▶ | sub setup { 1 } | ||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 15 | |||||||||||||
| 16 | 5 | ▶ | sub register_tools { | ||||||||||
|
Subroutine
register_tools: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||
| 17 | 5 | my ($self) = @_; | |||||||||||
| 18 | 5 | ▶ | my $tool_name = $self->params->{tool_name} // 'get_weather'; | ||||||||||
|
Condition100%2/2
$self->params->{"tool_name"} // "get_weather"
MC/DC100%1/1
$self->params->{"tool_name"} // "get_weather"
$self->params->{"tool_name"}
Truth table100%2/2
A
A= $self->params->{"tool_name"}
| |||||||||||||
| 19 | 5 | ▶ | my $api_key = $self->params->{api_key} // ''; | ||||||||||
|
Condition100%2/2
$self->params->{"api_key"} // ""
MC/DC100%1/1
$self->params->{"api_key"} // ""
$self->params->{"api_key"}
Truth table100%2/2
A
A= $self->params->{"api_key"}
| |||||||||||||
| 20 | 5 | ▶ | my $unit = $self->params->{temperature_unit} // 'fahrenheit'; | ||||||||||
|
Condition100%2/2
$self->params->{"temperature_unit"} // "fahrenheit"
MC/DC100%1/1
$self->params->{"temperature_unit"} // "fahrenheit"
$self->params->{"temperature_unit"}
Truth table100%2/2
A
A= $self->params->{"temperature_unit"}
| |||||||||||||
| 21 | |||||||||||||
| 22 | 5 | ▶ | my $temp_field = $unit eq 'celsius' ? 'temp_c' : 'temp_f'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 5 | ▶ | my $feels_field = $unit eq 'celsius' ? 'feelslike_c' : 'feelslike_f'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 5 | ▶ | my $unit_label = $unit eq 'celsius' ? 'C' : 'F'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 25 | |||||||||||||
| 26 | 5 | $self->agent->register_swaig_function({ | |||||||||||
| 27 | function => $tool_name, | ||||||||||||
| 28 | description => 'Get current weather information for any location', | ||||||||||||
| 29 | parameters => { | ||||||||||||
| 30 | type => 'object', | ||||||||||||
| 31 | properties => { | ||||||||||||
| 32 | location => { type => 'string', description => 'Location to get weather for' }, | ||||||||||||
| 33 | }, | ||||||||||||
| 34 | required => ['location'], | ||||||||||||
| 35 | }, | ||||||||||||
| 36 | data_map => { | ||||||||||||
| 37 | webhooks => [{ | ||||||||||||
| 38 | method => 'GET', | ||||||||||||
| 39 | url => "https://api.weatherapi.com/v1/current.json?key=${api_key}&q=\${lc:enc:args.location}&aqi=no", | ||||||||||||
| 40 | output => { | ||||||||||||
| 41 | response => "Temperature: \${current.${temp_field}}${unit_label}, " | ||||||||||||
| 42 | . "Feels like: \${current.${feels_field}}${unit_label}, " | ||||||||||||
| 43 | . "Condition: \${current.condition.text}, " | ||||||||||||
| 44 | . "Humidity: \${current.humidity}%, " | ||||||||||||
| 45 | . "Wind: \${current.wind_mph} mph", | ||||||||||||
| 46 | }, | ||||||||||||
| 47 | }], | ||||||||||||
| 48 | }, | ||||||||||||
| 49 | }); | ||||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 1 | ▶ | sub get_parameter_schema { | ||||||||||
|
Subroutine
get_parameter_schema: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 53 | return { | ||||||||||||
| 54 | 1 | %{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, | |||||||||||
| 55 | api_key => { type => 'string', required => 1, hidden => 1 }, | ||||||||||||
| 56 | tool_name => { type => 'string', default => 'get_weather' }, | ||||||||||||
| 57 | temperature_unit => { type => 'string', enum => ['fahrenheit', 'celsius'], default => 'fahrenheit' }, | ||||||||||||
| 58 | }; | ||||||||||||
| 59 | } | ||||||||||||
| 60 | |||||||||||||
| 61 | 3 | 1; | |||||||||||