MCPcopy
hub / github.com/labring/FastGPT / handler

Function handler

projects/app/src/pages/api/core/dataset/createWithFiles.ts:45–187  ·  view source on GitHub ↗
(req: ApiRequestProps)

Source from the content-addressed store, hash-verified

43import { parseApiInput } from '@fastgpt/service/common/zod/requestParseError';
44
45async function handler(req: ApiRequestProps): Promise<CreateDatasetWithFilesResponse> {
46 const { datasetParams, files } = parseApiInput({
47 req,
48 bodySchema: CreateDatasetWithFilesBodySchema
49 }).body;
50 const {
51 parentId,
52 name,
53 avatar,
54 vectorModel = getDefaultEmbeddingModel()?.model,
55 agentModel = getDefaultLLMModel()?.model,
56 vlmModel = getDefaultVLMModel()?.model
57 } = datasetParams;
58
59 const { teamId, tmbId, userId } = parentId
60 ? await authDataset({
61 req,
62 datasetId: parentId,
63 authToken: true,
64 authApiKey: true,
65 per: WritePermissionVal
66 })
67 : await authUserPer({
68 req,
69 authToken: true,
70 authApiKey: true,
71 per: TeamDatasetCreatePermissionVal
72 });
73
74 // check limit
75 await checkTeamDatasetLimit(teamId);
76
77 try {
78 const result = await mongoSessionRun(async (session) => {
79 // 1. Create dataset
80 const [dataset] = await MongoDataset.create(
81 [
82 {
83 ...parseParentIdInMongo(parentId),
84 name,
85 teamId,
86 tmbId,
87 vectorModel,
88 agentModel,
89 vlmModel,
90 avatar,
91 intro: '',
92 type: DatasetTypeEnum.dataset
93 }
94 ],
95 { session, ordered: true }
96 );
97
98 // 2. Create permission
99 await MongoResourcePermission.insertOne({
100 teamId,
101 tmbId,
102 resourceId: dataset._id,

Callers

nothing calls this directly

Calls 15

parseApiInputFunction · 0.90
getDefaultEmbeddingModelFunction · 0.90
getDefaultLLMModelFunction · 0.90
getDefaultVLMModelFunction · 0.90
authDatasetFunction · 0.90
authUserPerFunction · 0.90
checkTeamDatasetLimitFunction · 0.90
mongoSessionRunFunction · 0.90
parseParentIdInMongoFunction · 0.90
getS3AvatarSourceFunction · 0.90
getEmbeddingModelFunction · 0.90

Tested by

no test coverage detected