diff --git a/core/llm/llm.test.ts b/core/llm/llm.test.ts index f3afd4c4b..420a40240 100644 --- a/core/llm/llm.test.ts +++ b/core/llm/llm.test.ts @@ -145,6 +145,7 @@ function testLLM( description: "Say Hello", parameters: { type: "object", + required: ["name"], properties: { name: { type: "string", @@ -165,7 +166,7 @@ function testLLM( }, )) { const typedChunk = chunk as AssistantChatMessage; - if (!typedChunk.toolCalls) { + if (!typedChunk.toolCalls || typedChunk.toolCalls.length === 0) { continue; } const toolCall = typedChunk.toolCalls[0]; diff --git a/core/llm/openaiTypeConverters.ts b/core/llm/openaiTypeConverters.ts index 4bc674066..1a8629708 100644 --- a/core/llm/openaiTypeConverters.ts +++ b/core/llm/openaiTypeConverters.ts @@ -190,24 +190,20 @@ export function fromChatCompletionChunk( content: delta.content, }; } else if (delta?.tool_calls) { - const toolCalls = delta?.tool_calls - .filter((tool_call) => tool_call.type === "function") - .map((tool_call) => ({ - id: tool_call.id, - type: "function" as const, - function: { - name: (tool_call as any).function?.name, - arguments: (tool_call as any).function?.arguments, - }, - })); - - if (toolCalls.length > 0) { - return { - role: "assistant", - content: "", - toolCalls, - }; - } + return { + role: "assistant", + content: "", + toolCalls: delta?.tool_calls + .filter((tool_call) => !tool_call.type || tool_call.type === "function") + .map((tool_call) => ({ + id: tool_call.id, + type: "function" as const, + function: { + name: (tool_call as any).function?.name, + arguments: (tool_call as any).function?.arguments, + }, + })), + }; } return undefined; diff --git a/packages/openai-adapters/src/apis/Azure.ts b/packages/openai-adapters/src/apis/Azure.ts index d9cf9ddc9..4d161c843 100644 --- a/packages/openai-adapters/src/apis/Azure.ts +++ b/packages/openai-adapters/src/apis/Azure.ts @@ -19,7 +19,7 @@ export class AzureApi extends OpenAIApi { const { baseURL, defaultQuery } = this._getAzureBaseURL(azureConfig); this.openai = new OpenAI({ - apiKey: azureConfig.apiKey ?? "", + apiKey: azureConfig.apiKey, baseURL, fetch: customFetch(azureConfig.requestOptions), defaultQuery,