| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package SignalWire::Agents::Skills::Builtin::WeatherApi; |
|
2
|
3
|
|
|
3
|
|
24
|
use strict; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
131
|
|
|
3
|
3
|
|
|
3
|
|
19
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
174
|
|
|
4
|
3
|
|
|
3
|
|
19
|
use Moo; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
21
|
|
|
5
|
|
|
|
|
|
|
extends 'SignalWire::Agents::Skills::SkillBase'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
4086
|
use SignalWire::Agents::Skills::SkillRegistry; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
1636
|
|
|
8
|
|
|
|
|
|
|
SignalWire::Agents::Skills::SkillRegistry->register_skill('weather_api', __PACKAGE__); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has '+skill_name' => (default => sub { 'weather_api' }); |
|
11
|
|
|
|
|
|
|
has '+skill_description' => (default => sub { 'Get current weather information from WeatherAPI.com' }); |
|
12
|
|
|
|
|
|
|
has '+supports_multiple_instances' => (default => sub { 0 }); |
|
13
|
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
0
|
2297
|
sub setup { 1 } |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register_tools { |
|
17
|
5
|
|
|
5
|
0
|
609
|
my ($self) = @_; |
|
18
|
5
|
|
100
|
|
|
51
|
my $tool_name = $self->params->{tool_name} // 'get_weather'; |
|
19
|
5
|
|
100
|
|
|
28
|
my $api_key = $self->params->{api_key} // ''; |
|
20
|
5
|
|
100
|
|
|
39
|
my $unit = $self->params->{temperature_unit} // 'fahrenheit'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
5
|
100
|
|
|
|
48
|
my $temp_field = $unit eq 'celsius' ? 'temp_c' : 'temp_f'; |
|
23
|
5
|
100
|
|
|
|
18
|
my $feels_field = $unit eq 'celsius' ? 'feelslike_c' : 'feelslike_f'; |
|
24
|
5
|
100
|
|
|
|
19
|
my $unit_label = $unit eq 'celsius' ? 'C' : 'F'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
227
|
$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
|
|
|
|
|
|
|
sub get_parameter_schema { |
|
53
|
|
|
|
|
|
|
return { |
|
54
|
1
|
|
|
1
|
0
|
62223
|
%{ SignalWire::Agents::Skills::SkillBase->get_parameter_schema }, |
|
|
1
|
|
|
|
|
8
|
|
|
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
|
|
|
|
|
|
|
1; |