You need to enable JavaScript to run this app.
导航
对话式 AI 第三方大模型接口验证
最近更新时间:2025.02.14 10:44:15首次发布时间:2024.12.17 17:10:35

在实时对话式 AI 场景下,你可能需要使用自研大模型进行更符合你要求场景的对话。如果你的大模型接口符合约定标准规范,就可以将你的大模型服务集成到对话式 AI 工作流中。

使用方法
  1. 参看接口标准对大模型接口进行改造。
  2. 使用接口标准验证工具验证接口是否符合标准。
  3. 调用 StartVoiceChat 接口启动智能体,LLMConfig 按照 RTC 约定第三方大模型参数结构配置。
接口标准

在对话期间,将按照以下格式通过 POST 请求访问你配置的大模型接口地址,获取相应结果。
接口返回需支持 SSE 协议。

Method

POST

Request body

HTTP 请求头中 Content-Type 取值为:application/json。

参数类型必填描述
messagesObject of messages参考StartVoiceChat.HistoryLength,包含最近 HistoryLength 轮对话内容。当前 ASR 内容在数组末位。
streamBoolean填入值:true
temperatureFloat透传 StartVoiceChat.LLMConfig.temperature
maxTokensInt透传 StartVoiceChat.LLMConfig.MaxTokens
modelString透传 StartVoiceChat.LLMConfig.ModelName
top_pFloat透传 StartVoiceChat.LLMConfig.TopP

messages

参数类型必填描述
roleString可取值及含义如下:
  • user
  • assistant
contentString对话内容。

Response Body

接口返回内容格式标准如下:

HTTP 响应头中 Content-Type 取值为:text/event-stream。

StatusCode==200

参数类型必填描述
idString请求 UUID。不同请求的 ID 需不同,但同一个流式请求的 ID 需相同。

choices

Object of choices

流式回复对象。

created

Int

UnixTime 时间戳,精确到秒。同一个请求的流式所有块拥有相同的时间戳。

usageObject of usage最后一个包可带此参数。
objectString填入值:chat.completion.chunk。填错将导致接口行为异常。

Choices

参数类型必填描述

finish_resaon

String

null: 流式请求未结束;
最后一个流式片段需填入以下值:
stop: 正常结束;
length: 达到 MaxTokens
content_filter: 内容不合规

deltaObject of delta流式片段对象。
modelString模型 ID。
stream_optionsobject流接口选项。

delta

参数类型必填描述
contentString对话内容。
roleString可取值及含义如下:
  • user
  • assistant
indexInt数组中位置,从 0 开始。

usage

参数类型必填描述
completion_tokensIntgenerated tokens 长度。
prompt_tokensIntprompt tokens 长度。
total_tokensIntprompt+generated tokens 长度。

成功请求及返回样例如下:

curl -v --location 'https://rtc-cloud-rendering.byted.org/voicechat/test-sse' \
--header 'Content-Type: application/json' \
--data '{
    "messages":[{
        "role":"user",
        "content":"今天适合干什么?"
    }],
    "stream": true,
    "temperature": 0.1,
    "max_tokens": 100,
    "top_p": 0.9,
    "model": "doubao-32k",
    "stream_options": {"include_usage":true}
}'

> POST /voicechat/test-sse HTTP/1.1
> Host: rtc-cloud-rendering.byted.org
> User-Agent: curl/8.4.0
> Accept: */*
> Content-Type: application/json
> Content-Length: 254
>
< HTTP/1.1 200 OK
< Date: Thu, 15 Aug 2024 09:36:02 GMT
< Content-Type: text/event-stream
< Transfer-Encoding: chunked
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Cache-Control: no-cache

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Role":"assistant"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":1,"delta":{"Content":"天"}},{"finish_reason":null,"index":0,"delta":{"Content":"从明"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"起,"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":1,"delta":{"Content":"幸福"}},{"finish_reason":null,"index":0,"delta":{"Content":"做一个"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"的"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"人"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"。"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"喂马,"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"劈柴,"}},{"finish_reason":null,"index":1,"delta":{"Content":"周游"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":null,"index":0,"delta":{"Content":"世界"}},{"finish_reason":null,"index":1,"delta":{"Content":"。"}}],"model":"doubao-32k-2024-07-25","created":1723714562}

data: {"id":"c99d67a4-5ae9-11ef-bdf5-b8cef6dcdbe2","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}],"model":"doubao-32k-2024-07-25","created":1723714562,"usage":{"prompt_tokens":1,"completion_tokens":2,"total_tokens":3}}

data: [DONE]

StatusCode==4xx、5xx

请求终止,报错返回。RTC 不做任何处理,仅报错。

参数类型必填描述
ErrorError错误详情。

Error

参数类型必填描述
CodeString错误码。
MessageString错误原因。

StatusCode!==200、4xx、5xx

此时 RTC 不做任何处理,仅报错,直接报错返回 StatusCode。

接口标准验证工具(Mac& Linux)


你可以使用该工具验证你的大模型接口是否符合标准规范。如果符合要求,则可以返回预期的输出结果。否则将返回异常信息。

Archive.zip
8.16MB
操作步骤
  1. 下载资源包。

  2. 进入资源包所在目录。

  3. 执行验证命令。

命令格式为:./app-mac <llmAPIUrl> <llmModel> <llmAPIKey> <LLMQuestion>
< > 中为你要填入的真实数据。例如:./app-mac https://api.cn/v1/chat/completion model-v1-chat sk-0aeQbtlX2reL 你好

参数名类型是否必填示例描述

llmAPIUrl

String

https://api.cn/v1/chat/completion

大模型请求 URL。

llmModelStringmodel-v1-chat大模型模型名称。默认值为空。

llmAPIKey

String

sk-0aeQbtlX2reL

鉴权 APIKey。默认值为空。

LLMQuestionString你好对话问题。
验证示例

openAI:

自定义URL: