xiongzhu 2 лет назад
Родитель
Сommit
f2ce75e315
1 измененных файлов с 7 добавлено и 4 удалено
  1. 7 4
      src/chat-pdf/chat-pdf.service.ts

+ 7 - 4
src/chat-pdf/chat-pdf.service.ts

@@ -48,7 +48,8 @@ export class ChatPdfService {
             username: configService.get<string>('PG_USERNAME'),
             password: configService.get<string>('PG_PASSWORD'),
             database: configService.get<string>('PG_DATABASE'),
-            logging: (msg) => Logger.debug(msg, 'Sequelize')
+            // logging: (msg) => Logger.debug(msg, 'Sequelize')
+            logging: false
         })
         ChatEmbedding.init(
             {
@@ -203,7 +204,7 @@ export class ChatPdfService {
             result[arg.index] = await self.getEmbedding(arg.text)
             Logger.log(`create embedding for ${arg.index + 1}/${content.length}`)
         }
-        const q = queue.promise(worker, 64)
+        const q = queue.promise(worker, 32)
         content.forEach((text, index) => {
             q.push({
                 text,
@@ -211,7 +212,7 @@ export class ChatPdfService {
             })
         })
         await q.drained()
-        return result
+        return result.filter(i=> i && i.text)
     }
 
     async getEmbedding(content: string, retry = 0) {
@@ -227,9 +228,11 @@ export class ChatPdfService {
             }
         } catch (error) {
             if (retry < 3) {
-                await setTimeout(1000)
+                Logger.error(`fetchEmbedding error: ${error.message}, retry ${retry}`, 'fetchEmbedding')
+                await setTimeout(2000)
                 return await this.getEmbedding(content, retry + 1)
             }
+            Logger.error(error.stack, 'fetchEmbedding')
             throw new InternalServerErrorException(error.message)
         }
     }