mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 12:20:34 +00:00
fix: package plus request (#4492)
* fix plus request (#4476) * perf: package plus request * perf: plus request fix * fix: doc --------- Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
29
packages/service/common/api/type.d.ts
vendored
Normal file
29
packages/service/common/api/type.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
|
||||
import {
|
||||
DeepRagSearchProps,
|
||||
SearchDatasetDataResponse
|
||||
} from '../../core/dataset/search/controller';
|
||||
import { AuthOpenApiLimitProps } from '../../support/openapi/auth';
|
||||
import { CreateUsageProps, ConcatUsageProps } from '@fastgpt/global/support/wallet/usage/api';
|
||||
import {
|
||||
GetProApiDatasetFileContentParams,
|
||||
GetProApiDatasetFileListParams,
|
||||
GetProApiDatasetFilePreviewUrlParams
|
||||
} from '../../core/dataset/apiDataset/proApi';
|
||||
|
||||
declare global {
|
||||
var textCensorHandler: (params: { text: string }) => Promise<{ code: number; message?: string }>;
|
||||
var deepRagHandler: (data: DeepRagSearchProps) => Promise<SearchDatasetDataResponse>;
|
||||
var authOpenApiHandler: (data: AuthOpenApiLimitProps) => Promise<any>;
|
||||
var createUsageHandler: (data: CreateUsageProps) => Promise<void>;
|
||||
var concatUsageHandler: (data: ConcatUsageProps) => Promise<void>;
|
||||
|
||||
// API dataset
|
||||
var getProApiDatasetFileList: (data: GetProApiDatasetFileListParams) => Promise<APIFileItem[]>;
|
||||
var getProApiDatasetFileContent: (
|
||||
data: GetProApiDatasetFileContentParams
|
||||
) => Promise<ApiFileReadContentResponse>;
|
||||
var getProApiDatasetFilePreviewUrl: (
|
||||
data: GetProApiDatasetFilePreviewUrlParams
|
||||
) => Promise<string>;
|
||||
}
|
@@ -1,4 +1,3 @@
|
||||
export const FastGPTProUrl = process.env.PRO_URL ? `${process.env.PRO_URL}/api` : '';
|
||||
export const isFastGPTMainService = !!process.env.PRO_URL;
|
||||
// @ts-ignore
|
||||
export const isFastGPTProService = () => !!global.systemConfig;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { POST } from './plusRequest';
|
||||
|
||||
export const postTextCensor = (data: { text: string }) =>
|
||||
POST<{ code?: number; message: string }>('/common/censor/check', data)
|
||||
global
|
||||
.textCensorHandler(data)
|
||||
.then((res) => {
|
||||
if (res?.code === 5000) {
|
||||
return Promise.reject(res);
|
25
packages/service/core/dataset/apiDataset/proApi.ts
Normal file
25
packages/service/core/dataset/apiDataset/proApi.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||
import { FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
|
||||
|
||||
export enum ProApiDatasetOperationTypeEnum {
|
||||
LIST = 'list',
|
||||
READ = 'read',
|
||||
CONTENT = 'content'
|
||||
}
|
||||
|
||||
export type ProApiDatasetCommonParams = {
|
||||
feishuServer?: FeishuServer;
|
||||
yuqueServer?: YuqueServer;
|
||||
};
|
||||
|
||||
export type GetProApiDatasetFileListParams = ProApiDatasetCommonParams & {
|
||||
parentId?: ParentIdType;
|
||||
};
|
||||
|
||||
export type GetProApiDatasetFileContentParams = ProApiDatasetCommonParams & {
|
||||
apiFileId: string;
|
||||
};
|
||||
|
||||
export type GetProApiDatasetFilePreviewUrlParams = ProApiDatasetCommonParams & {
|
||||
apiFileId: string;
|
||||
};
|
@@ -9,7 +9,6 @@ import { readRawContentByFileBuffer } from '../../common/file/read/utils';
|
||||
import { parseFileExtensionFromUrl } from '@fastgpt/global/common/string/tools';
|
||||
import { APIFileServer, FeishuServer, YuqueServer } from '@fastgpt/global/core/dataset/apiDataset';
|
||||
import { useApiDatasetRequest } from './apiDataset/api';
|
||||
import { POST } from '../../common/api/plusRequest';
|
||||
|
||||
export const readFileRawTextByUrl = async ({
|
||||
teamId,
|
||||
@@ -168,11 +167,7 @@ export const readApiServerFileContent = async ({
|
||||
}
|
||||
|
||||
if (feishuServer || yuqueServer) {
|
||||
return POST<{
|
||||
title?: string;
|
||||
rawText: string;
|
||||
}>(`/core/dataset/systemApiDataset`, {
|
||||
type: 'content',
|
||||
return global.getProApiDatasetFileContent({
|
||||
feishuServer,
|
||||
yuqueServer,
|
||||
apiFileId
|
||||
|
@@ -24,7 +24,6 @@ import { MongoDatasetCollectionTags } from '../tag/schema';
|
||||
import { readFromSecondary } from '../../../common/mongo/utils';
|
||||
import { MongoDatasetDataText } from '../data/dataTextSchema';
|
||||
import { ChatItemType } from '@fastgpt/global/core/chat/type';
|
||||
import { POST } from '../../../common/api/plusRequest';
|
||||
import { NodeInputKeyEnum } from '@fastgpt/global/core/workflow/constants';
|
||||
import { datasetSearchQueryExtension } from './utils';
|
||||
import type { RerankModelItemType } from '@fastgpt/global/core/ai/model.d';
|
||||
@@ -850,5 +849,4 @@ export type DeepRagSearchProps = SearchDatasetDataProps & {
|
||||
[NodeInputKeyEnum.datasetDeepSearchMaxTimes]?: number;
|
||||
[NodeInputKeyEnum.datasetDeepSearchBg]?: string;
|
||||
};
|
||||
export const deepRagSearch = (data: DeepRagSearchProps) =>
|
||||
POST<SearchDatasetDataResponse>('/core/dataset/deepRag', data);
|
||||
export const deepRagSearch = (data: DeepRagSearchProps) => global.deepRagHandler(data);
|
||||
|
@@ -29,9 +29,9 @@ import { InteractiveNodeResponseType } from '@fastgpt/global/core/workflow/templ
|
||||
import { getFileContentFromLinks, getHistoryFileLinks } from '../../tools/readFiles';
|
||||
import { parseUrlToFileType } from '@fastgpt/global/common/file/tools';
|
||||
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
||||
import { postTextCensor } from '../../../../../common/api/requestPlusApi';
|
||||
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
|
||||
import { getDocumentQuotePrompt } from '@fastgpt/global/core/ai/prompt/AIChat';
|
||||
import { postTextCensor } from '../../../../chat/postTextCensor';
|
||||
|
||||
type Response = DispatchNodeResultType<{
|
||||
[NodeOutputKeyEnum.answerText]: string;
|
||||
|
@@ -13,7 +13,6 @@ import type {
|
||||
} from '@fastgpt/global/core/ai/type.d';
|
||||
import { formatModelChars2Points } from '../../../../support/wallet/usage/utils';
|
||||
import type { LLMModelItemType } from '@fastgpt/global/core/ai/model.d';
|
||||
import { postTextCensor } from '../../../../common/api/requestPlusApi';
|
||||
import { ChatCompletionRequestMessageRoleEnum } from '@fastgpt/global/core/ai/constants';
|
||||
import type {
|
||||
ChatDispatchProps,
|
||||
@@ -51,6 +50,7 @@ import { getFileContentFromLinks, getHistoryFileLinks } from '../tools/readFiles
|
||||
import { parseUrlToFileType } from '@fastgpt/global/common/file/tools';
|
||||
import { i18nT } from '../../../../../web/i18n/utils';
|
||||
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
|
||||
import { postTextCensor } from '../../../chat/postTextCensor';
|
||||
|
||||
export type ChatProps = ModuleDispatchProps<
|
||||
AIChatNodeProps & {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
|
||||
import { updateApiKeyUsedTime } from './tools';
|
||||
import { MongoOpenApi } from './schema';
|
||||
import { POST } from '../../common/api/plusRequest';
|
||||
import type { OpenApiSchema } from '@fastgpt/global/support/openapi/type';
|
||||
|
||||
export type AuthOpenApiLimitProps = { openApi: OpenApiSchema };
|
||||
@@ -17,11 +16,10 @@ export async function authOpenApiKey({ apikey }: { apikey: string }) {
|
||||
}
|
||||
|
||||
// auth limit
|
||||
// @ts-ignore
|
||||
if (global.feConfigs?.isPlus) {
|
||||
await POST('/support/openapi/authLimit', {
|
||||
await global.authOpenApiHandler({
|
||||
openApi
|
||||
} as AuthOpenApiLimitProps);
|
||||
});
|
||||
}
|
||||
|
||||
updateApiKeyUsedTime(openApi._id);
|
||||
|
@@ -1,67 +1,21 @@
|
||||
import { UsageSourceEnum } from '@fastgpt/global/support/wallet/usage/constants';
|
||||
import { MongoUsage } from './schema';
|
||||
import { ClientSession, Types } from '../../../common/mongo';
|
||||
import { ClientSession } from '../../../common/mongo';
|
||||
import { addLog } from '../../../common/system/log';
|
||||
import { ChatNodeUsageType } from '@fastgpt/global/support/wallet/bill/type';
|
||||
import { ConcatUsageProps, CreateUsageProps } from '@fastgpt/global/support/wallet/usage/api';
|
||||
import { i18nT } from '../../../../web/i18n/utils';
|
||||
import { pushConcatBillTask, pushReduceTeamAiPointsTask } from './utils';
|
||||
|
||||
import { POST } from '../../../common/api/plusRequest';
|
||||
import { isFastGPTMainService } from '../../../common/system/constants';
|
||||
|
||||
export async function createUsage(data: CreateUsageProps) {
|
||||
try {
|
||||
// In FastGPT server
|
||||
if (isFastGPTMainService) {
|
||||
await POST('/support/wallet/usage/createUsage', data);
|
||||
} else if (global.reduceAiPointsQueue) {
|
||||
// In FastGPT pro server
|
||||
await MongoUsage.create(data);
|
||||
pushReduceTeamAiPointsTask({ teamId: data.teamId, totalPoints: data.totalPoints });
|
||||
|
||||
if (data.totalPoints === 0) {
|
||||
addLog.info('0 totalPoints', data);
|
||||
}
|
||||
}
|
||||
await global.createUsageHandler(data);
|
||||
} catch (error) {
|
||||
addLog.error('createUsage error', error);
|
||||
}
|
||||
}
|
||||
export async function concatUsage(data: ConcatUsageProps) {
|
||||
try {
|
||||
// In FastGPT server
|
||||
if (isFastGPTMainService) {
|
||||
await POST('/support/wallet/usage/concatUsage', data);
|
||||
} else if (global.reduceAiPointsQueue) {
|
||||
const {
|
||||
teamId,
|
||||
billId,
|
||||
totalPoints = 0,
|
||||
listIndex,
|
||||
inputTokens = 0,
|
||||
outputTokens = 0
|
||||
} = data;
|
||||
|
||||
// billId is required and valid
|
||||
if (!billId || !Types.ObjectId.isValid(billId)) return;
|
||||
|
||||
// In FastGPT pro server
|
||||
pushConcatBillTask([
|
||||
{
|
||||
billId,
|
||||
listIndex,
|
||||
inputTokens,
|
||||
outputTokens,
|
||||
totalPoints
|
||||
}
|
||||
]);
|
||||
pushReduceTeamAiPointsTask({ teamId, totalPoints });
|
||||
|
||||
if (data.totalPoints === 0) {
|
||||
addLog.info('0 totalPoints', data);
|
||||
}
|
||||
}
|
||||
await global.concatUsageHandler(data);
|
||||
} catch (error) {
|
||||
addLog.error('concatUsage error', error);
|
||||
}
|
||||
|
@@ -1,6 +1,5 @@
|
||||
import { findAIModel } from '../../../core/ai/model';
|
||||
import { ModelTypeEnum } from '@fastgpt/global/core/ai/model';
|
||||
import { ConcatBillQueueItemType } from './type';
|
||||
|
||||
export const formatModelChars2Points = ({
|
||||
model,
|
||||
@@ -35,20 +34,3 @@ export const formatModelChars2Points = ({
|
||||
totalPoints
|
||||
};
|
||||
};
|
||||
|
||||
export const pushReduceTeamAiPointsTask = ({
|
||||
teamId,
|
||||
totalPoints
|
||||
}: {
|
||||
teamId: string;
|
||||
totalPoints: number;
|
||||
}) => {
|
||||
global.reduceAiPointsQueue.push({
|
||||
teamId: String(teamId),
|
||||
totalPoints
|
||||
});
|
||||
};
|
||||
|
||||
export const pushConcatBillTask = (data: ConcatBillQueueItemType[]) => {
|
||||
global.concatBillQueue.push(...data);
|
||||
};
|
||||
|
@@ -97,7 +97,7 @@
|
||||
"permission.des.read": "View knowledge base content",
|
||||
"permission.des.write": "Ability to add and change knowledge base content",
|
||||
"preview_chunk": "Preview chunks",
|
||||
"preview_chunk_empty": "Unable to read the contents of the file",
|
||||
"preview_chunk_empty": "File content is empty",
|
||||
"preview_chunk_intro": "A total of {{total}} blocks, up to 10",
|
||||
"preview_chunk_not_selected": "Click on the file on the left to preview",
|
||||
"process.Auto_Index": "Automatic index generation",
|
||||
|
@@ -97,7 +97,7 @@
|
||||
"permission.des.read": "可查看知识库内容",
|
||||
"permission.des.write": "可增加和变更知识库内容",
|
||||
"preview_chunk": "分块预览",
|
||||
"preview_chunk_empty": "无法读取该文件内容",
|
||||
"preview_chunk_empty": "文件内容为空",
|
||||
"preview_chunk_intro": "共 {{total}} 个分块,最多展示 10 个",
|
||||
"preview_chunk_not_selected": "点击左侧文件后进行预览",
|
||||
"process.Auto_Index": "自动索引生成",
|
||||
|
@@ -97,7 +97,7 @@
|
||||
"permission.des.read": "可檢視資料集內容",
|
||||
"permission.des.write": "可新增和變更資料集內容",
|
||||
"preview_chunk": "分塊預覽",
|
||||
"preview_chunk_empty": "無法讀取該文件內容",
|
||||
"preview_chunk_empty": "文件內容為空",
|
||||
"preview_chunk_intro": "共 {{total}} 個分塊,最多展示 10 個",
|
||||
"preview_chunk_not_selected": "點擊左側文件後進行預覽",
|
||||
"process.Auto_Index": "自動索引生成",
|
||||
|
Reference in New Issue
Block a user