perf: plugin support files (#2708)

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

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
})
};
};