@@ -352,36 +352,39 @@ response =
352
352
" content" : " What is the weather like in San Francisco?" ,
353
353
},
354
354
],
355
- functions : [
355
+ tools : [
356
356
{
357
- name: " get_current_weather" ,
358
- description: " Get the current weather in a given location" ,
359
- parameters: {
360
- type: :object ,
361
- properties: {
362
- location: {
363
- type: :string ,
364
- description: " The city and state, e.g. San Francisco, CA" ,
365
- },
366
- unit: {
367
- type: " string" ,
368
- enum: %w[celsius fahrenheit] ,
357
+ type: " function" ,
358
+ function: {
359
+ name: " get_current_weather" ,
360
+ description: " Get the current weather in a given location" ,
361
+ parameters: {
362
+ type: :object ,
363
+ properties: {
364
+ location: {
365
+ type: :string ,
366
+ description: " The city and state, e.g. San Francisco, CA" ,
367
+ },
368
+ unit: {
369
+ type: " string" ,
370
+ enum: %w[celsius fahrenheit] ,
371
+ },
369
372
},
373
+ required: [" location" ],
370
374
},
371
- required: [" location" ],
372
375
},
373
- },
376
+ }
374
377
],
375
378
},
376
379
)
377
380
378
381
message = response.dig(" choices" , 0 , " message" )
379
382
380
- if message[" role" ] == " assistant" && message[" function_call " ]
381
- function_name = message.dig(" function_call " , " name" )
383
+ if message[" role" ] == " assistant" && message[" tool_calls " ]
384
+ function_name = message.dig(" tool_calls " , " function " , " name" )
382
385
args =
383
386
JSON .parse(
384
- message.dig(" function_call " , " arguments" ),
387
+ message.dig(" tool_calls " , " function " , " arguments" ),
385
388
{ symbolize_names: true },
386
389
)
387
390
0 commit comments