fix prettifier

This commit is contained in:
Dark Sun
2024-02-19 16:49:43 +05:00
parent fbfa9922e0
commit c8926c4691
+8 -7
View File
@@ -4,7 +4,6 @@ import type { Model } from './types.js';
import { calculateCost } from './utils/calculate-cost.js';
import { createOpenAIClient } from './clients/openai.js';
import { AbstractModel } from './model.js';
import { deepMerge } from '../utils/helpers.js';
export type ChatModelArgs = SetOptional<
ModelArgs<
@@ -124,13 +123,15 @@ export class ChatModel extends AbstractModel<
const mergedToolCalls = chunk.choices[0].delta.tool_calls || [];
tool_calls.forEach((new_call) => {
const index = new_call.index;
let existing_call = mergedToolCalls.find(call => call.index === index);
if (new_call.function && typeof new_call.function.arguments === 'string') {
const index = new_call.index;
let existing_call = mergedToolCalls.find(call => call.index === index);
if (existing_call) {
existing_call.function.arguments += new_call.function.arguments;
} else {
mergedToolCalls.push(new_call);
if (existing_call && existing_call.function) {
existing_call.function.arguments = (existing_call.function.arguments || '') + new_call.function.arguments;
} else {
mergedToolCalls.push({...new_call, function: { ...new_call.function } });
}
}
});