perf: plugin support files (#2708)

This commit is contained in:
Archer
2024-09-14 15:11:44 +08:00
committed by GitHub
parent 092bb9ab17
commit d0e8f7203c
3 changed files with 30 additions and 19 deletions

View File

@@ -14,6 +14,7 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import { computedPluginUsage } from '../../../app/plugin/utils'; import { computedPluginUsage } from '../../../app/plugin/utils';
import { filterSystemVariables } from '../utils'; import { filterSystemVariables } from '../utils';
import { getPluginRunUserQuery } from '../../utils'; import { getPluginRunUserQuery } from '../../utils';
import { chatValue2RuntimePrompt } from '@fastgpt/global/core/chat/adapt';
type RunPluginProps = ModuleDispatchProps<{ type RunPluginProps = ModuleDispatchProps<{
[key: string]: any; [key: string]: any;
@@ -25,6 +26,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
node: { pluginId }, node: { pluginId },
runningAppInfo, runningAppInfo,
mode, mode,
query,
params: data // Plugin input params: data // Plugin input
} = props; } = props;
@@ -32,6 +34,8 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
return Promise.reject('pluginId can not find'); return Promise.reject('pluginId can not find');
} }
const { files } = chatValue2RuntimePrompt(query);
// auth plugin // auth plugin
const pluginData = await authPluginByTmbId({ const pluginData = await authPluginByTmbId({
appId: pluginId, appId: pluginId,
@@ -74,7 +78,11 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
tmbId: pluginData?.tmbId || '' tmbId: pluginData?.tmbId || ''
}, },
variables: runtimeVariables, variables: runtimeVariables,
query: getPluginRunUserQuery(plugin.nodes, runtimeVariables).value, query: getPluginRunUserQuery({
nodes: plugin.nodes,
variables: runtimeVariables,
files
}).value,
chatConfig: {}, chatConfig: {},
runtimeNodes, runtimeNodes,
runtimeEdges: initWorkflowEdgeStatus(plugin.edges) runtimeEdges: initWorkflowEdgeStatus(plugin.edges)

View File

@@ -1,13 +1,14 @@
import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type'; import { SearchDataResponseItemType } from '@fastgpt/global/core/dataset/type';
import { countPromptTokens } from '../../common/string/tiktoken/index'; import { countPromptTokens } from '../../common/string/tiktoken/index';
import { getNanoid } from '@fastgpt/global/common/string/tools'; import { getNanoid } from '@fastgpt/global/common/string/tools';
import { ChatItemValueTypeEnum, ChatRoleEnum } from '@fastgpt/global/core/chat/constants'; import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import { import {
getPluginInputsFromStoreNodes, getPluginInputsFromStoreNodes,
getPluginRunContent getPluginRunContent
} from '@fastgpt/global/core/app/plugin/utils'; } from '@fastgpt/global/core/app/plugin/utils';
import { StoreNodeItemType } from '@fastgpt/global/core/workflow/type/node'; import { StoreNodeItemType } from '@fastgpt/global/core/workflow/type/node';
import { UserChatItemType } from '@fastgpt/global/core/chat/type'; import { RuntimeUserPromptType, UserChatItemType } from '@fastgpt/global/core/chat/type';
import { runtimePrompt2ChatsValue } from '@fastgpt/global/core/chat/adapt';
/* filter search result */ /* filter search result */
export const filterSearchResultsByMaxChars = async ( export const filterSearchResultsByMaxChars = async (
@@ -33,23 +34,24 @@ export const filterSearchResultsByMaxChars = async (
}; };
/* Get plugin runtime input user query */ /* Get plugin runtime input user query */
export const getPluginRunUserQuery = ( export const getPluginRunUserQuery = ({
nodes: StoreNodeItemType[], nodes,
variables: Record<string, any> variables,
): UserChatItemType & { dataId: string } => { files = []
}: {
nodes: StoreNodeItemType[];
variables: Record<string, any>;
files?: RuntimeUserPromptType['files'];
}): UserChatItemType & { dataId: string } => {
return { return {
dataId: getNanoid(24), dataId: getNanoid(24),
obj: ChatRoleEnum.Human, obj: ChatRoleEnum.Human,
value: [ value: runtimePrompt2ChatsValue({
{ text: getPluginRunContent({
type: ChatItemValueTypeEnum.text, pluginInputs: getPluginInputsFromStoreNodes(nodes),
text: { variables
content: getPluginRunContent({ }),
pluginInputs: getPluginInputsFromStoreNodes(nodes), files
variables })
})
}
}
]
}; };
}; };

View File

@@ -189,7 +189,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
// Get obj=Human history // Get obj=Human history
const userQuestion: UserChatItemType = (() => { const userQuestion: UserChatItemType = (() => {
if (isPlugin) { if (isPlugin) {
return getPluginRunUserQuery(app.modules, variables); // TODOget plugin files from variables
return getPluginRunUserQuery({ nodes: app.modules, variables });
} }
const latestHumanChat = chatMessages.pop() as UserChatItemType | undefined; const latestHumanChat = chatMessages.pop() as UserChatItemType | undefined;