Skip to main content

AI Chain Python Client SDK for IIP Dispatch WebSocket protocol v2.0

Project description

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:

pip install aichain-sdk

For local development inside this repository:

pip install -e .

Quick Start

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

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

aichain_sdk-0.1.2.tar.gz (531.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aichain_sdk-0.1.2-py3-none-any.whl (521.7 kB view details)

Uploaded Python 3

File details

Details for the file aichain_sdk-0.1.2.tar.gz.

File metadata

  • Download URL: aichain_sdk-0.1.2.tar.gz
  • Upload date:
  • Size: 531.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for aichain_sdk-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6aad578bbd5e33e8efcc64ce6919e185b6321c09e1ebd3441b772041aea00b0e
MD5 42af80bfe2ae95e0c717b95a3755faf1
BLAKE2b-256 8b92d249fd4cd501e44e9290d11b4faa64e8fdf5a5534a0986a7163ca462e7de

See more details on using hashes here.

File details

Details for the file aichain_sdk-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: aichain_sdk-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 521.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for aichain_sdk-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6f1abd97969f75cd2bdf6c05825cf3bdeef53fee66213960a922756289ba557
MD5 80b297facd6d880b1af97fc176f4f76a
BLAKE2b-256 7ba4739eeac305e099ad48f2b85e7503fabab332334d17eaab5261762d1bc5e0

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