ollama-langchain-client
A lightweight, reusable Python client for Ollama's
OpenAI-compatible chat API, built on top of
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
pip install ollama-langchain-client
Quick start
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 forchat.stream(message, **kwargs) -> Iterator[str]— stream the reply, yielding text chunks.
License
MIT
Metadata
Release files for ollama-langchain-client 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ollama_langchain_client-0.1.3.tar.gz | 4.6 kB | Without provenance | Details for ollama_langchain_client-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ollama_langchain_client-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for ollama_langchain_client-0.1.3-py3-none-any.whl |
Total release size: 10.0 kB
Release files / ollama_langchain_client-0.1.3.tar.gz
| Download URL | ollama_langchain_client-0.1.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
400c670b9311d7a7e5b9204cf3467d6ca236dab2a757e64082b5e18d3e5962d6
|
|
BLAKE2b-256 checksum How to use checksums |
3c77baa8af88724dde13c46b885a5c416cbb76a84df32ad7d64d50cd7b33645a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Release files / ollama_langchain_client-0.1.3-py3-none-any.whl
| Download URL | ollama_langchain_client-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6ea7568ec677c88649ceca3defad7594c6100e1935cdc8775e007f6d5412e93
|
|
BLAKE2b-256 checksum How to use checksums |
0f3011b0ebc5d4c4df5318e300844aaeffdd2e34b1b3cfaf6479180b8af44995
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.15
|
Security for ollama-langchain-client 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.