Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| habrok:examples:ollama [2026/05/27 11:14] – pedro | habrok:examples:ollama [2026/07/08 16:30] (current) – [Simple usage example] Fix model name pedro | ||
|---|---|---|---|
| Line 79: | Line 79: | ||
| You can find more info on how to use the Ollama Python library on their [[https:// | You can find more info on how to use the Ollama Python library on their [[https:// | ||
| + | The full example script is as follows: | ||
| + | <code python> | ||
| + | import os | ||
| + | import ollama | ||
| + | |||
| + | from openai import OpenAI | ||
| + | |||
| + | ollama.pull(" | ||
| + | |||
| + | for model in ollama.list().models: | ||
| + | print(model.model) | ||
| + | |||
| + | client = OpenAI( | ||
| + | base_url=f" | ||
| + | api_key=" | ||
| + | ) | ||
| + | |||
| + | response = client.chat.completions.create( | ||
| + | model=" | ||
| + | messages = [ | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | ] | ||
| + | ) | ||
| + | print(response.choices[0].message.content) | ||
| + | </ | ||