Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
habrok:examples:ollama [2026/05/27 11:14] pedrohabrok: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://github.com/ollama/ollama-python|GitHub page]]. You can find more info on how to use the Ollama Python library on their [[https://github.com/ollama/ollama-python|GitHub page]].
  
 +The full example script is as follows:
 +<code python>
 +import os
 +import ollama
 + 
 +from openai import OpenAI
 +
 +ollama.pull("gemma3:12b")
 +
 +for model in ollama.list().models:
 +    print(model.model)
 +
 +client = OpenAI(
 +    base_url=f"http://{os.environ['OLLAMA_HOST']}/v1",
 +    api_key="ollama"
 +)
 +
 +response = client.chat.completions.create(
 +    model="gemma3:12b",
 +    messages = [
 +        {
 +            "role": "system",
 +            "content": "You are a friendly dog"
 +        },
 +        {
 +            "role": "user",
 +            "content": "Would you like a bone?"
 +        }
 +    ]
 +)
 +print(response.choices[0].message.content)
 +</code>