Skip to main content

A lightweight OpenAI-compatible LLM client wrapper with defaults, retries, logging, and manual JSON mode.

Project description

LaiwenAI

LaiwenAI is a lightweight Python wrapper for OpenAI-compatible LLM endpoints. It keeps the familiar OpenAI SDK style while adding project-local .env defaults, retries, optional logging, and a small laiw command line helper.

PyPI: https://pypi.org/project/laiwenai/

Install

pip install laiwenai

Initialize

Run this in your project directory:

laiw init

laiw init checks only the current working directory. It creates or completes .env.example and .env, asks for LAIWEN_API_KEY, lets other values use defaults, then runs laiw test.

Default .env values:

LAIWEN_API_KEY=your_api_key_here
LAIWEN_BASE_URL=http://111.228.11.28:3000/v1
LAIWEN_MODEL=DeepSeek-V4-Flash
LAIWEN_EMBED_MODEL=text-embedding-3-small
LAIWEN_TEMP=0
LAIWEN_TIMEOUT=30.0
LAIWEN_RETRIES=1
LAIWEN_LOG_CONSOLE=False
LAIWEN_LOG_FILE=False
LAIWEN_LOG_DIR=laiwen_logs

CLI

laiw test

laiw test checks the current directory .env and loads config from that file; values in the current .env override same-name system environment variables. It first prints the resolved environment config with LAIWEN_API_KEY masked, then runs a chat smoke test.

Example output:

Environment config:
  LAIWEN_API_KEY=your_a...here
  LAIWEN_BASE_URL=http://111.228.11.28:3000/v1
  LAIWEN_MODEL=DeepSeek-V4-Flash
  LAIWEN_EMBED_MODEL=text-embedding-3-small
  LAIWEN_TEMP=0.0
  LAIWEN_TIMEOUT=30.0
  LAIWEN_RETRIES=1
  LAIWEN_LOG_CONSOLE=False
  LAIWEN_LOG_FILE=False
  LAIWEN_LOG_DIR=laiwen_logs

To test JSON-mode output:

laiw test --json

To test chat and embeddings:

laiw test --embedding

To run all smoke tests:

laiw test --all

Python Usage

from laiwenai import LaiwenAI

client = LaiwenAI()

response = client.chat.completions.create(
    messages=[
        {"role": "user", "content": "What model are you? Reply briefly as: I am the XXX model."}
    ]
)

print(response.choices[0].message.content)

You can still pass OpenAI SDK parameters:

response = client.chat.completions.create(
    model=None,
    messages=[{"role": "user", "content": "Hello"}],
    temperature=None,
    timeout=None,
    response_format={"type": "json_object"},
)

Embeddings:

embedding = client.embeddings.create(input="Hello")
print(len(embedding.data[0].embedding))

OpenAI-Compatible Endpoints

When you pass a custom base_url, you must also pass api_key explicitly. This prevents accidentally sending the default key to another provider.

from laiwenai import LaiwenAI

client = LaiwenAI(
    api_key="your-provider-key",
    base_url="http://111.228.11.28:3000/v1",
    model="DeepSeek-V4-Flash",
)

Configuration

Key Description
LAIWEN_API_KEY Default API key. Required unless passed explicitly.
LAIWEN_BASE_URL Default OpenAI-compatible base URL.
LAIWEN_MODEL Default chat/responses model.
LAIWEN_EMBED_MODEL Default embedding model.
LAIWEN_TEMP Default temperature when omitted or None.
LAIWEN_TIMEOUT Default timeout when omitted or None.
LAIWEN_RETRIES Retry attempts around API calls.
LAIWEN_LOG_CONSOLE Enable structured console logs.
LAIWEN_LOG_FILE Enable structured file logs.
LAIWEN_LOG_DIR Directory for laiwenai.log.

Notes

LaiwenAI() loads .env only from the current working directory. If .env is missing, initialization fails with a clear error.

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

laiwenai-0.0.9.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

laiwenai-0.0.9-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file laiwenai-0.0.9.tar.gz.

File metadata

  • Download URL: laiwenai-0.0.9.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for laiwenai-0.0.9.tar.gz
Algorithm Hash digest
SHA256 7862270228470550f1e47374ae2242492cb2d62de905092e4b890290a063fcf1
MD5 709bd30e9fb39c7fa553f94a5ff4a883
BLAKE2b-256 b3d8a3740153eda7c9f867c6710d8f83418e3a9fa78eefb8e1ce62b3f15d217c

See more details on using hashes here.

File details

Details for the file laiwenai-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: laiwenai-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for laiwenai-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 586ff61aad9c5c8e35bdf60b91834cd5da2cc6bd34647168f70d5ce9f97e9053
MD5 5410bea8b04cb3502404dc17bbd1afa6
BLAKE2b-256 2d3cba9f78a9689ce2a4b841b02665c710476abf8d1c34dd750c29d8e46e74b1

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