mirror of
https://github.com/labring/FastGPT.git
synced 2026-02-02 01:08:26 +08:00
feat: system prompt parse
This commit is contained in:
@@ -25,7 +25,7 @@ import { getSubApps, rewriteSubAppsToolset } from './sub';
|
||||
|
||||
import { getFileInputPrompt } from './sub/file/utils';
|
||||
import type { ChatCompletionMessageParam } from '@fastgpt/global/core/ai/type';
|
||||
import type { AgentPlanStepType, AgentPlanType } from './sub/plan/type';
|
||||
import type { AgentPlanType } from './sub/plan/type';
|
||||
import type { localeType } from '@fastgpt/global/common/i18n/type';
|
||||
import { stepCall } from './master/call';
|
||||
import type { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
|
||||
@@ -156,6 +156,7 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise
|
||||
interactive: lastInteractive,
|
||||
subAppList,
|
||||
getSubAppInfo,
|
||||
systemPrompt,
|
||||
model,
|
||||
temperature,
|
||||
top_p: aiChatTopP,
|
||||
@@ -215,6 +216,7 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise
|
||||
interactive: lastInteractive,
|
||||
subAppList,
|
||||
getSubAppInfo,
|
||||
systemPrompt,
|
||||
model,
|
||||
temperature,
|
||||
top_p: aiChatTopP,
|
||||
@@ -279,6 +281,14 @@ export const dispatchRunAgent = async (props: DispatchAgentModuleProps): Promise
|
||||
const steps = agentPlan?.steps!.filter((item) => !item.response)!;
|
||||
for await (const step of steps) {
|
||||
addLog.debug(`Step call: ${step.id}`, step);
|
||||
|
||||
workflowStreamResponse?.({
|
||||
event: SseResponseEventEnum.answer,
|
||||
data: textAdaptGptResponse({
|
||||
text: `# 步骤: ${step.title}\n`
|
||||
})
|
||||
});
|
||||
|
||||
const result = await stepCall({
|
||||
...props,
|
||||
getSubAppInfo,
|
||||
|
||||
@@ -126,7 +126,10 @@ export const stepCall = async ({
|
||||
],
|
||||
reserveId: false
|
||||
});
|
||||
// console.log('Step call requestMessages', JSON.stringify(requestMessages, null, 2));
|
||||
console.log(
|
||||
'Step call requestMessages',
|
||||
JSON.stringify({ requestMessages, subAppList }, null, 2)
|
||||
);
|
||||
const { assistantResponses, inputTokens, outputTokens, subAppUsages, interactiveResponse } =
|
||||
await runAgentCall({
|
||||
maxRunAgentTimes: 100,
|
||||
|
||||
@@ -23,6 +23,7 @@ import type { GetSubAppInfoFnType } from '../../type';
|
||||
import { getStepDependon } from '../../common/dependon';
|
||||
|
||||
type PlanAgentConfig = {
|
||||
systemPrompt?: string;
|
||||
model: string;
|
||||
temperature?: number;
|
||||
top_p?: number;
|
||||
@@ -55,6 +56,7 @@ export const dispatchPlanAgent = async ({
|
||||
interactive,
|
||||
subAppList,
|
||||
getSubAppInfo,
|
||||
systemPrompt,
|
||||
model,
|
||||
temperature,
|
||||
top_p,
|
||||
@@ -68,7 +70,8 @@ export const dispatchPlanAgent = async ({
|
||||
role: 'system',
|
||||
content: getPlanAgentSystemPrompt({
|
||||
getSubAppInfo,
|
||||
subAppList
|
||||
subAppList,
|
||||
systemPrompt
|
||||
})
|
||||
},
|
||||
...historyMessages
|
||||
@@ -99,7 +102,7 @@ export const dispatchPlanAgent = async ({
|
||||
{ requestMessages, tools: isTopPlanAgent ? [PlanAgentAskTool] : [] },
|
||||
{ depth: null }
|
||||
);
|
||||
const {
|
||||
let {
|
||||
answerText,
|
||||
toolCalls = [],
|
||||
usage,
|
||||
@@ -142,6 +145,9 @@ export const dispatchPlanAgent = async ({
|
||||
}
|
||||
return params;
|
||||
})();
|
||||
if (plan) {
|
||||
answerText = '';
|
||||
}
|
||||
|
||||
// 只有顶层有交互模式
|
||||
const interactiveResponse: InteractiveNodeResponseType | undefined = (() => {
|
||||
@@ -264,7 +270,7 @@ export const dispatchReplanAgent = async ({
|
||||
}
|
||||
|
||||
console.log('Replan call messages', JSON.stringify(requestMessages, null, 2));
|
||||
const {
|
||||
let {
|
||||
answerText,
|
||||
toolCalls = [],
|
||||
usage,
|
||||
@@ -307,6 +313,9 @@ export const dispatchReplanAgent = async ({
|
||||
}
|
||||
return params;
|
||||
})();
|
||||
if (rePlan) {
|
||||
answerText = '';
|
||||
}
|
||||
|
||||
// 只有顶层有交互模式
|
||||
const interactiveResponse: InteractiveNodeResponseType | undefined = (() => {
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { ChatCompletionTool } from '@fastgpt/global/core/ai/type';
|
||||
import { SubAppIds } from '../constants';
|
||||
import type { GetSubAppInfoFnType } from '../../type';
|
||||
import type { AgentPlanStepType } from './type';
|
||||
import { parseSystemPrompt } from '../../utils';
|
||||
|
||||
const getSubAppPrompt = ({
|
||||
getSubAppInfo,
|
||||
@@ -22,13 +23,16 @@ const getSubAppPrompt = ({
|
||||
|
||||
export const getPlanAgentSystemPrompt = ({
|
||||
getSubAppInfo,
|
||||
subAppList
|
||||
subAppList,
|
||||
systemPrompt
|
||||
}: {
|
||||
getSubAppInfo: GetSubAppInfoFnType;
|
||||
subAppList: ChatCompletionTool[];
|
||||
systemPrompt?: string;
|
||||
}) => {
|
||||
const userSystemPrompt = parseSystemPrompt({ systemPrompt, getSubAppInfo });
|
||||
const subAppPrompt = getSubAppPrompt({ getSubAppInfo, subAppList });
|
||||
|
||||
console.log(userSystemPrompt);
|
||||
return `
|
||||
<role>
|
||||
你是一个专业的主题计划构建专家,擅长将复杂的主题学习和探索过程转化为结构清晰、可执行的渐进式学习路径。你的规划方法强调:
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
匹配 {{@toolId@}},转化成: @name 的格式。
|
||||
*/
|
||||
export const parseAgentSystemPrompt = ({
|
||||
export const parseSystemPrompt = ({
|
||||
systemPrompt,
|
||||
getSubAppInfo
|
||||
}: {
|
||||
systemPrompt: string;
|
||||
systemPrompt?: string;
|
||||
getSubAppInfo: (id: string) => {
|
||||
name: string;
|
||||
avatar: string;
|
||||
|
||||
Reference in New Issue
Block a user