跳转到主要内容

安装

pip install shannon-sdk
从源代码安装(开发):
git clone https://github.com/Kocoro-lab/Shannon.git
cd Shannon/clients/python
pip install -e .
可选(WebSocket 流支持):
pip install websockets

快速验证

from shannon import ShannonClient
client = ShannonClient(base_url="http://localhost:8080")
print("✓ SDK ready")

认证

from shannon import ShannonClient
client = ShannonClient(
  base_url="http://localhost:8080",
  api_key="sk_test_123"
)
通过环境变量驱动:
import os
from shannon import ShannonClient
client = ShannonClient(
  base_url=os.getenv("SHANNON_BASE_URL", "http://localhost:8080"),
  api_key=os.getenv("SHANNON_API_KEY"),
)

客户端选项

参数类型默认值说明
base_urlstrhttp://localhost:8080网关 HTTP URL
api_keystrNone作为 X-API-Key 发送
bearer_tokenstrNone备选的 Authorization: Bearer
default_timeoutfloat30.0

异步客户端

import asyncio
from shannon import AsyncShannonClient

async def main():
  async with AsyncShannonClient(base_url="http://localhost:8080") as client:
    h = await client.submit_task("分析数据")
    s = await client.wait(h.task_id)
    print(s.result)

asyncio.run(main())

CLI

python -m shannon.cli --base-url http://localhost:8080 submit "2+2 等于多少?" --wait