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

该文档介绍如何测试你的接口是否符合第三方大模型接口标准。你可以使用该工具测试你的接口是否符合要求,如果符合要求,则可以返回预期的输出结果。否则将返回异常信息。

资源下载(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/completions

大模型请求 URL。

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

llmAPIKey

String

sk-0aeQbtlX2reL

鉴权 APIKey。默认值为空。

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

openAI:

自定义URL:

接口标准

接口返回支持SSE。

Method

POST

Request body

Content-Type Application/json

参数类型必填描述
messagesObject of messages参考StartVoiceChat.HistoryLength,包含最近 HistoryLength 轮对话内容。当前 ASR 内容在数组末位。
streambool填入值:true
temperaturefloat透传
maxTokensint透传
modelstring透传 StartVoiceChat.LLMConfig.ModelName
top_pstring[]透传

messages

参数类型必填描述
rolestring取值:
  • user
  • assistant
contentstring内容

Response Body

StatusCode==200

Content-Type text/event-stream

参数类型必填描述
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

Content-Type Application/json
请求终止,报错返回。RTC 不做任何处理,仅报错。

参数类型必填描述
Errorobject错误
Codestring错误码
Messagestring错误原因

StatusCode!==200、4xx、5xx

Application/json
不处理,直接报错返回 StatusCode。RTC 不做任何处理,仅报错。