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

View File

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