Has anyone managed to get a tool_call working when stream=True?

I think I’ve solved my issue, I was looping through each tool call, the error was only seen when I had more than 1 tool call.

I was returning the openai.chat.completions.create call inside of the for loop and not outside of it, causing the second tool call to be completed ommited.

I still see the following error though:

message: ‘An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_O99wyVF6KhPoswftxi6o0DHB’,
type: ‘invalid_request_error’,
param: ‘messages.[11].role’,
code: null

it seems like the param is different now: ‘messages.[11].role’

what reason could that be?

I was concatening each message from each tool, but actually the concatenation only needs to occur once at the very end.

This works really well for me with minimal fuss.

        .on('event', async (event) => {
            // console.log(event.event + '\n');
            if (event.event === 'thread.run.requires_action') {
                // const functionToExecute = event.data.required_action.submit_tool_outputs.tool_calls["0"].function;
                const toolCallsToExecute = event.data.required_action.submit_tool_outputs.tool_calls;

I don’t need to do any parsing. The trick seems to be to listen to all events and then capture the one you need since, for whatever reason, calling on('requires_action') doesn’t seem to work.