System plugin (#2091)
* System template (#2082) * feat: system plugin (#2024) * add plugin cost & change plugin avatar (#2030) * add plugin cost & change plugin avatar * add author * feat: duckduckgo plugin * duckduck search * perf: templates select system plugin * perf: system plugin avatar * feat: duckduck plugins * doc * perf: plugin classify * perf: icon avatar component * perf: system template avatar --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com> * feat: system plugin search * perf: plugin packages important * perf: source avatar * nextconfig * perf: i18n * perf: default model * perf: system plugin author --------- Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
@@ -1,26 +1,55 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import type { NextApiResponse } from 'next';
|
||||
import { authCert } from '@fastgpt/service/support/permission/auth/common';
|
||||
import { NodeTemplateListItemType } from '@fastgpt/global/core/workflow/type/node.d';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { getCommunityPluginsTemplateList } from '@fastgpt/plugins/register';
|
||||
import { getSystemPluginTemplates } from '@fastgpt/plugins/register';
|
||||
import { FlowNodeTemplateTypeEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
import { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import { ApiRequestProps } from '@fastgpt/service/type/next';
|
||||
import { replaceRegChars } from '@fastgpt/global/common/string/tools';
|
||||
|
||||
export type GetSystemPluginTemplatesBody = {
|
||||
searchKey?: string;
|
||||
parentId: ParentIdType;
|
||||
};
|
||||
|
||||
async function handler(
|
||||
req: NextApiRequest,
|
||||
req: ApiRequestProps<GetSystemPluginTemplatesBody>,
|
||||
res: NextApiResponse<any>
|
||||
): Promise<NodeTemplateListItemType[]> {
|
||||
await authCert({ req, authToken: true });
|
||||
|
||||
// const data: NodeTemplateListItemType[] =
|
||||
// global.communityPlugins?.map((plugin) => ({
|
||||
// id: plugin.id,
|
||||
// templateType: plugin.templateType ?? FlowNodeTemplateTypeEnum.other,
|
||||
// flowNodeType: FlowNodeTypeEnum.pluginModule,
|
||||
// avatar: plugin.avatar,
|
||||
// name: plugin.name,
|
||||
// intro: plugin.intro
|
||||
// })) || [];
|
||||
const { searchKey, parentId } = req.body;
|
||||
|
||||
return getCommunityPluginsTemplateList();
|
||||
const formatParentId = parentId || null;
|
||||
|
||||
return getSystemPluginTemplates().then((res) =>
|
||||
res
|
||||
// Just show the active plugins
|
||||
.filter((item) => item.isActive)
|
||||
.map<NodeTemplateListItemType>((plugin) => ({
|
||||
id: plugin.id,
|
||||
isFolder: plugin.isFolder,
|
||||
parentId: plugin.parentId,
|
||||
templateType: plugin.templateType ?? FlowNodeTemplateTypeEnum.other,
|
||||
flowNodeType: FlowNodeTypeEnum.pluginModule,
|
||||
avatar: plugin.avatar,
|
||||
name: plugin.name,
|
||||
intro: plugin.intro,
|
||||
isTool: plugin.isTool,
|
||||
currentCost: plugin.currentCost,
|
||||
author: plugin.author
|
||||
}))
|
||||
.filter((item) => {
|
||||
if (searchKey) {
|
||||
if (item.isFolder) return false;
|
||||
const regx = new RegExp(`${replaceRegChars(searchKey)}`, 'i');
|
||||
return regx.test(item.name) || regx.test(item.intro || '');
|
||||
}
|
||||
return item.parentId === formatParentId;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
|
||||
35
projects/app/src/pages/api/core/app/plugin/path.ts
Normal file
35
projects/app/src/pages/api/core/app/plugin/path.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { ParentIdType, ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import { getSystemPluginTemplates } from '@fastgpt/plugins/register';
|
||||
|
||||
export type pathQuery = {
|
||||
parentId: ParentIdType;
|
||||
};
|
||||
|
||||
export type pathBody = {};
|
||||
|
||||
export type pathResponse = Promise<ParentTreePathItemType[]>;
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<pathBody, pathQuery>,
|
||||
res: ApiResponseType<any>
|
||||
): Promise<pathResponse> {
|
||||
const { parentId } = req.query;
|
||||
|
||||
if (!parentId) return [];
|
||||
|
||||
const plugins = await getSystemPluginTemplates();
|
||||
const plugin = plugins.find((item) => item.id === parentId);
|
||||
|
||||
if (!plugin) return [];
|
||||
|
||||
return [
|
||||
{
|
||||
parentId: plugin.id,
|
||||
parentName: plugin.name
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
||||
@@ -30,7 +30,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
});
|
||||
|
||||
const response = await ai.chat.completions.create({
|
||||
model: 'gpt-3.5-turbo',
|
||||
model: 'gpt-4o-mini',
|
||||
max_tokens: 1,
|
||||
messages: [{ role: 'user', content: 'hi' }]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user