fix: don't filter when empty type on tool
This commit is contained in:
parent
1612df9be1
commit
e99d472339
3 changed files with 17 additions and 20 deletions
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue