Comparing version 3.12.1 to 3.12.2
@@ -152,3 +152,3 @@ 'use strict'; | ||
var version = "3.12.1"; | ||
var version = "3.12.2"; | ||
@@ -322,12 +322,30 @@ class Langfuse extends langfuseCore.LangfuseCore { | ||
const parseChunk = rawChunk => { | ||
let isToolCall = false; | ||
const _chunk = rawChunk; | ||
const chunkData = _chunk?.choices[0]; | ||
try { | ||
if ("delta" in _chunk?.choices[0]) { | ||
return _chunk.choices[0].delta?.content || ""; | ||
if ("delta" in chunkData && "tool_calls" in chunkData.delta && Array.isArray(chunkData.delta.tool_calls)) { | ||
isToolCall = true; | ||
return { | ||
isToolCall, | ||
data: chunkData.delta.tool_calls[0] | ||
}; | ||
} | ||
if ("text" in _chunk?.choices[0]) { | ||
return _chunk?.choices[0].text || ""; | ||
if ("delta" in chunkData) { | ||
return { | ||
isToolCall, | ||
data: chunkData.delta?.content || "" | ||
}; | ||
} | ||
if ("text" in chunkData) { | ||
return { | ||
isToolCall, | ||
data: chunkData.text || "" | ||
}; | ||
} | ||
} catch (e) {} | ||
return ""; | ||
return { | ||
isToolCall: false, | ||
data: "" | ||
}; | ||
}; | ||
@@ -338,2 +356,18 @@ // Type guard to check if an unknown object is a UsageResponse | ||
} | ||
const getToolCallOutput = toolCallChunks => { | ||
let name = ""; | ||
let toolArguments = ""; | ||
for (const toolCall of toolCallChunks) { | ||
name = toolCall.function?.name || name; | ||
toolArguments += toolCall.function?.arguments || ""; | ||
} | ||
return { | ||
tool_calls: [{ | ||
function: { | ||
name, | ||
arguments: toolArguments | ||
} | ||
}] | ||
}; | ||
}; | ||
@@ -386,3 +420,4 @@ const isAsyncIterable = x => x != null && typeof x === "object" && typeof x[Symbol.asyncIterator] === "function"; | ||
const response = res; | ||
const processedChunks = []; | ||
const textChunks = []; | ||
const toolCallChunks = []; | ||
let completionStartTime = null; | ||
@@ -392,6 +427,10 @@ for await (const rawChunk of response) { | ||
const processedChunk = parseChunk(rawChunk); | ||
processedChunks.push(processedChunk); | ||
if (!processedChunk.isToolCall) { | ||
textChunks.push(processedChunk.data); | ||
} else { | ||
toolCallChunks.push(processedChunk.data); | ||
} | ||
yield rawChunk; | ||
} | ||
const output = processedChunks.join(""); | ||
const output = toolCallChunks.length > 0 ? getToolCallOutput(toolCallChunks) : textChunks.join(""); | ||
langfuseParent.generation({ | ||
@@ -398,0 +437,0 @@ ...observationData, |
{ | ||
"name": "langfuse", | ||
"version": "3.12.1", | ||
"version": "3.12.2", | ||
"engines": { | ||
@@ -35,5 +35,5 @@ "node": ">=18" | ||
"dependencies": { | ||
"langfuse-core": "^3.12.1" | ||
"langfuse-core": "^3.12.2" | ||
}, | ||
"gitHead": "88a86c82399726afd6b67badd4930fd8a458d776", | ||
"gitHead": "ec20d8fbdd5dceee9dbca5ce125f789ef8caa7e8", | ||
"devDependencies": { | ||
@@ -40,0 +40,0 @@ "typedoc": "^0.25.13" |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
124714
1144
4
Updatedlangfuse-core@^3.12.2