ollama-python/examples
2024-11-20 13:45:38 -08:00
..
async-chat.py Examples and readme updates 2024-11-20 13:45:38 -08:00
async-generate.py Examples and readme updates 2024-11-20 13:45:38 -08:00
async-list.py Examples and readme updates 2024-11-20 13:45:38 -08:00
async-ps.py Examples and readme updates 2024-11-20 13:45:38 -08:00
async-tools.py Examples and readme updates 2024-11-20 13:45:38 -08:00
chat-stream.py Examples and readme updates 2024-11-20 13:45:38 -08:00
chat.py Examples and readme updates 2024-11-20 13:45:38 -08:00
create.py Examples and readme updates 2024-11-20 13:45:38 -08:00
fill-in-middle.py Examples and readme updates 2024-11-20 13:45:38 -08:00
generate-stream.py Examples and readme updates 2024-11-20 13:45:38 -08:00
generate.py Examples and readme updates 2024-11-20 13:45:38 -08:00
list.py Examples and readme updates 2024-11-20 13:45:38 -08:00
multimodal.py Examples and readme updates 2024-11-20 13:45:38 -08:00
ps.py Examples and readme updates 2024-11-20 13:45:38 -08:00
pull-progress.py Examples and readme updates 2024-11-20 13:45:38 -08:00
README.md Examples and readme updates 2024-11-20 13:45:38 -08:00
tools.py Examples and readme updates 2024-11-20 13:45:38 -08:00

Running Examples

Run the examples in this directory with:

# Navigate to examples directory
cd examples/

# Run example
python3 <example>.py

Chat

Generate

List

  • list.py - List all downloaded models and their properties
  • async-list.py - Async list all downloaded models and their properties

Fill in the middle

Multimodal

Pull Progress

Requirement: pip install tqdm

Ollama create (create a model)

Ollama ps (show model status - cpu/gpu usage)

Tools/Function Calling

  • tools.py - Simple example of Tools/Function Calling
  • async-tools.py - Async example of Tools/Function Calling

Configuring Clients

Custom parameters can be passed to the client when initializing:

import ollama
client = ollama.Client(
  host='http://localhost:11434',
  timeout=10.0, # Default: None
  follow_redirects=True, # Default: True
  headers={'x-some-header': 'some-value'}
)

Similarly, the AsyncClient class can be configured with the same parameters.