Compare commits

...

4 Commits

Author SHA1 Message Date
博凡
d8f1962ae7 tmp 2025-08-23 20:52:18 +08:00
koalazf.99
409cef0c1d fix ci/cd 2025-08-20 23:38:02 +08:00
koalazf.99
16a1acfea5 Merge branch 'main' into fix/parallel-tool-use 2025-08-20 23:35:18 +08:00
koalazf.99
013459fd69 try fix: parallel tool use 2025-08-20 23:32:08 +08:00

View File

@@ -1249,8 +1249,10 @@ export class OpenAIContentGenerator implements ContentGenerator {
// Handle text content
if (choice.delta?.content) {
if (typeof choice.delta.content === 'string') {
parts.push({ text: choice.delta.content });
}
}
// Handle tool calls - only accumulate during streaming, emit when complete
if (choice.delta?.tool_calls) {
@@ -1269,10 +1271,36 @@ export class OpenAIContentGenerator implements ContentGenerator {
accumulatedCall.id = toolCall.id;
}
if (toolCall.function?.name) {
// If this is a new function name, reset the arguments
if (accumulatedCall.name !== toolCall.function.name) {
accumulatedCall.arguments = '';
}
accumulatedCall.name = toolCall.function.name;
}
if (toolCall.function?.arguments) {
accumulatedCall.arguments += toolCall.function.arguments;
// Check if we already have a complete JSON object
const currentArgs = accumulatedCall.arguments;
const newArgs = toolCall.function.arguments;
// If current arguments already form a complete JSON and new arguments start a new object,
// this indicates a new tool call with the same name
let shouldReset = false;
if (currentArgs && newArgs.trim().startsWith('{')) {
try {
JSON.parse(currentArgs);
// If we can parse current arguments as complete JSON and new args start with {,
// this is likely a new tool call
shouldReset = true;
} catch {
// Current arguments are not complete JSON, continue accumulating
}
}
if (shouldReset) {
accumulatedCall.arguments = newArgs;
} else {
accumulatedCall.arguments += newArgs;
}
}
}
}
@@ -1768,7 +1796,7 @@ export class OpenAIContentGenerator implements ContentGenerator {
}
}
messageContent = textParts.join('');
messageContent = textParts.join('').trimEnd();
}
const choice: OpenAIChoice = {