Skip to main content

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.

GitHub

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 completion
  • client.chat.completions.stream(model, messages, **kwargs): Stream chat completion
  • client.embeddings.create(model, input, **kwargs): Create embeddings
  • client.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docker_model_runner-0.1.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docker_model_runner-0.1.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file docker_model_runner-0.1.1.tar.gz.

File metadata

  • Download URL: docker_model_runner-0.1.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for docker_model_runner-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4ddae52252ef0f207eabfdb58d4d2d668e5c486fd92eb2e65b97279e28e53aa4
MD5 0a8fd332ec1fdd0fac5a51d8d2cd3566
BLAKE2b-256 3f299f41ee960ca7da95e0b1c283fac672b8e2f97e718eb327cdcfa3db2094e0

See more details on using hashes here.

File details

Details for the file docker_model_runner-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for docker_model_runner-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d393f9952b28eee7651df16bab12f0ab890447f59aeda8449e995dcd6b523da8
MD5 c3e8b4ce625e482eddb961182632514b
BLAKE2b-256 27597e746c135ec583ab9838c77db35148d03f164371c35a3b9f120dcb3efb0a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page