Metadata-Version: 2.4
Name: respan-instrumentation-ollama
Version: 0.1.1
Summary: Respan instrumentation plugin for Ollama
License: Apache 2.0
Author: Respan
Author-email: team@respan.ai
Requires-Python: >=3.11,<3.14
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Provides-Extra: instruments
Requires-Dist: ollama (>=0.6.0) ; extra == "instruments"
Requires-Dist: opentelemetry-semantic-conventions-ai (>=0.4.1)
Requires-Dist: respan-sdk (>=2.6.26)
Requires-Dist: respan-tracing (>=2.17.0,<3.0.0)
Description-Content-Type: text/markdown

# respan-instrumentation-ollama

Respan instrumentation plugin for [Ollama](https://ollama.com/). It instruments the official Ollama Python client and emits chat, completion, and embedding spans into the Respan tracing pipeline.

Chat spans include canonical request tool definitions and only the tool calls emitted by the current response turn. Streamed calls are marked with `llm.is_streaming`, and provider HTTP failures retain their explicit status code.

## Configuration

### 1. Install

```bash
pip install respan-ai respan-instrumentation-ollama ollama
```

`ollama` is the official Ollama Python client. A running Ollama server is required for real model calls.

### 2. Set Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `RESPAN_API_KEY` | Yes | Your Respan API key. |
| `RESPAN_BASE_URL` | No | Defaults to `https://api.respan.ai/api`. |
| `OLLAMA_HOST` | No | Ollama server URL. Defaults to the Ollama client default. |
| `OLLAMA_MODEL` | No | Model used by your application. |

## Quickstart

```python
import os

from dotenv import load_dotenv
from ollama import Client
from respan import Respan, workflow
from respan_instrumentation_ollama import OllamaInstrumentor

load_dotenv()

respan = Respan(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
    instrumentations=[OllamaInstrumentor()],
)
client = Client(host=os.getenv("OLLAMA_HOST"))


@workflow(name="ollama_quickstart")
def run() -> str:
    response = client.chat(
        model=os.getenv("OLLAMA_MODEL", "llama3.2"),
        messages=[{"role": "user", "content": "Reply with one concise sentence."}],
    )
    return response["message"]["content"]


print(run())
respan.flush()
respan.shutdown()
```

## Further Reading

See the [Respan example projects](https://github.com/respanai/respan-example-projects/tree/main/python/tracing/ollama) for runnable scripts.

