45
45
TOOLS = [person_info_tool ]
46
46
47
47
48
- def process_tool_call (response : ToolCallResponse ) -> Dict [str , Any ]:
49
- """Process the tool call response and return the extracted parameters."""
48
+ def process_tool_calls (response : ToolCallResponse ) -> Dict [str , Any ]:
49
+ """Process all tool calls in the response and return the extracted parameters."""
50
50
if not response .tool_calls :
51
51
raise ValueError ("No tool calls found in response" )
52
52
53
- tool_call = response .tool_calls [0 ]
54
- print (f"\n Tool called: { tool_call .name } " )
55
- print (f"Arguments: { tool_call .arguments } " )
53
+ print (f"\n Number of tool calls: { len (response .tool_calls )} " )
56
54
print (f"Additional content: { response .content or 'None' } " )
57
- return tool_call .arguments
55
+
56
+ results = []
57
+ for i , tool_call in enumerate (response .tool_calls ):
58
+ print (f"\n Tool call #{ i + 1 } : { tool_call .name } " )
59
+ print (f"Arguments: { tool_call .arguments } " )
60
+ results .append (tool_call .arguments )
61
+
62
+ # For backward compatibility, return the first tool call's arguments
63
+ return results [0 ] if results else {}
58
64
59
65
60
66
async def main () -> None :
@@ -74,7 +80,7 @@ async def main() -> None:
74
80
input = f"Extract information about the person from this text: { text } " ,
75
81
tools = TOOLS ,
76
82
)
77
- sync_result = process_tool_call (sync_response )
83
+ sync_result = process_tool_calls (sync_response )
78
84
print ("\n === Synchronous Tool Call Result ===" )
79
85
print (json .dumps (sync_result , indent = 2 ))
80
86
@@ -85,7 +91,7 @@ async def main() -> None:
85
91
input = f"Extract information about the person from this text: { text2 } " ,
86
92
tools = TOOLS ,
87
93
)
88
- async_result = process_tool_call (async_response )
94
+ async_result = process_tool_calls (async_response )
89
95
print ("\n === Asynchronous Tool Call Result ===" )
90
96
print (json .dumps (async_result , indent = 2 ))
91
97
0 commit comments