Skip to main content

Python client for Cudara inference server with prompt engineering utilities

Project description

cudara-client

PyPI Python 3.12+ License: MIT CI

Python client library for the Cudara inference server (Ollama-compatible API).

This package provides a small, synchronous httpx-based client for:

  • Chat (/api/chat)
  • Text generation (/api/generate)
  • Embeddings (/api/embeddings)
  • Vision helpers (send images via /api/generate)
  • Audio transcription (/api/transcribe)
  • Prompt building + output parsing utilities

Install

With uv

uv add cudara-client

With pip

pip install cudara-client

Run the Cudara API (server)

You need a running Cudara server to use this client.

Option A: Docker (recommended)

# Pull and run
docker run --gpus all -p 8000:8000 ghcr.io/juliog922/cudara:latest

# With persistent models
docker run --gpus all -p 8000:8000 \
  -v cudara_models:/app/models \
  ghcr.io/juliog922/cudara:latest

Option B: uv (development)

git clone https://github.com/juliog922/cudara
cd cudara
uv sync

# Run server
uv run cudara serve

Health check:

curl http://localhost:8000/health

Quickstart

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    # Optionally pull/download a model (if enabled on your server)
    client.pull("Qwen/Qwen2.5-3B-Instruct")

    resp = client.chat("Qwen/Qwen2.5-3B-Instruct", "Hello!")
    print(resp.content)

Chat

from cudara_client import CudaraClient, Message, GenerationOptions

with CudaraClient("http://localhost:8000") as client:
    resp = client.chat(
        "Qwen/Qwen2.5-3B-Instruct",
        [
            Message(role="system", content="You are concise."),
            Message(role="user", content="Explain embeddings in 2 bullets."),
        ],
        options=GenerationOptions(temperature=0.2, max_tokens=128),
    )
    print(resp.content)

Text generation

from cudara_client import CudaraClient, GenerationOptions

with CudaraClient("http://localhost:8000") as client:
    resp = client.generate(
        "Qwen/Qwen2.5-3B-Instruct",
        "Write a haiku about GPUs.",
        system="You are a poet.",
        options=GenerationOptions(max_tokens=64, temperature=0.8),
    )
    print(resp.content)

Embeddings

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    out = client.embed("sentence-transformers/all-MiniLM-L6-v2", ["hello", "world"])
    print(len(out.embeddings), len(out.embeddings[0]))

Single string convenience:

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    out = client.embed("sentence-transformers/all-MiniLM-L6-v2", "hello")
    vec = out.embedding
    print(len(vec))

Vision (image-to-text)

If your server is running a vision-language model, you can send images. vision() reads an image and sends it as base64 via /api/generate.

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    resp = client.vision(
        "your-vision-model",
        "Describe the image.",
        image_path="cat.jpg",
    )
    print(resp.content)

OCR helper

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    text = client.ocr("your-vision-model", "receipt.png")
    print(text)

Transcription (ASR)

Cudara supports multipart transcription at /api/transcribe.

from cudara_client import CudaraClient

with CudaraClient("http://localhost:8000") as client:
    out = client.transcribe("openai/whisper-small", "audio.wav", language="en")
    print(out.text)

Error handling

Any 4xx/5xx response raises CudaraError.

from cudara_client import CudaraClient, CudaraError

try:
    with CudaraClient("http://localhost:8000") as client:
        client.generate("unknown-model", "hello")
except CudaraError as e:
    print("Request failed:", e)

Development

uv sync --dev --locked
uv run pytest -v

License

MIT

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

cudara_client-0.0.3.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

cudara_client-0.0.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file cudara_client-0.0.3.tar.gz.

File metadata

  • Download URL: cudara_client-0.0.3.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cudara_client-0.0.3.tar.gz
Algorithm Hash digest
SHA256 e358c153d3d7c1312fd4966784976b51c16654464d6c3b10a8c983870e448878
MD5 4fc5676df859c5b51150590518f34669
BLAKE2b-256 bfc89f6e9b598936d9639499cb0d0f456e910a65f76b2532ff664059cb7ce7cb

See more details on using hashes here.

File details

Details for the file cudara_client-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: cudara_client-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cudara_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a23a85bc339cbcc5295ff54006e82489f1fe98bd53ba6dac4275ff2790cee48d
MD5 eaa8f38c2c48f0d5254222833404ae2e
BLAKE2b-256 6f4c4479097e7f755d58b54b9ae3f2581486985a31040f2602c476c642385877

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