mirror of
https://github.com/kharonsec/ollama-python
synced 2026-05-10 17:12:03 +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()
|
||||
12
examples/simple-chat/main.py
Normal file
12
examples/simple-chat/main.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from ollama import chat
|
||||
|
||||
|
||||
messages = [
|
||||
{
|
||||
'role': 'user',
|
||||
'content': 'Why is the sky blue?',
|
||||
},
|
||||
]
|
||||
|
||||
response = chat('mistral', messages=messages)
|
||||
print(response['message'])
|
||||
29
examples/simple-multimodal/main.py
Normal file
29
examples/simple-multimodal/main.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import sys
|
||||
import random
|
||||
import httpx
|
||||
|
||||
from ollama import generate
|
||||
|
||||
|
||||
latest = httpx.get('https://xkcd.com/info.0.json')
|
||||
latest.raise_for_status()
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
num = int(sys.argv[1])
|
||||
else:
|
||||
num = random.randint(1, latest.json().get('num'))
|
||||
|
||||
comic = httpx.get(f'https://xkcd.com/{num}/info.0.json')
|
||||
comic.raise_for_status()
|
||||
|
||||
print(f'xkcd #{comic.json().get("num")}: {comic.json().get("alt")}')
|
||||
print(f'link: https://xkcd.com/{num}')
|
||||
print('---')
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user