Преглед изворни кода

Rename field (pageId -> page)

Shun Miyazawa пре 1 година
родитељ
комит
e6337bee0d

+ 8 - 8
apps/app/src/features/openai/server/models/vector-store-file-relation.ts

@@ -6,7 +6,7 @@ import { getOrCreateModel } from '~/server/util/mongoose-utils';
 
 export interface VectorStoreFileRelation {
   vectorStoreRelationId: mongoose.Types.ObjectId;
-  pageId: mongoose.Types.ObjectId;
+  page: mongoose.Types.ObjectId;
   fileIds: string[];
   isAttachedToVectorStore: boolean;
 }
@@ -19,9 +19,9 @@ interface VectorStoreFileRelationModel extends Model<VectorStoreFileRelation> {
 }
 
 export const prepareVectorStoreFileRelations = (
-    vectorStoreRelationId: Types.ObjectId, pageId: Types.ObjectId, fileId: string, relationsMap: Map<string, VectorStoreFileRelation>,
+    vectorStoreRelationId: Types.ObjectId, page: Types.ObjectId, fileId: string, relationsMap: Map<string, VectorStoreFileRelation>,
 ): Map<string, VectorStoreFileRelation> => {
-  const pageIdStr = pageId.toHexString();
+  const pageIdStr = page.toHexString();
   const existingData = relationsMap.get(pageIdStr);
 
   // If the data exists, add the fileId to the fileIds array
@@ -32,7 +32,7 @@ export const prepareVectorStoreFileRelations = (
   else {
     relationsMap.set(pageIdStr, {
       vectorStoreRelationId,
-      pageId,
+      page,
       fileIds: [fileId],
       isAttachedToVectorStore: false,
     });
@@ -47,7 +47,7 @@ const schema = new Schema<VectorStoreFileRelationDocument, VectorStoreFileRelati
     ref: 'VectorStore',
     required: true,
   },
-  pageId: {
+  page: {
     type: Schema.Types.ObjectId,
     ref: 'Page',
     required: true,
@@ -64,14 +64,14 @@ const schema = new Schema<VectorStoreFileRelationDocument, VectorStoreFileRelati
 });
 
 // define unique compound index
-schema.index({ vectorStoreRelationId: 1, pageId: 1 }, { unique: true });
+schema.index({ vectorStoreRelationId: 1, page: 1 }, { unique: true });
 
 schema.statics.upsertVectorStoreFileRelations = async function(vectorStoreFileRelations: VectorStoreFileRelation[]): Promise<void> {
   await this.bulkWrite(
     vectorStoreFileRelations.map((data) => {
       return {
         updateOne: {
-          filter: { pageId: data.pageId, vectorStoreRelationId: data.vectorStoreRelationId },
+          filter: { page: data.page, vectorStoreRelationId: data.vectorStoreRelationId },
           update: {
             $addToSet: { fileIds: { $each: data.fileIds } },
           },
@@ -85,7 +85,7 @@ schema.statics.upsertVectorStoreFileRelations = async function(vectorStoreFileRe
 // Used when attached to VectorStore
 schema.statics.markAsAttachedToVectorStore = async function(pageIds: Types.ObjectId[]): Promise<void> {
   await this.updateMany(
-    { pageId: { $in: pageIds } },
+    { page: { $in: pageIds } },
     { $set: { isAttachedToVectorStore: true } },
   );
 };

+ 2 - 2
apps/app/src/features/openai/server/services/openai.ts

@@ -265,7 +265,7 @@ class OpenaiService implements IOpenaiService {
 
   async deleteVectorStoreFile(vectorStoreRelationId: Types.ObjectId, pageId: Types.ObjectId, apiCallInterval?: number): Promise<void> {
     // Delete vector store file and delete vector store file relation
-    const vectorStoreFileRelation = await VectorStoreFileRelationModel.findOne({ vectorStoreRelationId, pageId });
+    const vectorStoreFileRelation = await VectorStoreFileRelationModel.findOne({ vectorStoreRelationId, page: pageId });
     if (vectorStoreFileRelation == null) {
       return;
     }
@@ -316,7 +316,7 @@ class OpenaiService implements IOpenaiService {
     // Delete obsolete VectorStoreFile
     for await (const vectorStoreFileRelation of obsoleteVectorStoreFileRelations) {
       try {
-        await this.deleteVectorStoreFile(vectorStoreFileRelation.vectorStoreRelationId, vectorStoreFileRelation.pageId, apiCallInterval);
+        await this.deleteVectorStoreFile(vectorStoreFileRelation.vectorStoreRelationId, vectorStoreFileRelation.page, apiCallInterval);
       }
       catch (err) {
         logger.error(err);

+ 2 - 2
apps/app/src/features/openai/server/services/replace-annotation-with-page-link.ts

@@ -14,13 +14,13 @@ export const replaceAnnotationWithPageLink = async(messageContentDelta: MessageC
 
         const vectorStoreFileRelation = await VectorStoreFileRelationModel
           .findOne({ fileIds: { $in: [annotation.file_citation?.file_id] } })
-          .populate<{pageId: Pick<IPageHasId, 'path' | '_id'>}>('pageId', 'path');
+          .populate<{page: Pick<IPageHasId, 'path' | '_id'>}>('page', 'path');
 
         if (vectorStoreFileRelation != null) {
           const { t } = await getTranslation(lang);
           messageContentDelta.text.value = messageContentDelta.text.value?.replace(
             annotation.text,
-            ` [${t('source')}: [${vectorStoreFileRelation.pageId.path}](/${vectorStoreFileRelation.pageId._id})]`,
+            ` [${t('source')}: [${vectorStoreFileRelation.page.path}](/${vectorStoreFileRelation.page._id})]`,
           );
         }
       }