Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Dec 22, 2023
1 parent 916fe11 commit 0fb7c9f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
6 changes: 2 additions & 4 deletions examples/simple-chat-stream/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
},
]

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()
2 changes: 1 addition & 1 deletion examples/simple-chat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
]

response = chat('mistral', messages=messages)
print(response['message'])
print(response['message']['content'])
5 changes: 5 additions & 0 deletions examples/simple-generate-stream/main.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions examples/simple-generate/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from ollama import generate


response = generate('mistral', 'Why is the sky blue?')
print(response['response'])
2 changes: 1 addition & 1 deletion examples/simple-multimodal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
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()

0 comments on commit 0fb7c9f

Please sign in to comment.