mirror of
https://github.com/kharonsec/ollama-python
synced 2026-05-12 18:06:20 +02:00
initial commit
This commit is contained in:
17
examples/simple-chat-stream/main.py
Normal file
17
examples/simple-chat-stream/main.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from ollama import chat
|
||||
|
||||
|
||||
messages = [
|
||||
{
|
||||
'role': 'user',
|
||||
'content': 'Why is the sky blue?',
|
||||
},
|
||||
]
|
||||
|
||||
for message in chat('mistral', messages=messages, stream=True):
|
||||
if message := message.get('message'):
|
||||
if message.get('role') == 'assistant':
|
||||
print(message.get('content', ''), end='', flush=True)
|
||||
|
||||
# end with a newline
|
||||
print()
|
||||
Reference in New Issue
Block a user