mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 11:02:17 +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,
|
||||
});
|
||||
} else if (block.type === "toolCall") {
|
||||
block.arguments = JSON.parse(block.partialArgs || "{}");
|
||||
block.arguments = parseStreamingJson(block.partialArgs);
|
||||
delete block.partialArgs;
|
||||
stream.push({
|
||||
type: "toolcall_end",
|
||||
|
|
|
|||
|
|
@ -414,8 +414,8 @@ export async function processResponsesStream<TApi extends Api>(
|
|||
} else if (item.type === "function_call") {
|
||||
const args =
|
||||
currentBlock?.type === "toolCall" && currentBlock.partialJson
|
||||
? JSON.parse(currentBlock.partialJson)
|
||||
: JSON.parse(item.arguments);
|
||||
? parseStreamingJson(currentBlock.partialJson)
|
||||
: parseStreamingJson(item.arguments || "{}");
|
||||
const toolCall: ToolCall = {
|
||||
type: "toolCall",
|
||||
id: `${item.call_id}|${item.id}`,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue