Comparing version 0.6.4 to 0.6.5
42
index.js
@@ -46,3 +46,24 @@ var __defProp = Object.defineProperty; | ||
if (base === null) { | ||
return mergeChunks({ ...chunk, object: "chat.completion", choices: [] }, chunk); | ||
return mergeChunks( | ||
{ ...chunk, object: "chat.completion", choices: [] }, | ||
// Prevent function call and tool call arguments from being double-merged | ||
{ | ||
...chunk, | ||
choices: chunk.choices.map((c) => ({ | ||
...c, | ||
delta: { | ||
...c.delta, | ||
function_call: { | ||
...c.delta.function_call | ||
}, | ||
tool_calls: c.delta.tool_calls?.map((tc) => ({ | ||
...tc, | ||
function: { | ||
...tc.function | ||
} | ||
})) | ||
} | ||
})) | ||
} | ||
); | ||
} | ||
@@ -65,2 +86,18 @@ const choices = [...base.choices]; | ||
} | ||
if (choice.delta?.tool_calls) { | ||
const toolCalls = baseChoice.message.tool_calls ?? []; | ||
const toolCallDelta = { ...choice.delta.tool_calls[0] }; | ||
if (toolCallDelta?.function?.name) { | ||
toolCalls.push({ | ||
id: toolCallDelta.id, | ||
type: "function", | ||
function: { | ||
name: toolCallDelta.function.name ?? "", | ||
arguments: toolCallDelta.function.arguments ?? "" | ||
} | ||
}); | ||
} else if (toolCalls[toolCalls.length - 1] && toolCallDelta) { | ||
toolCalls[toolCalls.length - 1].function.arguments += toolCallDelta.function?.arguments ?? ""; | ||
} | ||
} | ||
} else { | ||
@@ -570,3 +607,3 @@ choices.push({ ...omit(choice, "delta"), message: { role: "assistant", ...choice.delta } }); | ||
name: "openpipe-dev", | ||
version: "0.6.4", | ||
version: "0.6.5", | ||
type: "module", | ||
@@ -614,3 +651,2 @@ description: "LLM metrics and inference", | ||
"@rollup/plugin-node-resolve": "^15.2.1", | ||
"@types/lodash-es": "^4.17.8", | ||
"@types/node": "^20.4.8", | ||
@@ -617,0 +653,0 @@ "@types/node-fetch": "^2.6.4", |
@@ -268,3 +268,3 @@ import * as openai$1 from 'openai'; | ||
}; | ||
}>; | ||
} | null>; | ||
/** | ||
@@ -271,0 +271,0 @@ * Report an API call |
@@ -37,3 +37,24 @@ var __accessCheck = (obj, member, msg) => { | ||
if (base === null) { | ||
return mergeChunks({ ...chunk, object: "chat.completion", choices: [] }, chunk); | ||
return mergeChunks( | ||
{ ...chunk, object: "chat.completion", choices: [] }, | ||
// Prevent function call and tool call arguments from being double-merged | ||
{ | ||
...chunk, | ||
choices: chunk.choices.map((c) => ({ | ||
...c, | ||
delta: { | ||
...c.delta, | ||
function_call: { | ||
...c.delta.function_call | ||
}, | ||
tool_calls: c.delta.tool_calls?.map((tc) => ({ | ||
...tc, | ||
function: { | ||
...tc.function | ||
} | ||
})) | ||
} | ||
})) | ||
} | ||
); | ||
} | ||
@@ -56,2 +77,18 @@ const choices = [...base.choices]; | ||
} | ||
if (choice.delta?.tool_calls) { | ||
const toolCalls = baseChoice.message.tool_calls ?? []; | ||
const toolCallDelta = { ...choice.delta.tool_calls[0] }; | ||
if (toolCallDelta?.function?.name) { | ||
toolCalls.push({ | ||
id: toolCallDelta.id, | ||
type: "function", | ||
function: { | ||
name: toolCallDelta.function.name ?? "", | ||
arguments: toolCallDelta.function.arguments ?? "" | ||
} | ||
}); | ||
} else if (toolCalls[toolCalls.length - 1] && toolCallDelta) { | ||
toolCalls[toolCalls.length - 1].function.arguments += toolCallDelta.function?.arguments ?? ""; | ||
} | ||
} | ||
} else { | ||
@@ -561,3 +598,3 @@ choices.push({ ...omit(choice, "delta"), message: { role: "assistant", ...choice.delta } }); | ||
name: "openpipe-dev", | ||
version: "0.6.4", | ||
version: "0.6.5", | ||
type: "module", | ||
@@ -605,3 +642,2 @@ description: "LLM metrics and inference", | ||
"@rollup/plugin-node-resolve": "^15.2.1", | ||
"@types/lodash-es": "^4.17.8", | ||
"@types/node": "^20.4.8", | ||
@@ -608,0 +644,0 @@ "@types/node-fetch": "^2.6.4", |
@@ -11,3 +11,24 @@ // src/openai/mergeChunks.ts | ||
if (base === null) { | ||
return mergeChunks({ ...chunk, object: "chat.completion", choices: [] }, chunk); | ||
return mergeChunks( | ||
{ ...chunk, object: "chat.completion", choices: [] }, | ||
// Prevent function call and tool call arguments from being double-merged | ||
{ | ||
...chunk, | ||
choices: chunk.choices.map((c) => ({ | ||
...c, | ||
delta: { | ||
...c.delta, | ||
function_call: { | ||
...c.delta.function_call | ||
}, | ||
tool_calls: c.delta.tool_calls?.map((tc) => ({ | ||
...tc, | ||
function: { | ||
...tc.function | ||
} | ||
})) | ||
} | ||
})) | ||
} | ||
); | ||
} | ||
@@ -30,2 +51,18 @@ const choices = [...base.choices]; | ||
} | ||
if (choice.delta?.tool_calls) { | ||
const toolCalls = baseChoice.message.tool_calls ?? []; | ||
const toolCallDelta = { ...choice.delta.tool_calls[0] }; | ||
if (toolCallDelta?.function?.name) { | ||
toolCalls.push({ | ||
id: toolCallDelta.id, | ||
type: "function", | ||
function: { | ||
name: toolCallDelta.function.name ?? "", | ||
arguments: toolCallDelta.function.arguments ?? "" | ||
} | ||
}); | ||
} else if (toolCalls[toolCalls.length - 1] && toolCallDelta) { | ||
toolCalls[toolCalls.length - 1].function.arguments += toolCallDelta.function?.arguments ?? ""; | ||
} | ||
} | ||
} else { | ||
@@ -32,0 +69,0 @@ choices.push({ ...omit(choice, "delta"), message: { role: "assistant", ...choice.delta } }); |
@@ -14,3 +14,24 @@ // src/openai/streaming.ts | ||
if (base === null) { | ||
return mergeChunks({ ...chunk, object: "chat.completion", choices: [] }, chunk); | ||
return mergeChunks( | ||
{ ...chunk, object: "chat.completion", choices: [] }, | ||
// Prevent function call and tool call arguments from being double-merged | ||
{ | ||
...chunk, | ||
choices: chunk.choices.map((c) => ({ | ||
...c, | ||
delta: { | ||
...c.delta, | ||
function_call: { | ||
...c.delta.function_call | ||
}, | ||
tool_calls: c.delta.tool_calls?.map((tc) => ({ | ||
...tc, | ||
function: { | ||
...tc.function | ||
} | ||
})) | ||
} | ||
})) | ||
} | ||
); | ||
} | ||
@@ -33,2 +54,18 @@ const choices = [...base.choices]; | ||
} | ||
if (choice.delta?.tool_calls) { | ||
const toolCalls = baseChoice.message.tool_calls ?? []; | ||
const toolCallDelta = { ...choice.delta.tool_calls[0] }; | ||
if (toolCallDelta?.function?.name) { | ||
toolCalls.push({ | ||
id: toolCallDelta.id, | ||
type: "function", | ||
function: { | ||
name: toolCallDelta.function.name ?? "", | ||
arguments: toolCallDelta.function.arguments ?? "" | ||
} | ||
}); | ||
} else if (toolCalls[toolCalls.length - 1] && toolCallDelta) { | ||
toolCalls[toolCalls.length - 1].function.arguments += toolCallDelta.function?.arguments ?? ""; | ||
} | ||
} | ||
} else { | ||
@@ -35,0 +72,0 @@ choices.push({ ...omit(choice, "delta"), message: { role: "assistant", ...choice.delta } }); |
{ | ||
"name": "openpipe", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"type": "module", | ||
@@ -24,3 +24,2 @@ "description": "LLM metrics and inference", | ||
"@rollup/plugin-node-resolve": "^15.2.1", | ||
"@types/lodash-es": "^4.17.8", | ||
"@types/node": "^20.4.8", | ||
@@ -27,0 +26,0 @@ "@types/node-fetch": "^2.6.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
408283
12
4028