Skip to content

Commit 09ef98b

Browse files
committed
docs: update cookbook to test tracing through iterator
1 parent 9a72f96 commit 09ef98b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cookbook/openai/tracing_open_ai_streams.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818

1919

2020
@trace
21-
def call_openai_stream(data: dict):
21+
def _call_openai_stream(data: dict):
2222
data["stream"] = True
2323
stream = client.chat.completions.create(**data)
24+
for chunk in stream:
25+
yield chunk
26+
27+
28+
def call_openai_stream(data: dict):
29+
stream = _call_openai_stream(data)
2430
for chunk in stream:
2531
print(chunk.choices[0].delta or "")
2632

0 commit comments

Comments
 (0)