mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-09-21 00:02:30 +00:00
fix: Ai Chat: do not send tools if empty + respond even if tool fails (#5692)
* do not send tools if empty * respond to user request even if tool call fails * remove test line * add missing await
This commit is contained in:
@@ -487,6 +487,31 @@ async function callTool(
|
||||
}
|
||||
}
|
||||
|
||||
async function processToolCall(
|
||||
toolCall: ChatCompletionMessageToolCall,
|
||||
messages: ChatCompletionMessageParam[],
|
||||
lang: ScriptLang | 'bunnative'
|
||||
) {
|
||||
try {
|
||||
const args = JSON.parse(toolCall.function.arguments)
|
||||
let result = ''
|
||||
try {
|
||||
result = await callTool(toolCall.function.name, args, lang, get(workspaceStore) ?? '')
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
result =
|
||||
'Error while calling tool, MUST tell the user to check the browser console for more details, and then respond as much as possible to the original request'
|
||||
}
|
||||
messages.push({
|
||||
role: 'tool',
|
||||
tool_call_id: toolCall.id,
|
||||
content: result
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
export async function chatRequest(
|
||||
messages: ChatCompletionMessageParam[],
|
||||
abortController: AbortController,
|
||||
@@ -554,23 +579,7 @@ export async function chatRequest(
|
||||
tool_calls: toolCalls
|
||||
})
|
||||
for (const toolCall of toolCalls) {
|
||||
try {
|
||||
const args = JSON.parse(toolCall.function.arguments)
|
||||
const result = await callTool(
|
||||
toolCall.function.name,
|
||||
args,
|
||||
lang,
|
||||
get(workspaceStore) ?? ''
|
||||
)
|
||||
messages.push({
|
||||
role: 'tool',
|
||||
tool_call_id: toolCall.id,
|
||||
content: result
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw new Error('Error while calling tool')
|
||||
}
|
||||
await processToolCall(toolCall, messages, lang)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
|
||||
@@ -385,7 +385,7 @@ function getProviderAndCompletionConfig<K extends boolean>({
|
||||
: {
|
||||
model: modelProvider.model,
|
||||
temperature: 0,
|
||||
tools
|
||||
...(tools && tools.length > 0 ? { tools } : {})
|
||||
}),
|
||||
max_tokens: getModelMaxTokens(modelProvider.model),
|
||||
messages: processedMessages,
|
||||
|
||||
Reference in New Issue
Block a user