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=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=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.8.tar.gz (13.3 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.8-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: laiwenai-0.0.8.tar.gz
  • Upload date:
  • Size: 13.3 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.8.tar.gz
Algorithm Hash digest
SHA256 98495e80119ba38efc2665b1f3a2f29c3bc9937c60f7aa651d3b2a6729f7737c
MD5 d7034534fff2cc3657455d211f69f781
BLAKE2b-256 1ae67254643fdc96b7f74168ac4f58051412f33c659c204277e9590e7078916c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laiwenai-0.0.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0b9d6dff6010ad57769eeafde45847ee19537af30ae2bd06b77a21aca91b6cbc
MD5 ede93e58c595366ce9fe13e9e238fbf1
BLAKE2b-256 d6b0c3382175d3c25ac5ba2c037a0fa751c2891fbae578413c26adb2bcb65f2a

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