Replies: 1 comment 2 replies
-
|
可以,ant-design/x 提供了 AI 请求生命周期相关的回调接口,比如 onSuccess(AI回答完成)、onUpdate(流式更新)、onError(出错)等。你可以在 onSuccess 回调里安全地更新当前会话标题,这个时机就是 AI 回答完整返回之后,官方和示例代码都是这么做的 示例1 示例2。 通常做法是:在 onSuccess 回调里用 setState 或 setSessionList 等方式修改当前会话的 label 字段,比如: agent.request(
{ messages: [{ role: 'user', content: input }] },
{
onSuccess: (chunks) => {
// 这里更新会话标题,比如用 AI 返回内容的前几句
setSessionList(list =>
list.map(item =>
item.key === curSession
? { ...item, label: getTitleFromAI(chunks) }
: item
)
);
},
onUpdate: (chunk) => {
// 流式更新内容,不建议在这里更新标题
},
}
);也可以结合 isRequesting 状态(AI请求进行中为 true,完成后为 false)做辅助判断 参考。 注意:不要在 onUpdate 里更新标题,因为 AI 还没回答完,内容可能不完整。只需要在 onSuccess 里处理即可。 To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
主要是更新会话标题的时机,有没有ai回答完成的回调之类的接口
Beta Was this translation helpful? Give feedback.
All reactions