Now I am struggling how to implement function calling in streaming assistant run in my NestJS project. As you know, The example code is like this.
https://platform.openai.com/docs/assistants/overview?context=with-streaming
const run = openai.beta.threads.runs.createAndStream(thread.id, {
assistant_id: assistant.id
})
.on('textCreated', (text) => process.stdout.write('\nassistant > '))
.on('textDelta', (textDelta, snapshot) => process.stdout.write(textDelta.value))
.on('toolCallCreated', (toolCall) => process.stdout.write(`\nassistant > ${toolCall.type}\n\n`))
.on('toolCallDelta', (toolCallDelta, snapshot) => {
if (toolCallDelta.type === 'code_interpreter') {
if (toolCallDelta.code_interpreter.input) {
process.stdout.write(toolCallDelta.code_interpreter.input);
}
if (toolCallDelta.code_interpreter.outputs) {
process.stdout.write("\noutput >\n");
toolCallDelta.code_interpreter.outputs.forEach(output => {
if (output.type === "logs") {
process.stdout.write(`\n${output.logs}\n`);
}
});
}
}
});
It was able to get streaming working for regular text responses, but now I’m stuck on function calling. I would like to know about event handler of nodejs SDK for OpenAI. Is there anyone to know about that? especially function calling of streaming assistant?
The function called will just be a name and some arguments as defined in your Assistant. You need to manually handle the function by checking the name and arguments like this:
psuedo code adaption for typescript