Skip to content

Commit 613fb66

Browse files
oskarhanestellasia
authored andcommitted
Print all tool calls in example file
1 parent 39c73c6 commit 613fb66

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

examples/tool_calls/openai_tool_calls.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@
4545
TOOLS = [person_info_tool]
4646

4747

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."""
5050
if not response.tool_calls:
5151
raise ValueError("No tool calls found in response")
5252

53-
tool_call = response.tool_calls[0]
54-
print(f"\nTool called: {tool_call.name}")
55-
print(f"Arguments: {tool_call.arguments}")
53+
print(f"\nNumber of tool calls: {len(response.tool_calls)}")
5654
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"\nTool 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 {}
5864

5965

6066
async def main() -> None:
@@ -74,7 +80,7 @@ async def main() -> None:
7480
input=f"Extract information about the person from this text: {text}",
7581
tools=TOOLS,
7682
)
77-
sync_result = process_tool_call(sync_response)
83+
sync_result = process_tool_calls(sync_response)
7884
print("\n=== Synchronous Tool Call Result ===")
7985
print(json.dumps(sync_result, indent=2))
8086

@@ -85,7 +91,7 @@ async def main() -> None:
8591
input=f"Extract information about the person from this text: {text2}",
8692
tools=TOOLS,
8793
)
88-
async_result = process_tool_call(async_response)
94+
async_result = process_tool_calls(async_response)
8995
print("\n=== Asynchronous Tool Call Result ===")
9096
print(json.dumps(async_result, indent=2))
9197

0 commit comments

Comments
 (0)