INNER CODE UNIT · Python

ChatReq

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

class ChatReq(BaseModel):
    messages: list[dict]
    context: str = ""
    llm: LLMConfig


@app.post("/api/chat")
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」里选择")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…