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.

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:

环境参数:
  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": "你是什么模型?请用中文简短回复:我是XXX模型。"}
    ]
)

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 兼容接口

当你传入自定义 base_url 时,必须显式传入 api_key,避免把默认密钥误用于另一个服务商。

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.7.tar.gz (13.1 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.7-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: laiwenai-0.0.7.tar.gz
  • Upload date:
  • Size: 13.1 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.7.tar.gz
Algorithm Hash digest
SHA256 cc8d5635c12c58edc3c5691481e46ce35c6104bf4e76f7632e8c079699d611a6
MD5 f33f2e11ad5b3b394fdc14445afe165a
BLAKE2b-256 a33550c77d4f05595bec647735fc52bbfda2414121ffd9d575ae06351a6f8488

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laiwenai-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c904f39c30a4350499dc57cba24f65bad6ce025abf7646077c2a663508d2b9ca
MD5 4cb9e6a0eb19368f9ff4e7c7183fe15a
BLAKE2b-256 df613930fc63fe29358c3e782ca85b9c2598e04e45d1b2e773e17f7631fc3b1e

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