-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtools
executable file
·49 lines (40 loc) · 1.13 KB
/
tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env ruby
# frozen_string_literal: true
require "omniai/google"
CLIENT = OmniAI::Google::Client.new
LOCATION = OmniAI::Tool::Property.object(
properties: {
city: OmniAI::Tool::Property.string(description: 'e.g. "Toronto"'),
country: OmniAI::Tool::Property.string(description: 'e.g. "Canada"'),
},
required: %i[city country]
)
LOCATIONS = OmniAI::Tool::Property.array(
min_items: 1,
max_items: 5,
items: LOCATION
)
UNIT = OmniAI::Tool::Property.string(enum: %w[celcius fahrenheit])
WEATHER = proc do |locations:, unit: "celsius"|
locations.map do |location|
"#{rand(20..50)}° #{unit} in #{location[:city]}, #{location[:country]}"
end.join("\n")
end
TOOL = OmniAI::Tool.new(
WEATHER,
name: "Weather",
description: "Lookup the weather in a location",
parameters: OmniAI::Tool::Parameters.new(
properties: {
locations: LOCATIONS,
unit: UNIT,
},
required: %i[locations]
)
)
completion = CLIENT.chat(tools: [TOOL]) do |prompt|
prompt.user do |message|
message.text('What is the weather in "London" in celcius and "Seattle" in fahrenheit?')
end
end
puts(completion.text)