Explorar el Código

imprv createVectorStoreFileWithStreamForAttachment

Shun Miyazawa hace 10 meses
padre
commit
a74d9e0695
Se han modificado 1 ficheros con 11 adiciones y 10 borrados
  1. 11 10
      apps/app/src/features/openai/server/services/openai.ts

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

@@ -357,17 +357,18 @@ class OpenaiService implements IOpenaiService {
       objectMode: true,
       write: async(attachments: HydratedDocument<IAttachmentDocument>[], _encoding, callback) => {
         for await (const attachment of attachments) {
-          if (isVectorStoreCompatible(attachment.originalName, attachment.fileFormat)) {
-            try {
-              const fileStream = await this.crowi.fileUploadService.findDeliveryFile(attachment);
-              const uploadedFileForAttachment = await this.uploadFileForAttachment(fileStream, attachment.originalName);
-              prepareVectorStoreFileRelations(
-                vectorStoreRelationId, pageId, uploadedFileForAttachment.id, vectorStoreFileRelationsMap, attachment._id,
-              );
-            }
-            catch (err) {
-              logger.error(err);
+          try {
+            if (!isVectorStoreCompatible(attachment.originalName, attachment.fileFormat)) {
+              continue;
             }
+            const fileStream = await this.crowi.fileUploadService.findDeliveryFile(attachment);
+            const uploadedFileForAttachment = await this.uploadFileForAttachment(fileStream, attachment.originalName);
+            prepareVectorStoreFileRelations(
+              vectorStoreRelationId, pageId, uploadedFileForAttachment.id, vectorStoreFileRelationsMap, attachment._id,
+            );
+          }
+          catch (err) {
+            logger.error(err);
           }
         }
         callback();