ai
ai copied to clipboard
Inconsistence tools call response with Azure Openai API
Description
When using Azure openai package for tools function calls there is incorrect response in the tools call response type which Azure openai is not exactly the same as openai response, not sure if this should be handled in this ai package but will be good to flag this bug.
The issue will cause the response invalid to Azure Openai API calls as the response in the OpenAIStream is using "tool_call_id" while Azure API is expecting "toolCallId"
Will this inconsistence will be handled?
Code example
OpenAIStream response using "tool_call_id"
// https://github.com/vercel/ai/blob/main/packages/core/streams/openai-stream.ts#L640
// Append the function call result message
{
role: 'tool',
tool_call_id,
name: function_name,
content: JSON.stringify(tool_call_result),
},
But Azure is using "toolCallId" in their client
// Purely for convenience and clarity, this function handles tool call responses.
function applyToolCall({ function: call, id }) {
if (call.name === "get_current_weather") {
const { location, unit } = JSON.parse(call.arguments);
// In a real application, this would be a call to a weather API with location and unit parameters
return {
role: "tool",
content: `The weather in ${location} is 72 degrees ${unit} and sunny.`,
toolCallId: id,
}
}
throw new Error(`Unknown tool call: ${call.name}`);
}
Additional context
No response
Also ran into this. Workaround is to manually pass both tool_call_id
and toolCallId
to my message object. Would be great if this wouldn't be necessary in the future 👍
Also got error Missing parameter 'tool_call_id': messages with role 'tool' must have a 'tool_call_id'.
when run with Azure OpenAI Service.
@toonverbeek Can you provide your workaround? I tried to pass toolCallId
but still does not work:
appendToolCallMessage({
// tool_call_id: toolCall.id,
// @ts-ignore
toolCallId: toolCall.id,
function_name: 'search',
tool_call_result: result,
})
@gouku it's not in the appendToolCallMessage
where you need to pass it, but when you're returning the messages from the tool:
const finalMessages = [
...messages.map((message) => ({
content: message.content,
role: message.role,
})),
...newMessages.map((message) => ({
...message,
content: message.content,
role: message.role as any,
// azureOpenaI generates pascal case keys, but vercel ai expects snake_case
toolCallId: message.tool_call_id,
})),
];
return client.streamChatCompletions(finalMessages);
Superseeded by #1675