aichain-sdk 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aichain_sdk-0.1.0/PKG-INFO +116 -0
- aichain_sdk-0.1.0/README.md +97 -0
- aichain_sdk-0.1.0/aichain_sdk/__init__.py +13 -0
- aichain_sdk-0.1.0/aichain_sdk/client.py +1254 -0
- aichain_sdk-0.1.0/aichain_sdk/config.py +174 -0
- aichain_sdk-0.1.0/aichain_sdk/errors.py +21 -0
- aichain_sdk-0.1.0/aichain_sdk/events.py +586 -0
- aichain_sdk-0.1.0/aichain_sdk/types.py +102 -0
- aichain_sdk-0.1.0/aichain_sdk/utils.py +59 -0
- aichain_sdk-0.1.0/aichain_sdk.egg-info/PKG-INFO +116 -0
- aichain_sdk-0.1.0/aichain_sdk.egg-info/SOURCES.txt +27 -0
- aichain_sdk-0.1.0/aichain_sdk.egg-info/dependency_links.txt +1 -0
- aichain_sdk-0.1.0/aichain_sdk.egg-info/requires.txt +11 -0
- aichain_sdk-0.1.0/aichain_sdk.egg-info/top_level.txt +2 -0
- aichain_sdk-0.1.0/examples/__init__.py +0 -0
- aichain_sdk-0.1.0/examples/full_duplex_example.py +348 -0
- aichain_sdk-0.1.0/examples/half_duplex_example.py +181 -0
- aichain_sdk-0.1.0/examples/nlu_example.py +69 -0
- aichain_sdk-0.1.0/examples/stt_example.py +137 -0
- aichain_sdk-0.1.0/examples/test.wav +0 -0
- aichain_sdk-0.1.0/examples/text_chat_example.py +66 -0
- aichain_sdk-0.1.0/examples/tts_output.wav +0 -0
- aichain_sdk-0.1.0/pyproject.toml +44 -0
- aichain_sdk-0.1.0/setup.cfg +4 -0
- aichain_sdk-0.1.0/test/test_buffer.py +233 -0
- aichain_sdk-0.1.0/test/test_connection.py +301 -0
- aichain_sdk-0.1.0/test/test_integration.py +1063 -0
- aichain_sdk-0.1.0/test/test_interrupt.py +317 -0
- aichain_sdk-0.1.0/test/test_reconnect.py +553 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aichain-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: AI Chain Python Client SDK for IIP Dispatch WebSocket protocol v2.0
|
|
5
|
+
Author-email: AI Chain SDK Team <justpluspro@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://aichain-sh.xfyun.cn
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: websockets<13.0,>=12.0
|
|
10
|
+
Requires-Dist: pydantic<3.0,>=2.0
|
|
11
|
+
Requires-Dist: numpy>=2.2.6
|
|
12
|
+
Requires-Dist: soundfile>=0.13.1
|
|
13
|
+
Requires-Dist: sounddevice>=0.5.5
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
17
|
+
Requires-Dist: build>=1.5.0; extra == "dev"
|
|
18
|
+
Requires-Dist: twine>=6.2.0; extra == "dev"
|
|
19
|
+
|
|
20
|
+
## AI Chain Python Client SDK
|
|
21
|
+
|
|
22
|
+
This package provides a Python implementation of the **AI Chain Client SDK** for
|
|
23
|
+
the WebSocket **v2.1** interaction protocol described in:
|
|
24
|
+
|
|
25
|
+
- `交互协议设计文档.md`
|
|
26
|
+
- `Client SDK设计文档.md`
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
- Async WebSocket client (`AIChainClient`) based on `asyncio`
|
|
31
|
+
- Strongly-typed session configuration (`SessionConfig`) matching the protocol
|
|
32
|
+
- Typed request items (`TextItem`, `ImageItem`, `AudioItem`)
|
|
33
|
+
- Typed result / event objects (STT, NLU, TTS, welcome, system events)
|
|
34
|
+
- Event-based callback system: `client.on(event, callback)`
|
|
35
|
+
- Built‑in CID generation and checksum generation utilities
|
|
36
|
+
- Heartbeat loop after `session.configed`
|
|
37
|
+
|
|
38
|
+
### Installation
|
|
39
|
+
|
|
40
|
+
In your own project (outside this repo) you can install this package once it is
|
|
41
|
+
packaged and published, for example:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install aichain-sdk
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For local development inside this repository:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
pip install -e .
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Quick Start
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
import asyncio
|
|
57
|
+
from aichain_sdk import AIChainClient, SessionConfig
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def main():
|
|
61
|
+
client = AIChainClient(
|
|
62
|
+
app_id="your_app_id",
|
|
63
|
+
app_key="your_app_key",
|
|
64
|
+
host="itv-bbs.openspeech.cn:9706",
|
|
65
|
+
sn="SN123456789",
|
|
66
|
+
scene="customer_service",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@client.on("nlu.answer")
|
|
70
|
+
def on_nlu_answer(cid, result, is_last):
|
|
71
|
+
print(result.answer, end="", flush=True)
|
|
72
|
+
if is_last:
|
|
73
|
+
print("\n[NLU done]")
|
|
74
|
+
|
|
75
|
+
await client.connect()
|
|
76
|
+
await client.set_config(
|
|
77
|
+
SessionConfig(
|
|
78
|
+
nlu={
|
|
79
|
+
"enable": True,
|
|
80
|
+
"tools": {
|
|
81
|
+
"models": [{"modelId": "spark-v3.5"}],
|
|
82
|
+
"modelId": "spark-v3.5",
|
|
83
|
+
},
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
await client.begin_send()
|
|
89
|
+
await client.send_text("你好")
|
|
90
|
+
|
|
91
|
+
# keep process alive to receive streaming responses
|
|
92
|
+
await asyncio.sleep(5)
|
|
93
|
+
|
|
94
|
+
await client.disconnect()
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
if __name__ == "__main__":
|
|
98
|
+
asyncio.run(main())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Status
|
|
102
|
+
|
|
103
|
+
This is an initial implementation aligned with the v2.1 protocol and the SDK
|
|
104
|
+
design document. It focuses on:
|
|
105
|
+
|
|
106
|
+
- Correct protocol message formats
|
|
107
|
+
- Event dispatching semantics
|
|
108
|
+
- Core connection / configuration / send APIs
|
|
109
|
+
|
|
110
|
+
You can extend it with more advanced features such as:
|
|
111
|
+
|
|
112
|
+
- More detailed logging hooks
|
|
113
|
+
- Custom reconnection policies
|
|
114
|
+
- Rich error handling and metrics
|
|
115
|
+
|
|
116
|
+
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
## AI Chain Python Client SDK
|
|
2
|
+
|
|
3
|
+
This package provides a Python implementation of the **AI Chain Client SDK** for
|
|
4
|
+
the WebSocket **v2.1** interaction protocol described in:
|
|
5
|
+
|
|
6
|
+
- `交互协议设计文档.md`
|
|
7
|
+
- `Client SDK设计文档.md`
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- Async WebSocket client (`AIChainClient`) based on `asyncio`
|
|
12
|
+
- Strongly-typed session configuration (`SessionConfig`) matching the protocol
|
|
13
|
+
- Typed request items (`TextItem`, `ImageItem`, `AudioItem`)
|
|
14
|
+
- Typed result / event objects (STT, NLU, TTS, welcome, system events)
|
|
15
|
+
- Event-based callback system: `client.on(event, callback)`
|
|
16
|
+
- Built‑in CID generation and checksum generation utilities
|
|
17
|
+
- Heartbeat loop after `session.configed`
|
|
18
|
+
|
|
19
|
+
### Installation
|
|
20
|
+
|
|
21
|
+
In your own project (outside this repo) you can install this package once it is
|
|
22
|
+
packaged and published, for example:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install aichain-sdk
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
For local development inside this repository:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install -e .
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Quick Start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import asyncio
|
|
38
|
+
from aichain_sdk import AIChainClient, SessionConfig
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
async def main():
|
|
42
|
+
client = AIChainClient(
|
|
43
|
+
app_id="your_app_id",
|
|
44
|
+
app_key="your_app_key",
|
|
45
|
+
host="itv-bbs.openspeech.cn:9706",
|
|
46
|
+
sn="SN123456789",
|
|
47
|
+
scene="customer_service",
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
@client.on("nlu.answer")
|
|
51
|
+
def on_nlu_answer(cid, result, is_last):
|
|
52
|
+
print(result.answer, end="", flush=True)
|
|
53
|
+
if is_last:
|
|
54
|
+
print("\n[NLU done]")
|
|
55
|
+
|
|
56
|
+
await client.connect()
|
|
57
|
+
await client.set_config(
|
|
58
|
+
SessionConfig(
|
|
59
|
+
nlu={
|
|
60
|
+
"enable": True,
|
|
61
|
+
"tools": {
|
|
62
|
+
"models": [{"modelId": "spark-v3.5"}],
|
|
63
|
+
"modelId": "spark-v3.5",
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
await client.begin_send()
|
|
70
|
+
await client.send_text("你好")
|
|
71
|
+
|
|
72
|
+
# keep process alive to receive streaming responses
|
|
73
|
+
await asyncio.sleep(5)
|
|
74
|
+
|
|
75
|
+
await client.disconnect()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Status
|
|
83
|
+
|
|
84
|
+
This is an initial implementation aligned with the v2.1 protocol and the SDK
|
|
85
|
+
design document. It focuses on:
|
|
86
|
+
|
|
87
|
+
- Correct protocol message formats
|
|
88
|
+
- Event dispatching semantics
|
|
89
|
+
- Core connection / configuration / send APIs
|
|
90
|
+
|
|
91
|
+
You can extend it with more advanced features such as:
|
|
92
|
+
|
|
93
|
+
- More detailed logging hooks
|
|
94
|
+
- Custom reconnection policies
|
|
95
|
+
- Rich error handling and metrics
|
|
96
|
+
|
|
97
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from .client import AIChainClient
|
|
2
|
+
from .config import SessionConfig, VoiceConfig, AudioConfig
|
|
3
|
+
from .errors import AIChainError
|
|
4
|
+
from .utils import get_version
|
|
5
|
+
|
|
6
|
+
__all__ = [
|
|
7
|
+
"AIChainClient",
|
|
8
|
+
"SessionConfig",
|
|
9
|
+
"VoiceConfig",
|
|
10
|
+
"AudioConfig",
|
|
11
|
+
"AIChainError",
|
|
12
|
+
"get_version",
|
|
13
|
+
]
|