File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -405,16 +405,18 @@ def get_current_weather(location:, unit: "fahrenheit")
405405 # use a weather api to fetch weather
406406end
407407
408+ messages = [
409+ {
410+ " role" : " user" ,
411+ " content" : " What is the weather like in San Francisco?" ,
412+ },
413+ ]
414+
408415response =
409416 client.chat(
410417 parameters: {
411418 model: " gpt-4o" ,
412- messages: [
413- {
414- " role" : " user" ,
415- " content" : " What is the weather like in San Francisco?" ,
416- },
417- ],
419+ messages: messages, # Defined above because we'll use it again
418420 tools: [
419421 {
420422 type: " function" ,
@@ -444,7 +446,6 @@ response =
444446 )
445447
446448message = response.dig(" choices" , 0 , " message" )
447- function_messages = []
448449
449450if message[" role" ] == " assistant" && message[" tool_calls" ]
450451 messages[" tool_calls" ].each do |tool_calls |
@@ -461,18 +462,18 @@ if message["role"] == "assistant" && message["tool_calls"]
461462 # decide how to handle
462463 end
463464
464- function_messages << [{
465+ messages << [{
465466 tool_call_id: tool_call_id,
466467 role: " tool" ,
467468 name: function_name,
468469 content: function_response
469- }]
470+ }] # Extend the conversation with the results of the functions
470471 end
471472
472473 second_response = client.chat(
473474 parameters: {
474475 model: " gpt-4o" ,
475- messages: function_messages
476+ messages: messages
476477 })
477478
478479 # At this point, the model has decided to call functions, you've called the functions
You can’t perform that action at this time.
0 commit comments