一、需求场景
·大模型返回不参与 TTS 的内容。
·大模型返回表情甚至业务信息。
二、非流式请求
在大模型返回的 body 中增加 metainfo 字段。
{ "id": "chatcmpl-123", "object": "chat.completion", "created": 1694268190, "model": "gpt-xxxx", "system_fingerprint": "fp_xxxx", "choices": [{ "index": 0, "message": { "role": "assistant", "content": "\\n\\nHello there, how may I assist you today?", "metainfo": {} // 这里增加自定义字段 }, "logprobs": null, "finish_reason": "stop" }], "usage": { "prompt_tokens": 9, "completion_tokens": 12, "total_tokens": 21, "completion_tokens_details": { "reasoning_tokens": 0 } }}
三、流式请求
在大模型流式返回 chat completion chunk 对象时,同时返回 metainfo 的 chunk。
{"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-xxxx", "system_fingerprint": "fp_xxxx", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]} {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-xxxx", "system_fingerprint": "fp_xxxx", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]} // 增加如下自定义消息 {"id":"chatcmpl-123","type":"meta.info","created":1694268190,"metainfo": {}} {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-xxxx", "system_fingerprint": "fp_xxxx", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}
四、客户端侧如何接收
TRTC AI 检测到有 metainfo 之后,通过 TRTC SDK 的 自定义消息 进行下发。客户端可通过 SDK 回调中的 onRecvCustomCmdMsg 接口接收。
{ "type": 10002, // 自定义消息 "sender": "user_a", // 发送者userid,这里是机器人的id "receiver": [], // 接受者userid列表,该消息实际是在房间内广播, "roundid": "xxxxxx", "payload": {} // metainfo }