Run the examples in this directory with:
# Run example
python3 examples/<example>.py
# or with uv
uv run examples/<example>.pySee ollama/docs/api.md for full API documentation
- chat.py
- async-chat.py
- chat-stream.py - Streamed outputs
- chat-with-history.py - Chat with model and maintain history of the conversation
- generate.py
- async-generate.py
- generate-stream.py - Streamed outputs
- fill-in-middle.py - Given a prefix and suffix, fill in the middle
- tools.py - Simple example of Tools/Function Calling
- async-tools.py
- multi-tool.py - Using multiple tools, with thinking enabled
An API key from Ollama's cloud service is required. You can create one here.
export OLLAMA_API_KEY="your_api_key_here"- web-search.py
- web-search-gpt-oss.py - Using browser research tools with gpt-oss
The MCP server can be used with an MCP client like Cursor, Cline, Codex, Open WebUI, Goose, and more.
uv run examples/web-search-mcp.pyConfiguration to use with an MCP client:
{
"mcpServers": {
"web_search": {
"type": "stdio",
"command": "uv",
"args": ["run", "path/to/ollama-python/examples/web-search-mcp.py"],
"env": { "OLLAMA_API_KEY": "your_api_key_here" }
}
}
}Note: Image generation is experimental and currently only available on macOS.
Requirement: pip install tqdm