Class: SignalWire::Skills::Builtin::JokeSkill
- Inherits:
-
SkillBase
- Object
- SkillBase
- SignalWire::Skills::Builtin::JokeSkill
show all
- Defined in:
- lib/signalwire/skills/builtin/joke.rb
Instance Attribute Summary
Attributes inherited from SkillBase
#agent, #logger, #params, #swaig_fields
Instance Method Summary
collapse
Methods inherited from SkillBase
#cleanup, #get_hints, #get_param, #initialize, #instance_key, #required_env_vars, #supports_multiple_instances?, #version
Instance Method Details
#description ⇒ Object
12
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 12
def description; 'Tell jokes using the API Ninjas joke API'; end
|
#get_global_data ⇒ Object
34
35
36
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 34
def get_global_data
{ 'joke_skill_enabled' => true }
end
|
#get_parameter_schema ⇒ Object
52
53
54
55
56
57
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 52
def get_parameter_schema
{
'api_key' => { 'type' => 'string', 'required' => true, 'hidden' => true, 'env_var' => 'API_NINJAS_KEY' },
'tool_name' => { 'type' => 'string', 'default' => 'get_joke' }
}
end
|
#get_prompt_sections ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 38
def get_prompt_sections
[
{
'title' => 'Joke Telling',
'body' => 'You can tell jokes to entertain users.',
'bullets' => [
"Use #{@tool_name || 'get_joke'} to tell jokes when users ask for humor",
'You can tell regular jokes or dad jokes',
'Be enthusiastic and fun when sharing jokes'
]
}
]
end
|
#name ⇒ Object
11
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 11
def name; 'joke'; end
|
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 21
def register_tools
dm = DataMap.new(@tool_name)
.description('Get a random joke from API Ninjas')
.parameter('type', 'string', 'Type of joke to get', required: true, enum: %w[jokes dadjokes])
.webhook('GET', "https://api.api-ninjas.com/v1/${args.type}",
headers: { 'X-Api-Key' => @api_key })
.output(Swaig::FunctionResult.new("Here's a joke: ${array[0].joke}"))
.error_keys(%w[error])
.fallback_output(Swaig::FunctionResult.new('Sorry, there is a problem with the joke service right now. Please try again later.'))
[{ datamap: dm.to_swaig_function }]
end
|
#setup ⇒ Object
14
15
16
17
18
19
|
# File 'lib/signalwire/skills/builtin/joke.rb', line 14
def setup
@api_key = get_param('api_key', env_var: 'API_NINJAS_KEY')
@tool_name = get_param('tool_name', default: 'get_joke')
return false unless @api_key && !@api_key.empty?
true
end
|