跳转到主要内容

安装

pip install shannon-sdk

第一个任务

from shannon import ShannonClient
client = ShannonClient(base_url="http://localhost:8080")

handle = client.submit_task("以单个词返回法国的首都。")
final = client.wait(handle.task_id, timeout=60)
print(final.result)

流式传输 (SSE)

from shannon import ShannonClient, EventType
client = ShannonClient()

h = client.submit_task(
  "起草一份约 120 字的关于近期三个量子计算里程碑的执行摘要。以 Markdown 段落格式输出。"
)
for e in client.stream(h.workflow_id, types=[EventType.LLM_OUTPUT, EventType.WORKFLOW_COMPLETED]):
  print(e.type, e.message)
  if e.type == EventType.WORKFLOW_COMPLETED:
    break

模型/模式选择(可选)

在提交时控制成本和提供商选择:
handle = client.submit_task(
  "将段落总结为三个重点关注收入趋势的要点。输出:Markdown 列表。",
  model_tier="small",                # small|medium|large
  # model_override="gpt-5-nano-2025-08-07",
  # provider_override="openai",      # 或 anthropic、google 等
  mode="simple",                      # simple|standard|complex|supervisor
)
print(client.wait(handle.task_id).result)

异步版本

import asyncio
from shannon import AsyncShannonClient

async def main():
  async with AsyncShannonClient(base_url="http://localhost:8080") as client:
    h = await client.submit_task(
      "对“我喜欢这个产品!”进行情感分类(positive|neutral|negative)。返回 JSON {label, score}。"
    )
    f = await client.wait(h.task_id)
    print(f.result)

asyncio.run(main())

CLI

# 使用模型选择提交
python -m shannon.cli --base-url http://localhost:8080 \
  submit "总结" --model-tier small --mode simple --wait