Metadata-Version: 2.4
Name: laiwenai
Version: 0.0.5
Summary: A lightweight OpenAI-compatible LLM client wrapper with defaults, retries, logging, and manual JSON mode.
Author: LaiwenAI
License-Expression: MIT
Keywords: openai,llm,client,json,retry
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: openai>=1.0.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: tenacity>=8.0.0
Dynamic: license-file

# 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

```bash
pip install laiwenai
```

## Initialize

Run this in your project directory:

```bash
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:

```env
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

```bash
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:

```bash
laiw test --embedding
```

## Python Usage

```python
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:

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

Embeddings:

```python
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
