mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-13 14:29:40 +00:00
fix: agent call stop sign
This commit is contained in:
@@ -72,17 +72,6 @@ export const runAgentCall = async ({
|
||||
|
||||
let requestMessages = messages;
|
||||
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
{
|
||||
messages: requestMessages,
|
||||
tools: subApps
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
|
||||
let inputTokens: number = 0;
|
||||
let outputTokens: number = 0;
|
||||
const subAppUsages: ChatNodeUsageType[] = [];
|
||||
@@ -95,6 +84,7 @@ export const runAgentCall = async ({
|
||||
|
||||
// TODO: Context agent compression
|
||||
|
||||
// console.log(JSON.stringify(requestMessages, null, 2));
|
||||
// Request LLM
|
||||
let {
|
||||
reasoningText: reasoningContent,
|
||||
@@ -153,13 +143,16 @@ export const runAgentCall = async ({
|
||||
messages: requestMessages.slice(requestMessagesLength),
|
||||
getToolInfo
|
||||
})[0] as AIChatItemType;
|
||||
assistantResponses.push(...currentAssistantResponses.value);
|
||||
|
||||
if (currentAssistantResponses) {
|
||||
assistantResponses.push(...currentAssistantResponses.value);
|
||||
}
|
||||
|
||||
// Usage concat
|
||||
inputTokens += usage.inputTokens;
|
||||
outputTokens += usage.outputTokens;
|
||||
|
||||
if (isEndSign) {
|
||||
if (isEndSign || toolCalls.length === 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ import json5 from 'json5';
|
||||
import type { ChatCompletionTool } from '@fastgpt/global/core/ai/type';
|
||||
import type { ToolNodeItemType } from './type';
|
||||
import { textAdaptGptResponse } from '@fastgpt/global/core/workflow/runtime/utils';
|
||||
import { sliceStrStartEnd } from '@fastgpt/global/common/string/tools';
|
||||
|
||||
export type DispatchAgentModuleProps = ModuleDispatchProps<{
|
||||
[NodeInputKeyEnum.history]?: ChatItemType[];
|
||||
@@ -193,10 +194,25 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise
|
||||
isToolCall: true
|
||||
});
|
||||
dispatchFlowResponse.push(...flowResponses);
|
||||
|
||||
const response = formatToolResponse(toolResponses);
|
||||
workflowStreamResponse?.({
|
||||
event: SseResponseEventEnum.toolResponse,
|
||||
data: {
|
||||
tool: {
|
||||
id: call.id,
|
||||
toolName: '',
|
||||
toolAvatar: '',
|
||||
params: '',
|
||||
response: sliceStrStartEnd(response, 5000, 5000)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: 推送账单
|
||||
|
||||
return {
|
||||
response: formatToolResponse(toolResponses),
|
||||
response,
|
||||
usages: flowUsages,
|
||||
isEnd: false
|
||||
};
|
||||
|
Reference in New Issue
Block a user