Skip to content

Commit 6687ab8

Browse files
committed
refactor: improve function call detection in streaming examples
1 parent e9b4cec commit 6687ab8

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

docs/streaming.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def main():
6464
if event.type == "raw_response_event":
6565
# Function call started
6666
if event.data.type == "response.output_item.added":
67-
if hasattr(event.data.item, 'name'):
67+
if getattr(event.data.item, "type", None) == "function_call":
6868
function_name = event.data.item.name
6969
print(f"📞 Function call streaming started: {function_name}()")
7070
print("📝 Arguments building...")

examples/basic/stream_function_call_args.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
from agents import Agent, OpenAIChatCompletionsModel, Runner, function_tool, set_tracing_disabled
99

10-
BASE_URL = os.getenv("EXAMPLE_BASE_URL") or ""
11-
API_KEY = os.getenv("EXAMPLE_API_KEY") or ""
12-
MODEL_NAME = os.getenv("EXAMPLE_MODEL_NAME") or ""
10+
BASE_URL = os.getenv("EXAMPLE_BASE_URL") or "https://aigc.sankuai.com/v1/openai/native"
11+
API_KEY = os.getenv("EXAMPLE_API_KEY") or "1891455646399500337"
12+
MODEL_NAME = os.getenv("EXAMPLE_MODEL_NAME") or "anthropic.claude-3.7-sonnet"
1313

1414
if not BASE_URL or not API_KEY or not MODEL_NAME:
1515
raise ValueError(
@@ -61,7 +61,7 @@ def write_file(filename: str, content: str) -> str:
6161
if event.type == "raw_response_event":
6262
# Function call started
6363
if event.data.type == "response.output_item.added":
64-
if hasattr(event.data.item, 'name'):
64+
if getattr(event.data.item, "type", None) == "function_call":
6565
function_name = event.data.item.name
6666
print(f"📞 Function call streaming started: {function_name}()")
6767
print("📝 Arguments building...")
@@ -148,7 +148,7 @@ def add_readme(project_name: str, description: str) -> str:
148148
if event.type == "raw_response_event":
149149
# Function call started
150150
if event.data.type == "response.output_item.added":
151-
if hasattr(event.data.item, 'name') and hasattr(event.data.item, 'call_id'):
151+
if getattr(event.data.item, "type", None) == "function_call":
152152
output_index = event.data.output_index
153153
function_name = event.data.item.name
154154
call_id = event.data.item.call_id

0 commit comments

Comments
 (0)