-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy path03_direct_stream.py
More file actions
28 lines (20 loc) · 863 Bytes
/
Copy path03_direct_stream.py
File metadata and controls
28 lines (20 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""Example 3 — stream the reply as it is generated, in-process.
client.stream() yields pieces of text as they arrive, instead of waiting for the
whole reply. Good for showing output live (like a chat UI typing).
Run it from the project root:
python examples/03_direct_stream.py
"""
# Make the project importable when this file is run directly.
import sys
import pathlib
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent))
from deepseek import DeepSeekClient
client = DeepSeekClient()
# Omit conversation_id to start fresh. Each chunk is a string; the
# conversation_id is filled in once the stream finishes.
stream = client.stream("Tell me a short, clean joke.")
for chunk in stream:
print(chunk, end="", flush=True)
print() # newline after the streamed text
print("conversation_id:", stream.conversation_id)
client.close()