Files
ollama-python/examples/simple-chat-stream/main.py
Michael Yang 4fb93dcb0c initial commit
2023-12-20 12:09:49 -08:00

18 lines
347 B
Python

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()