|
21 | 21 | end |
22 | 22 | end |
23 | 23 |
|
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 |
35 | 25 | let(:parameters) do |
36 | 26 | { |
37 | 27 | model: model, |
38 | 28 | messages: messages, |
39 | 29 | stream: stream, |
40 | | - functions: functions |
| 30 | + tools: tools |
41 | 31 | } |
42 | 32 | end |
43 | | - let(:functions) do |
| 33 | + let(:tools) do |
44 | 34 | [ |
45 | 35 | { |
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"] |
56 | 50 | } |
57 | | - } |
| 51 | + } |
58 | 52 | } |
59 | 53 | ] |
60 | 54 | end |
61 | 55 |
|
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 |
68 | 74 | end |
69 | 75 | end |
70 | 76 | end |
|
0 commit comments