Metadata-Version: 2.4
Name: ollama-langchain-client
Version: 0.1.2
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

# Defaults to a local Ollama server
client = OllamaClient(model="gemma4:12b")

reply = client.chat("你好！")
print(reply)
```

Point at a remote server and control "thinking":

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

## API

### `OllamaClient`

| Parameter     | Type             | Default                                   | Description                                      |
| ------------- | ---------------- | ----------------------------------------- | ------------------------------------------------ |
| `model`       | `str`            | `"gemma4:12b"`                            | Ollama model name.                               |
| `base_url`    | `str`            | `"http://localhost:11434/api/chat"`       | Ollama OpenAI-compatible endpoint.               |
| `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 reply text.
- `invoke(message, **kwargs) -> str` — alias for `chat`.

## License

MIT
