feat: llm node support tools

This commit is contained in:
zxhlyh
2026-01-04 18:03:47 +08:00
parent e83635ee5a
commit ececc5ec2c
6 changed files with 172 additions and 1 deletions

View File

@ -270,9 +270,53 @@ export const useChat = (
handleRun(
bodyParams,
{
onData: (message: string, isFirstMessage: boolean, { conversationId: newConversationId, messageId, taskId }: any) => {
onData: (message: string, isFirstMessage: boolean, {
conversationId: newConversationId,
messageId,
taskId,
chunk_type,
tool_call_id,
tool_name,
tool_arguments,
tool_files,
tool_error,
tool_elapsed_time,
}: any) => {
responseItem.content = responseItem.content + message
if (chunk_type === 'tool_call') {
if (!responseItem.toolCalls)
responseItem.toolCalls = []
responseItem.toolCalls?.push({
tool_call_id,
tool_name,
tool_arguments,
tool_files,
tool_error,
tool_elapsed_time,
})
}
if (chunk_type === 'tool_result') {
const currentToolCallIndex = responseItem.toolCalls?.findIndex(item => item.tool_call_id === tool_call_id) ?? -1
if (currentToolCallIndex > -1)
responseItem.toolCalls![currentToolCallIndex].tool_output = message
}
if (chunk_type === 'thought_start') {
responseItem.toolCalls?.push({
is_thought: true,
tool_elapsed_time,
})
}
if (chunk_type === 'thought') {
const currentThoughtIndex = responseItem.toolCalls?.findIndex(item => item.is_thought) ?? -1
if (currentThoughtIndex > -1)
responseItem.toolCalls![currentThoughtIndex].tool_output = message
}
if (messageId && !hasSetResponseId) {
questionItem.id = `question-${messageId}`
responseItem.id = messageId