Skip to main content

A minimal, backend-agnostic AI resolver with SQL adapters.

Project description

clx — Minimal AI Resolver

clx is a lightweight Python library that forwards prompts to your own AI backend. It exposes a single primitive, clx_query, plus a handful of thin task helpers and SQL adapters for Spark, DuckDB, and SQLite. The library never talks directly to OpenAI/Ollama/etc.—you point it at any backend that implements the simple /v1/query contract.

Installation

pip install clx-cli

Backend configuration

Provide a backend URL via (in order of precedence):

  1. Function argument: backend_url="https://your-worker.workers.dev"
  2. Environment variable: CLX_BACKEND_URL
  3. Config file: ~/.clx/config.toml

Example ~/.clx/config.toml:

backend_url = "https://my-backend.company.com"

Default /v1/query contract

POST /v1/query
{
  "model": "...",
  "prompt": "...",
  "params": { ... }
}

Response:
{ "output": ... }  # string or JSON-serializable

Pod/actor worker-style backend

If your backend uses the pods/{podName}/actors/{actorId}/run route (see example below), set CLX_POD_NAME and CLX_ACTOR_ID (or pass pod_name/actor_id to clx_query). Payload will be sent as {"messages": [{"role":"user","content": prompt}], "metadata": {...}} when use_messages_payload=True.

Example endpoint: https://your-worker.workers.dev/pods/{podName}/actors/{actorId}/run

Core usage

from clx import Cache, clx_query

result = clx_query(
    model="meta-llama-3-3-70b-instruct",
    prompt="Summarize: " + text,
    params={"max_tokens": 120, "temperature": 0.3},
    backend_url="https://your-worker.workers.dev",  # optional if CLX_BACKEND_URL/config is set
)
print(result)

Optional caching

Caching is off by default. Pass a Cache instance to enable it (keyed by backend URL + model + prompt + params).

from clx import Cache, clx_query

with Cache() as cache:
    summary = clx_query("meta-llama", "Summarize: " + text, cache=cache)

Worker-style backend usage

from clx import clx_query

result = clx_query(
    model="meta-llama-3-3-70b-instruct",
    prompt="What is 2+2?",
    backend_url="https://your-worker.workers.dev",
    pod_name="ed98786f-0342-4785-9be4-f0b9988ecd27",
    actor_id="3ec7a4b1-2e63-4c05-9ba5-25df471ceefc",
    use_messages_payload=True,
    metadata={"user_id": "user_123"},
)
print(result)  # e.g., "2+2 equals 4."

Paseo backend optimization

clx is optimized to work cleanly with the Paseo backend contract:

  • Supports pod/actor routes at https://<paseo-worker>/pods/{podName}/actors/{actorId}/run.
  • Uses use_messages_payload=True to send {"messages": [{"role":"user","content": prompt}], "metadata": {...}} which matches Paseo’s expected shape.
  • Accepts response or output fields so Paseo responses map directly to return values.
  • Environment-friendly defaults: set CLX_BACKEND_URL, CLX_POD_NAME, CLX_ACTOR_ID, and CLX_MODEL (e.g., @cf/meta/llama-3.1-8b-instruct) in .env and invoke clx_query or demo_backend_call.py.

Task helpers

All helpers forward to clx_query with light prompt templates:

  • clx_gen(model, prompt, **params)
  • clx_summarize(model, text, **params)
  • clx_translate(model, text, target_lang, **params)
  • clx_classify(model, text, labels, **params)
  • clx_extract(model, text, schema, **params)
  • clx_similarity(model, a, b, **params)
  • clx_fix_grammar(model, text, **params)

Example:

from clx import clx_summarize
summary = clx_summarize("meta-llama3", text, max_tokens=100)

SQL adapters

Each adapter registers clx_query as a SQL function and returns strings (JSON is returned as a stringified payload when expect_json=True).

Spark

from clx.adapters.spark import register_clx_query
register_clx_query(spark, expect_json=True)

df_out = df.selectExpr(
    "clx_query('meta-llama3', CONCAT('Summarize: ', text), named_struct('max_tokens', 120)) AS summary"
)

DuckDB

import duckdb
from clx.adapters.duckdb import register_clx_query

con = duckdb.connect()
register_clx_query(con)

con.execute(\"\"\"
SELECT clx_query(
  'meta-llama3',
  'Translate: ' || text,
  '{"max_tokens": 80}'
) AS translation
FROM docs;
\"\"\")

SQLite

import sqlite3
from clx.adapters.sqlite import register_clx_query

conn = sqlite3.connect(":memory:")
register_clx_query(conn)

conn.execute("SELECT clx_query('meta-llama3', 'Summarize: ' || text, NULL) FROM messages;")

Notes

  • clx_query returns either a string or JSON (when expect_json=True, invalid JSON raises ValueError).
  • Backend errors surface as RuntimeError with the status code.
  • Keep your backend responsible for model selection, routing, and authentication.

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

clx_cli-0.6.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

clx_cli-0.6.0-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file clx_cli-0.6.0.tar.gz.

File metadata

  • Download URL: clx_cli-0.6.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for clx_cli-0.6.0.tar.gz
Algorithm Hash digest
SHA256 155863b7382362c21230785c37730f86553624498fb775c681349741e10d0e14
MD5 cddc8e4da55c65671f65bbd51335d4ba
BLAKE2b-256 13efaeafc1d616861776b2d2f9281bf1dff5d9099762a6b711b6b387f20528c1

See more details on using hashes here.

File details

Details for the file clx_cli-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: clx_cli-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for clx_cli-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35e5ceb964330ec721fa366f1afaf5fdf54ef5b744cbf5c11c3a34a9bc890eb2
MD5 4b43e98df68d9b16042b30e106656ea1
BLAKE2b-256 8e89a85adfd4997962298eb0dc8b7fa4680562c2e5e91d3e8092533fa1293e1d

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