hello i try to implement tool call with the Streaming option for the Assistant. but ran into a problem:
gptConversation['main_run'] = openai.beta.threads.runs.createAndStream(gptConversation['main_thread'].id, {
assistant_id: gptConversation['main_assistant'].id
})
.on('textCreated', (text) => console.log(text))
.on('textDelta', (textDelta, snapshot) => {
saveConversation(gptConversation, textDelta.value)
console.log(textDelta)
console.log(snapshot)
let gptC = []
gptC.push(gptConversation)
let body = {
jsonData: {
type: "update",
query: {
gptConversation: gptC
}
}
}
let token = authService.getBearer()
BackendService.post(url, body, false, token).then((res) => {
}, (error) => {
console.log("Backend Post failed", error)
})
})
.on('toolCallCreated', (toolCall) => {
toolCallId = toolCall.id;
functionName = toolCall.function.name;
})
.on('toolCallDelta', (toolCallDelta, snapshot) => {
toolCallArgs += toolCallDelta.function.arguments;
const completeArgs = checkToolCallArgsComplete(toolCallArgs);
if (completeArgs !== "") {
console.log("toolCallId", toolCallId)
console.log("functionName", functionName)
console.log("completeArgs", completeArgs)
let functionResponse = JSON.stringify( aiFunctions[functionName](gptConversation,completeArgs));
saveConversation(gptConversation, toolCallDelta)
let gptC = []
gptC.push(gptConversation)
let body = {
jsonData: {
type: "update",
query: {
gptConversation: gptC
}
}
}
let token = authService.getBearer()
BackendService.post(url, body, false, token).then((res) => {
}, (error) => {
console.log("Backend Post failed", error)
})
try {
const run = openai.beta.threads.runs.submitToolOutputs(
gptConversation['main_thread'].id,
gptConversation['main_run'].id,
{
tool_outputs: [
{
tool_call_id: toolCallId,
output: functionResponse,
},
],
}
);
} catch (e) {
console.log("Run error", e)
}
}
})
the error i get is
" message: “Can’t add messages to THREAD_ID while a run RUN_ID is active.”,"
i have no idea how to submitt the tool output and the next problem is i dont get any text answer like “Tht sounds nice etc etc”
if a toolcall is happening no other output will be provided , i try now to figure out sience over 4 Days and slowly it goes expensive for me xD