INNER CODE UNIT · Python

chat

simonlin1212/vibe-astock · vr/app.py:93

def chat(req: ChatReq):
    """系统 AI 对话,**流式** NDJSON(每行一个事件 {type: tool|delta|done|error})。

    - API 接入:OpenAI 兼容 function-calling,边流答案边推工具调用事件。
    - 订阅接入(provider=cli-*):调本机已登录的 CLI,stdout 边出边流(数据靠 context)。
    配置错误(缺 key / 未装 CLI)走 HTTP 400;运行时错误走流内 error 事件。用户配置随请求传入,后端不持久化。
    """
    if not req.messages:
        raise HTTPException(400, "messages 不能为空")
    if not req.llm.model:
        raise HTTPException(400, "缺少模型配置,请先在「接入 AI」里选择")

    is_cli = req.llm.provider.startswith("cli-")
    if is_cli:
        kind = req.llm.provider[4:]
        if not cli_runtime.detect_cli(kind):
            raise HTTPException(400, f"未检测到「{kind}」对应的本机命令。请先安装并登录该 CLI,或改用「API 接入」。")
    elif not req.llm.apiKey or not req.llm.baseURL:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…