perf: workflow code (#5548)

* perf: workflow code

* add tool call limit
This commit is contained in:
Archer
2025-08-27 11:45:46 +08:00
committed by GitHub
parent 610634e1a1
commit c4799df3fd
11 changed files with 133 additions and 118 deletions
@@ -66,11 +66,12 @@ export const promptToolCallMessageRewrite = (
return cloneMessages;
};
const ERROR_TEXT = 'Tool run error';
const ERROR_TEXT = 'Tool call error';
export const parsePromptToolCall = (
str: string
): {
answer: string;
streamAnswer?: string;
toolCalls?: ChatCompletionMessageToolCall[];
} => {
str = str.trim();
@@ -99,11 +100,13 @@ export const parsePromptToolCall = (
} catch (error) {
if (prefixReg.test(str)) {
return {
answer: ERROR_TEXT
answer: `${ERROR_TEXT}: ${str}`,
streamAnswer: `${ERROR_TEXT}: ${str}`
};
} else {
return {
answer: str
answer: str,
streamAnswer: str
};
}
}
+5 -1
View File
@@ -324,7 +324,11 @@ export const createStreamResponse = async ({
}
const { reasoningContent, content, finish_reason, usage } = getResponseData();
const { answer: llmAnswer, toolCalls } = parsePromptToolCall(content);
const { answer: llmAnswer, streamAnswer, toolCalls } = parsePromptToolCall(content);
if (streamAnswer) {
onStreaming?.({ text: streamAnswer });
}
toolCalls?.forEach((call) => {
onToolCall?.({ call });