Skip to content

Commit d5535fa

Browse files
authored
Merge pull request #446 from alexrudall/functions-to-tools
Refactor functions call spec to use tools
2 parents 96ca0e1 + f452cb8 commit d5535fa

File tree

3 files changed

+151
-201
lines changed

3 files changed

+151
-201
lines changed

spec/fixtures/cassettes/gpt-3_5-turbo_function_call_chat.yml

Lines changed: 0 additions & 171 deletions
This file was deleted.

spec/fixtures/cassettes/gpt-3_5-turbo_valid_tool_call_chat.yml

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/openai/client/chat_spec.rb

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,50 +21,56 @@
2121
end
2222
end
2323

24-
context "with an invalid function call" do
25-
let(:cassette) { "#{model} function call chat".downcase }
26-
let(:messages) do
27-
[
28-
{
29-
"role" => "function",
30-
# "name" => "function",
31-
"content" => "function"
32-
}
33-
]
34-
end
24+
context "with a tool call" do
3525
let(:parameters) do
3626
{
3727
model: model,
3828
messages: messages,
3929
stream: stream,
40-
functions: functions
30+
tools: tools
4131
}
4232
end
43-
let(:functions) do
33+
let(:tools) do
4434
[
4535
{
46-
"name" => "function",
47-
"description" => "function",
48-
"parameters" =>
49-
{
50-
"type" => "object",
51-
"properties" => {
52-
"user" => {
53-
"type" => "string",
54-
"description" => "the full name of the user"
55-
}
36+
"type" => "function",
37+
"function" => {
38+
"name" => "get_current_weather",
39+
"description" => "Get the current weather in a given location",
40+
"parameters" =>
41+
{
42+
"type" => "object",
43+
"properties" => {
44+
"location" => {
45+
"type" => "string",
46+
"description" => "The geographic location to get the weather for"
47+
}
48+
},
49+
"required" => ["location"]
5650
}
57-
}
51+
}
5852
}
5953
]
6054
end
6155

62-
it "raises an error containing the reason" do
63-
VCR.use_cassette(cassette) do
64-
response
65-
rescue Faraday::Error => e
66-
expect(e.response.dig(:body, "error",
67-
"message")).to include("Missing parameter 'name'")
56+
context "with a valid message" do
57+
let(:cassette) { "#{model} valid tool call chat".downcase }
58+
let(:messages) do
59+
[
60+
{
61+
"role" => "user",
62+
"content" => "What is the weather like in the Peak District?"
63+
}
64+
]
65+
end
66+
67+
it "succeeds" do
68+
VCR.use_cassette(cassette) do
69+
expect(response.dig("choices", 0, "message", "tool_calls", 0, "function",
70+
"name")).to eq("get_current_weather")
71+
expect(response.dig("choices", 0, "message", "tool_calls", 0, "function",
72+
"arguments")).to include("Peak District")
73+
end
6874
end
6975
end
7076
end

0 commit comments

Comments
 (0)