Skip to content

Commit cae4112

Browse files
committed
Update function calling few shots example
1 parent fb010a6 commit cae4112

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ All example scripts are located in the root directory. They follow a consistent
3232
- `function_calling_basic.py` - Single function declaration, prints tool calls (no execution)
3333
- `function_calling_call.py` - Executes the function once if the model requests it
3434
- `function_calling_extended.py` - Full round-trip: executes, returns tool output, gets final answer
35-
- `function_calling_extended_errors.py` - Same as extended but with robust error handling (malformed JSON args, missing tool, tool exceptions, JSON serialization)
35+
- `function_calling_errors.py` - Same as extended but with robust error handling (malformed JSON args, missing tool, tool exceptions, JSON serialization)
3636
- `function_calling_parallel.py` - Shows model requesting multiple tools in one response
3737
- `function_calling_while_loop.py` - Conversation loop that keeps executing sequential tool calls until the model produces a final natural language answer (with error handling)
3838

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Scripts (in increasing order of capability):
4444
1. [`function_calling_basic.py`](./function_calling_basic.py): Declares a single `lookup_weather` function and prompts the model. It prints the tool call (if any) or falls back to the model's normal content. No actual function execution occurs.
4545
2. [`function_calling_call.py`](./function_calling_call.py): Executes the `lookup_weather` function if the model requests it by parsing the returned arguments JSON and calling the local Python function.
4646
3. [`function_calling_extended.py`](./function_calling_extended.py): Shows a full round‑trip: after executing the function, it appends a `tool` role message containing the function result and asks the model again so it can incorporate real data into a final user-facing response.
47-
4. [`function_calling_extended_errors.py`](./function_calling_extended_errors.py): Same as the extended example but adds robust error handling (malformed JSON arguments, missing tool implementations, execution exceptions, JSON serialization fallback).
47+
4. [`function_calling_errors.py`](./function_calling_errors.py): Same as the extended example but adds robust error handling (malformed JSON arguments, missing tool implementations, execution exceptions, JSON serialization fallback).
4848
5. [`function_calling_parallel.py`](./function_calling_parallel.py): Demonstrates the model returning multiple tool calls in a single response
4949
6. [`function_calling_while_loop.py`](./function_calling_while_loop.py): An iterative conversation loop that keeps executing sequential tool calls (with error handling) until the model produces a final natural language answer.
5050

function_calling_fewshots.py

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,31 +93,42 @@ def search_database(search_query: str, price_filter: dict | None = None) -> dict
9393
{"role": "system", "content": "You are a product search assistant."},
9494
{"role": "user", "content": "good options for climbing gear that can be used outside?"},
9595
{
96-
"id": "madeup",
97-
"call_id": "call_abc123",
98-
"name": "search_database",
99-
"arguments": '{"search_query":"climbing gear outside"}',
100-
"type": "function_call",
96+
"role": "assistant",
97+
"content": "",
98+
"tool_calls": [
99+
{
100+
"id": "call_abc123",
101+
"type": "function",
102+
"function": {"name": "search_database", "arguments": '{"search_query":"climbing gear outside"}'},
103+
}
104+
]
101105
},
102106
{
103-
"id": "madeupoutput",
104-
"call_id": "call_abc123",
105-
"output": "Search results for climbing gear that can be used outside: ...",
106-
"type": "function_call_output",
107+
"role": "tool",
108+
"tool_call_id": "call_abc123",
109+
"name": "search_database",
110+
"content": "Search results for climbing gear that can be used outside: ...",
107111
},
108112
{"role": "user", "content": "are there any shoes less than $50?"},
109113
{
110-
"id": "madeup",
111-
"call_id": "call_abc456",
112-
"name": "search_database",
113-
"arguments": '{"search_query":"shoes","price_filter":{"comparison_operator":"<","value":50}}',
114-
"type": "function_call",
114+
"role": "assistant",
115+
"content": "",
116+
"tool_calls": [
117+
{
118+
"id": "call_abc456",
119+
"type": "function",
120+
"function": {
121+
"name": "search_database",
122+
"arguments": '{"search_query":"tenis","price_filter":{"comparison_operator":"<","value":50}}',
123+
},
124+
}
125+
],
115126
},
116127
{
117-
"id": "madeupoutput",
118-
"call_id": "call_abc456",
119-
"output": "Search results for shoes cheaper than 50: ...",
120-
"type": "function_call_output",
128+
"role": "tool",
129+
"tool_call_id": "call_abc456",
130+
"name": "search_database",
131+
"content": "Search results for shoes cheaper than 50: ...",
121132
},
122133
{"role": "user", "content": "Find me a red shirt under $20."},
123134
]

0 commit comments

Comments
 (0)