应用开发开发教程
在异步 Web 服务中使用 SDK
在异步 Web 服务中使用 SDK:沿用平台当前公开 SDK 合同,区分本地模拟、联网调试与正式运行。
import httpx
from jusp_sdk.runtime import AsyncRuntimeClient, AsyncRuntimeHttpClient
session_client = AsyncRuntimeClient(
app_key="your-app",
)
runtime_pool = httpx.AsyncClient(trust_env=False)
async def handle(launch_code: str):
session = await session_client.exchange(launch_code)
runtime = AsyncRuntimeHttpClient(
session=session,
client=runtime_pool,
)
return await runtime.chat_completions({
"messages": [{"role": "user", "content": "你好"}],
})进程关闭时执行 await session_client.close() 和 await runtime_pool.aclose()。不要在每次请求中重新创建底层连接池。