Wbot-3 & Wbot-4-Preview

Wbot开放API

如何体验Wbot-4-Preview-low?

答:前往https://api.223387.xyz/体验!

对话型应用 API

对话应用支持会话持久化,可将之前的聊天记录作为上下进行回答,可适用于聊天/客服 AI 等。

基础 URL

https://servicewbot.ecylt.top/v1/chat-messages

鉴权

Service API 使用 API-Key 进行鉴权。 强烈建议开发者把 API-Key 放在后端存储,而非分享或者放在客户端存储,以免 API-Key 泄露,导致财产损失。 所有 API 请求都应在 Authorization HTTP Header 中包含您的 API-Key,如下所示:

Authorization: Bearer {API_KEY}

现版本API-Key仅开放给内测人员和专业版用户


POST

发送对话消息

创建会话消息。

Request Body

  • NamequeryTypestringDescription

    用户输入/提问内容。

  • NameinputsTypeobjectDescription

    (选填)允许传入 App 定义的各变量值。 inputs 参数包含了多组键值对(Key/Value pairs),每组的键对应一个特定变量,每组的值则是该变量的具体值。

  • Nameresponse_modeTypestringDescription

    • streaming 流式模式(推荐)。基于 SSE(Server-Sent Events)实现类似打字机输出方式的流式返回。

  • NameuserTypestringDescription

    用户标识,用于定义终端用户的身份,方便检索、统计。 由开发者定义规则,需保证用户标识在应用内唯一。

  • Nameconversation_idTypestringDescription

    (选填)会话 ID,需要基于之前的聊天记录继续对话,必须传之前消息的 conversation_id。

  • Nameauto_generate_nameTypeboolDescription

    (选填)自动生成标题,默认 false。 可通过调用会话重命名接口并设置 auto_generatetrue 实现异步生成标题。

Response

  • response_modestreaming时,返回 ChunkChatCompletionResponse object 流式序列。

  • ChunkChatCompletionResponse

  • 返回 App 输出的流式块,Content-Typetext/event-stream。 每个流式块均为 data: 开头,块之间以 \n\n 即两个换行符分隔,如下所示:

  • data: {"event": "message", "task_id": "900bbd43-dc0b-4383-a372-aa6e6c414227", "id": "663c5084-a254-4040-8ad3-51f2a3c1a77c", "answer": "Hi", "created_at": 1705398420}\n\n

流式块中根据 event 不同,结构也不同:

  • event: message LLM 返回文本块事件,即:完整的文本以分块的方式输出。

    • task_id (string) 任务 ID,用于请求跟踪和下方的停止响应接口

    • message_id (string) 消息唯一 ID

    • conversation_id (string) 会话 ID

    • answer (string) LLM 返回文本块内容

    • created_at (int) 创建时间戳,如:1705395332

  • event: agent_message Agent模式下返回文本块事件,即:在Agent模式下,文章的文本以分块的方式输出(仅Agent模式下使用)

    • task_id (string) 任务 ID,用于请求跟踪和下方的停止响应接口

    • message_id (string) 消息唯一 ID

    • conversation_id (string) 会话 ID

    • answer (string) LLM 返回文本块内容

    • created_at (int) 创建时间戳,如:1705395332

  • event: agent_thought Agent模式下有关Agent思考步骤的相关内容,涉及到工具调用(仅Agent模式下使用)

    • id (string) agent_thought ID,每一轮Agent迭代都会有一个唯一的id

    • task_id (string) 任务ID,用于请求跟踪下方的停止响应接口

    • message_id (string) 消息唯一ID

    • position (int) agent_thought在消息中的位置,如第一轮迭代position为1

    • thought (string) agent的思考内容

    • observation (string) 工具调用的返回结果

    • tool (string) 使用的工具列表,以 ; 分割多个工具

    • tool_input (string) 工具的输入,JSON格式的字符串(object)。如:{"dalle3": {"prompt": "a cute cat"}}

    • created_at (int) 创建时间戳,如:1705395332

    • message_files (array[string]) 当前 agent_thought 关联的文件ID

      • file_id (string) 文件ID

    • conversation_id (string) 会话ID

  • event: message_file 文件事件,表示有新文件需要展示

    • id (string) 文件唯一ID

    • type (string) 文件类型,目前仅为image

    • belongs_to (string) 文件归属,user或assistant,该接口返回仅为 assistant

    • url (string) 文件访问地址

    • conversation_id (string) 会话ID

  • event: message_end 消息结束事件,收到此事件则代表流式返回结束。

    • task_id (string) 任务 ID,用于请求跟踪和下方的停止响应接口

    • message_id (string) 消息唯一 ID

    • conversation_id (string) 会话 ID

    • metadata (object) 元数据

      • usage (Usage) 模型用量信息

      • retriever_resources (array[RetrieverResource]) 引用和归属分段列表

  • event: message_replace 消息内容替换事件。 开启内容审查和审查输出内容时,若命中了审查条件,则会通过此事件替换消息内容为预设回复。

    • task_id (string) 任务 ID,用于请求跟踪和下方的停止响应接口

    • message_id (string) 消息唯一 ID

    • conversation_id (string) 会话 ID

    • answer (string) 替换内容(直接替换 LLM 所有回复文本)

    • created_at (int) 创建时间戳,如:1705395332

  • event: error 流式输出过程中出现的异常会以 stream event 形式输出,收到异常事件后即结束。

    • task_id (string) 任务 ID,用于请求跟踪和下方的停止响应接口

    • message_id (string) 消息唯一 ID

    • status (int) HTTP 状态码

    • code (string) 错误码

    • message (string) 错误消息

  • event: ping 每 10s 一次的 ping 事件,保持连接存活。

