Metadata-Version: 2.4
Name: aichain-sdk
Version: 0.1.4
Summary: AI Chain Python Client SDK for IIP Dispatch WebSocket protocol v2.0
Author-email: AI Chain SDK Team <justpluspro@gmail.com>
Project-URL: Homepage, https://aichain-sh.xfyun.cn
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: websockets>=14.0
Requires-Dist: pydantic<3.0,>=2.0
Requires-Dist: numpy>=2.2.6
Requires-Dist: soundfile>=0.13.1
Requires-Dist: sounddevice>=0.5.5
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
Requires-Dist: build>=1.5.0; extra == "dev"
Requires-Dist: twine>=6.2.0; extra == "dev"

## AI Chain Python Client SDK

This package provides a Python implementation of the **AI Chain Client SDK** for
the WebSocket **v2.1** interaction protocol described in:

- `交互协议设计文档.md`
- `Client SDK设计文档.md`

### Features

- Async WebSocket client (`AIChainClient`) based on `asyncio`
- Strongly-typed session configuration (`SessionConfig`) matching the protocol
- Typed request items (`TextItem`, `ImageItem`, `AudioItem`)
- Typed result / event objects (STT, NLU, TTS, welcome, system events)
- Event-based callback system: `client.on(event, callback)`
- Built‑in CID generation and checksum generation utilities
- Heartbeat loop after `session.configed`

### Installation

In your own project (outside this repo) you can install this package once it is
packaged and published, for example:

```bash
pip install aichain-sdk
```

### Quick Start

```python
import asyncio
from aichain_sdk import AIChainClient, SessionConfig


async def main():
    client = AIChainClient(
        app_id="your_app_id",
        app_key="your_app_key",
        host="itv-bbs.openspeech.cn:9706",
        sn="SN123456789",
        scene="customer_service",
    )

    @client.on("nlu.answer")
    def on_nlu_answer(cid, result, is_last):
        print(result.answer, end="", flush=True)
        if is_last:
            print("\n[NLU done]")

    await client.connect()
    await client.set_config(
        SessionConfig(
            nlu={
                "enable": True,
                "tools": {
                    "models": [{"modelId": "spark-v3.5"}],
                    "modelId": "spark-v3.5",
                },
            }
        )
    )

    await client.begin_send()
    await client.send_text("你好")

    # keep process alive to receive streaming responses
    await asyncio.sleep(5)

    await client.disconnect()


if __name__ == "__main__":
    asyncio.run(main())
```

### Status

This is an initial implementation aligned with the v2.1 protocol and the SDK
design document. It focuses on:

- Correct protocol message formats
- Event dispatching semantics
- Core connection / configuration / send APIs

You can extend it with more advanced features such as:

- More detailed logging hooks
- Custom reconnection policies
- Rich error handling and metrics


