This commit is contained in:
Michael Yang 2023-12-21 16:37:07 -08:00
parent 2236de230c
commit e8a66b8de1
5 changed files with 14 additions and 6 deletions

View File

@ -8,10 +8,8 @@ messages = [
},
]
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)
for part in chat('mistral', messages=messages, stream=True):
print(part['message']['content'], end='', flush=True)
# end with a newline
print()

View File

@ -9,4 +9,4 @@ messages = [
]
response = chat('mistral', messages=messages)
print(response['message'])
print(response['message']['content'])

View File

@ -0,0 +1,5 @@
from ollama import generate
for part in generate('mistral', 'Why is the sky blue?', stream=True):
print(part['response'], end='', flush=True)

View File

@ -0,0 +1,5 @@
from ollama import generate
response = generate('mistral', 'Why is the sky blue?')
print(response['response'])

View File

@ -24,6 +24,6 @@ raw = httpx.get(comic.json().get('img'))
raw.raise_for_status()
for response in generate('llava', 'explain this comic:', images=[raw.content], stream=True):
print(response.get('response'), end='', flush=True)
print(response['response'], end='', flush=True)
print()