Errors

  • 404,对话不存在

  • 400,invalid_param,传入参数异常

  • 400,app_unavailable,App 配置不可用

  • 400,provider_not_initialize,无可用模型凭据配置

  • 400,provider_quota_exceeded,模型调用额度不足

  • 400,model_currently_not_support,当前模型不可用

  • 400,completion_request_error,文本生成失败

  • 500,服务内部异常


示例

请求示例

curl -X POST 'https://servicewbot.ecylt.top/v1/chat-messages' \
--header 'Authorization: Bearer {api_key}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "inputs": {},
    "query": "What are the specs of the iPhone 13 Pro Max?",
    "response_mode": "streaming",
    "conversation_id": "",
    "user": "abc-123"
    ]
},'

流式模式返回示例

  data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "", "tool": "dalle3", "tool_input": "{\"dalle3\": {\"prompt\": \"cute Japanese anime girl with white hair, blue eyes, bunny girl suit\"}}", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_thought", "id": "8dcf3648-fbad-407a-85dd-73a6f43aeb9f", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 1, "thought": "", "observation": "image has been created and sent to user already, you should tell user to check it now.", "tool": "dalle3", "tool_input": "{\"dalle3\": {\"prompt\": \"cute Japanese anime girl with white hair, blue eyes, bunny girl suit\"}}", "created_at": 1705639511, "message_files": ["d75b7a5c-ce5e-442e-ab1b-d6a5e5b557b0"], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_thought", "id": "67a99dc1-4f82-42d3-b354-18d4594840c8", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 2, "thought": "", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": "I have created an image of a cute Japanese", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " anime girl with white hair and blue", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " eyes wearing a bunny girl" ,"created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_message", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "answer": " suit .", "created_at": 1705639511, "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "agent_thought", "id": "67a99dc1-4f82-42d3-b354-18d4594840c8", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "position": 2, "thought": "I have created an image of a cute Japanese anime girl with white hair and blue eyes wearing a bunny girl suit.", "observation": "", "tool": "", "tool_input": "", "created_at": 1705639511, "message_files": [], "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142"}
  data: {"event": "message_end", "task_id": "9cf1ddd7-f94b-459b-b942-b77b26c59e9b", "id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "message_id": "1fb10045-55fd-4040-99e6-d048d07cbad3", "conversation_id": "c216c595-2d89-438c-b33c-aae5ddddd142", "metadata": {"usage": {"prompt_tokens": 305, "prompt_unit_price": "0.001", "prompt_price_unit": "0.001", "prompt_price": "0.0003050", "completion_tokens": 97, "completion_unit_price": "0.002", "completion_price_unit": "0.001", "completion_price": "0.0001940", "total_tokens": 184, "total_price": "0.0002290", "currency": "USD", "latency": 1.771092874929309}}}

最后更新于