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.

(Note :- In Code We Have Used gemma3 model please use tool callling supported model else it might possible you face issue or errors for more information please check dockerhub AI Models.)

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/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/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.2.tar.gz (17.6 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.2-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docker_model_runner-0.1.2.tar.gz
  • Upload date:
  • Size: 17.6 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.2.tar.gz
Algorithm Hash digest
SHA256 727452006d7a74d44c5fd50f74e56009807ca22a13515f98ed370bc6e1ab45a1
MD5 c5687184692dd4d3a4ea27523ea32a83
BLAKE2b-256 3054c021c25a19ba5201f44fb1d252438288157c0e16c6beac50971b5213908b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for docker_model_runner-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 14b993a6d3d3b1607001a27133deefb96a843dab4b1f6380456e0f5dfdee4d02
MD5 edc5a131c80331d153ca037c7857be96
BLAKE2b-256 f7dca9c8cbeee1363888fd30d645e7eb82c08da395fb9ed7f53285a240cab71e

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