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 LLM_API_KEY, lets other values use defaults, then runs laiw test.

Default .env values:

LLM_API_KEY=your_api_key_here
DEFAULT_BASE_URL=http://111.228.11.28:3000/v1
DEFAULT_MODEL=DeepSeek-V4-Flash
DEFAULT_EMBEDDING_MODEL=text-embedding-3-small
DEFAULT_TEMPERATURE=0
DEFAULT_TIMEOUT=30.0
MAX_RETRIES=1
ENABLE_LOG_CONSOLE=False
ENABLE_LOG_FILE=False
LOG_DIR=logs

CLI

laiw test

laiw test checks the current directory .env and runs a chat smoke test. It prints the question and answer.

To also test embeddings:

laiw test --embedding

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))

Configuration

Key Description
LLM_API_KEY Default API key. Required unless passed explicitly.
DEFAULT_BASE_URL Default OpenAI-compatible base URL.
DEFAULT_MODEL Default chat/responses model.
DEFAULT_EMBEDDING_MODEL Default embedding model.
DEFAULT_TEMPERATURE Default temperature when omitted or None.
DEFAULT_TIMEOUT Default timeout when omitted or None.
MAX_RETRIES Retry attempts around API calls.
ENABLE_LOG_CONSOLE Enable structured console logs.
ENABLE_LOG_FILE Enable structured file logs.
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.5.tar.gz (12.0 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.5-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: laiwenai-0.0.5.tar.gz
  • Upload date:
  • Size: 12.0 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.5.tar.gz
Algorithm Hash digest
SHA256 0f3599f458f46af96dc728e8b3233d55ae0b4c415a07ac1621fb95b6262ae9fb
MD5 98ab09d2e1ce7cb018f015fd72a291be
BLAKE2b-256 21362d8a6d4aa40c2d9cb5d9602553399b06a9cc5e3e60b2161743cc0184e2f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: laiwenai-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.5-py3-none-any.whl
Algorithm Hash digest
SHA256 696264cc7db6106804bbcd1798072a5c77cdd90e6a073966971807f3f1d5dfc9
MD5 86c8d120e3b22374f07cb5f80b9fe713
BLAKE2b-256 22adb5b57d7789539d495d04be92dac1af6daed3ae6f35233c0f7256601b243e

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