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 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 |
|---|---|
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file laiwenai-0.0.6.tar.gz.
File metadata
- Download URL: laiwenai-0.0.6.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f11bf74e09c0cd8162a3d704c3e20a6023b4e2349b6d6c366f2a0dfa914c7ff0
|
|
| MD5 |
9c786d612a6e9866934d8aa6b2ad35ff
|
|
| BLAKE2b-256 |
a95d6a3e5d027162d90944a45a7368c058ef6e8002bc87ec00d14d32221de190
|
File details
Details for the file laiwenai-0.0.6-py3-none-any.whl.
File metadata
- Download URL: laiwenai-0.0.6-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e83b7cf75f6179bf1e7743f8b8239d59e0272cc3285dcc986283a34ea1eb1242
|
|
| MD5 |
37c97eed7766305c4fbce7271310bb6c
|
|
| BLAKE2b-256 |
1a35da33a54f7c755224af2563d1a346d1e8d3b66b45632035e579cb0ca87cab
|