Metadata-Version: 2.4
Name: ollama-langchain-client
Version: 0.1.3
Summary: A lightweight, reusable Python client for Ollama's OpenAI-compatible chat API, built on langchain-openai.
Author: OllamaClient maintainers
License-Expression: MIT
Project-URL: Homepage, https://pypi.org/project/ollama-langchain-client/
Project-URL: Repository, https://github.com/
Project-URL: Documentation, https://pypi.org/project/ollama-langchain-client/
Keywords: ollama,llm,chat,langchain,openai,client,gemma
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: langchain-openai>=0.1
Dynamic: license-file

# ollama-langchain-client

A lightweight, reusable Python client for [Ollama](https://ollama.com)'s
OpenAI-compatible chat API, built on top of
[`langchain-openai`](https://pypi.org/project/langchain-openai/).

Point it at any Ollama server (local or remote) and chat with your models,
optionally toggling chain-of-thought "thinking" for models that support it.

## Installation

```bash
pip install ollama-langchain-client
```

## Quick start

```python
from ollama_langchain_client import OllamaClient

client = OllamaClient(
    model="gemma4:12b",
    base_url="http://your-server:11434/v1",
    think=False,        # disable chain-of-thought thinking
    num_predict=1024,   # max tokens to generate in one reply
)

# 非流式：一次性返回完整回复
reply = client.chat("你好！")
print(reply)

# 流式：逐块打印
for chunk in client.stream("写一首关于春天的诗"):
    print(chunk, end="", flush=True)
```

## API

### `OllamaClient`

| Parameter     | Type             | Default                                   | Description                                      |
| ------------- | ---------------- | ----------------------------------------- | ------------------------------------------------ |
| `model`       | `str`            | `"gemma4:12b"`                            | Ollama model name.                               |
| `base_url`    | `str`            | `"http://localhost:11434/v1"`             | Ollama OpenAI-compatible base URL (`/v1`).       |
| `api_key`     | `str`            | `"ollama"`                                | Auth token sent to Ollama.                       |
| `temperature` | `float`          | `0.0`                                     | Sampling temperature.                            |
| `think`       | `bool`           | `False`                                   | Disable chain-of-thought thinking when `False`.  |
| `num_predict` | `int \| None`    | `None`                                    | Max tokens per reply (Ollama `num_predict`).     |
| `timeout`     | `float \| None`  | `None`                                    | Optional request timeout (seconds).              |
| `**kwargs`    | —                | —                                         | Extra args forwarded to `ChatOpenAI`.            |

Methods:

- `chat(message, **kwargs) -> str` — send a message, return the full reply text.
- `invoke(message, **kwargs) -> str` — alias for `chat`.
- `stream(message, **kwargs) -> Iterator[str]` — stream the reply, yielding text chunks.

## License

MIT
