Python Client for Docker Model Runner
Project description
Docker Model Runner Client
A Python client for interacting with Docker Model Runner, providing a standard API interface for chat completions, embeddings, and more.
Installation
Install via pip:
pip install docker-model-runner
Quick Start
Synchronous Client
from docker_model_runner import Client
client = Client(base_url="http://localhost:12434/engines/llama.cpp/v1") # API key optional
# Chat completion
response = client.chat.completions.create(
model="your-model",
messages=[{"role": "user", "content": "Hello, world!"}]
)
print(response['choices'][0]['message']['content'])
Asynchronous Client
import asyncio
from docker_model_runner import AsyncClient
async def main():
async with AsyncClient(base_url="http://localhost:12434/engines/llama.cpp/v1") as client: # API key optional
response = await client.chat.completions.create(
model="your-model",
messages=[{"role": "user", "content": "Hello, world!"}]
)
print(response['choices'][0]['message']['content'])
asyncio.run(main())
Tool Calls
from docker_model_runner import Client
client = Client() # Uses default base_url, API key optional
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather",
"parameters": {
"type": "object",
"properties": {"location": {"type": "string"}},
"required": ["location"]
}
}
}
]
response = client.chat.completions.create(
model="your-model",
messages=[{"role": "user", "content": "What's the weather in Paris?"}],
tools=tools,
tool_choice="auto"
)
# Handle tool calls
message = response['choices'][0]['message']
if message.get("tool_calls"):
for tool_call in message["tool_calls"]:
print(f"Tool: {tool_call['function']['name']}")
Features
- Synchronous and asynchronous clients
- Chat completions with streaming support
- Embeddings
- Tool calls with local handling
- Compatible with standard API format
API Reference
Client
Client(base_url, api_key): Initialize sync client (api_key optional)client.chat.completions.create(model, messages, **kwargs): Create chat completionclient.chat.completions.stream(model, messages, **kwargs): Stream chat completionclient.embeddings.create(model, input, **kwargs): Create embeddingsclient.models.list(): List available models
AsyncClient
AsyncClient(base_url, api_key): Initialize async client (api_key optional)- Similar methods as Client, but async
Tool Choice
"auto": Let model decide (default)"none": Don't use tools"always": Force tool usage
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docker_model_runner-0.1.0.tar.gz.
File metadata
- Download URL: docker_model_runner-0.1.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c1fae5d62bc1d29a94856a5dcbfbd1852b0f1f5b4714419e0122b961609f8a8
|
|
| MD5 |
f4c938f7130d718ad47fecf1901212ac
|
|
| BLAKE2b-256 |
06aa737362ead5914a0871788175e2eeb5db6a79771a8706cab90cbab5334b83
|
File details
Details for the file docker_model_runner-0.1.0-py3-none-any.whl.
File metadata
- Download URL: docker_model_runner-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
564eb1b68a6cca1d7bad316623615c7fcaf59c15c8d56e03b10fa18f441889d5
|
|
| MD5 |
9546764ac52a94bbb7458cf3319b1996
|
|
| BLAKE2b-256 |
b32b03df396e287ad085147c842ded62042e2eccc0a6ebabae45f17964a6d758
|