返回博客列表

阿里 Ant X使用

2026-01-29
1 min read
2026-01-19

发送消息 自定义发送消息, 比如使用工具情况,这样会导致添加一个一行空的用户消息。所以要用 reload 属性 还有一种简单的用法就是用更新消息方法

发送消息

    const {onRequest, messages, isRequesting, abort, onReload} = useXChat({
        provider: providerFactory(curConversation), // every conversation has its own provider
        conversationKey: curConversation,
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-expect-error
        defaultMessages: historyMessageFactory(curConversation),
        requestPlaceholder: () => {
            return {
                content: locale.noData,
                role: 'assistant',
            };
        },
        requestFallback: (_, {error, errorInfo, messageInfo}) => {
            if (error.name === 'AbortError') {
                return {
                    content: messageInfo?.message?.content || locale.requestAborted,
                    role: 'assistant',
                };
            }
            return {
                content: errorInfo?.error?.message || locale.requestFailed,
                role: 'assistant',
            };
        },
    });

自定义发送消息, 比如使用工具情况,这样会导致添加一个一行空的用户消息。所以要用 reload 属性

    onRequest({
         chatSpaceId: curConversation,
            confirmed: true,
         },
         {
            reload: true,
            updatingId: id,
         })

还有一种简单的用法就是用更新消息方法

    const useToolsRequest = (toolCall: PendingToolCall, id: string) => {
        onReload(id, {
            chatSpaceId: curConversation,
            confirmed: true,
        })
    }
返回博客列表
最后更新于 2026-01-29
想法或问题?在 GitHub Issue 下方参与讨论
去评论