forked from AllAboutAI-YT/local_deepseekr1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepseek_r1.py
34 lines (28 loc) · 976 Bytes
/
deepseek_r1.py
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
29
30
31
32
33
34
from ollama import chat
import sys
stream = chat(
model='deepseek-r1:14b',
messages=[{'role': 'user', 'content': "You Question"}],
stream=True,
)
reasoning_content = ""
content = ""
for chunk in stream:
if chunk and 'message' in chunk and chunk['message'].content:
# Get the content from the chunk
chunk_content = chunk['message'].content
# Print the content immediately, without newline
sys.stdout.write(chunk_content)
sys.stdout.flush()
# Store in appropriate buffer
if chunk_content.startswith('<think>'):
in_thinking = True
elif chunk_content.startswith('</think>'):
in_thinking = False
else:
if 'in_thinking' in locals() and in_thinking:
reasoning_content += chunk_content
else:
content += chunk_content
print("\n\nReasoning:", reasoning_content)
print("\nFinal Answer:", content)