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

+ 11 - 2
src/chat-pdf/chat-pdf.service.ts

@@ -183,12 +183,18 @@ export class ChatPdfService {
             return res.data.choices[0].message.content
         } catch (error) {
             Logger.error(error.message)
+            if (error.response) {
+                Logger.error(error.response.data)
+            }
             throw new InternalServerErrorException(error.message)
         }
     }
 
     async searchEmbedding(name: string, embedding: number[]) {
         return await ChatEmbedding.findAll({
+            where: {
+                name
+            },
             order: this.sequelize.literal(`embedding <-> '${formatEmbedding(embedding)}'`),
             limit: 100
         })
@@ -209,7 +215,7 @@ export class ChatPdfService {
         const keywords = await this.getKeywords(q)
         const { embedding: keywordEmbedding } = await this.getEmbedding(keywords)
         const context = this.cutContext((await this.searchEmbedding(name, keywordEmbedding)).map((item) => item.text))
-        if (!context.length) {
+        if (!context || !context.length) {
             return {
                 answer: '未找到相关内容'
             }
@@ -225,7 +231,6 @@ export class ChatPdfService {
         If the context does not mention the content or it is uncertain whether it is correct, 
         please answer "Current context cannot provide effective information."
         You must use Chinese to respond.`
-        Logger.log(content)
         try {
             const response = await this.openai.createChatCompletion({
                 model: 'gpt35',
@@ -237,6 +242,10 @@ export class ChatPdfService {
             return { answer: response.data.choices[0].message.content }
         } catch (error) {
             Logger.error(error.message)
+            if (error.response) {
+                Logger.error(error.response.data)
+            }
+            throw new InternalServerErrorException(error.message)
         }
     }
 }