Reference · Snippet · python

Ollama chat API

Last updated

ollamalocalchat

import requests

resp = requests.post(
    "http://localhost:11434/api/chat",
    json={
        "model": "llama3.2",
        "messages": [{"role": "user", "content": "Explain RAG in one paragraph."}],
        "stream": False,
    },
    timeout=120,
)
print(resp.json()["message"]["content"])