mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 07:03:25 +00:00
fix(ai): tolerate malformed trailing tool-call JSON in OpenAI streams closes #1424
This commit is contained in:
parent
5ddb04f74a
commit
ed0cfcbda2
2 changed files with 3 additions and 3 deletions
|
|
@ -129,7 +129,7 @@ export const streamOpenAICompletions: StreamFunction<"openai-completions", OpenA
|
||||||
partial: output,
|
partial: output,
|
||||||
});
|
});
|
||||||
} else if (block.type === "toolCall") {
|
} else if (block.type === "toolCall") {
|
||||||
block.arguments = JSON.parse(block.partialArgs || "{}");
|
block.arguments = parseStreamingJson(block.partialArgs);
|
||||||
delete block.partialArgs;
|
delete block.partialArgs;
|
||||||
stream.push({
|
stream.push({
|
||||||
type: "toolcall_end",
|
type: "toolcall_end",
|
||||||
|
|
|
||||||
|
|
@ -414,8 +414,8 @@ export async function processResponsesStream<TApi extends Api>(
|
||||||
} else if (item.type === "function_call") {
|
} else if (item.type === "function_call") {
|
||||||
const args =
|
const args =
|
||||||
currentBlock?.type === "toolCall" && currentBlock.partialJson
|
currentBlock?.type === "toolCall" && currentBlock.partialJson
|
||||||
? JSON.parse(currentBlock.partialJson)
|
? parseStreamingJson(currentBlock.partialJson)
|
||||||
: JSON.parse(item.arguments);
|
: parseStreamingJson(item.arguments || "{}");
|
||||||
const toolCall: ToolCall = {
|
const toolCall: ToolCall = {
|
||||||
type: "toolCall",
|
type: "toolCall",
|
||||||
id: `${item.call_id}|${item.id}`,
|
id: `${item.call_id}|${item.id}`,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue