xiongzhu %!s(int64=2) %!d(string=hai) anos
pai
achega
2894f00c15
Modificáronse 1 ficheiros con 11 adicións e 2 borrados
  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
             return res.data.choices[0].message.content
         } catch (error) {
         } catch (error) {
             Logger.error(error.message)
             Logger.error(error.message)
+            if (error.response) {
+                Logger.error(error.response.data)
+            }
             throw new InternalServerErrorException(error.message)
             throw new InternalServerErrorException(error.message)
         }
         }
     }
     }
 
 
     async searchEmbedding(name: string, embedding: number[]) {
     async searchEmbedding(name: string, embedding: number[]) {
         return await ChatEmbedding.findAll({
         return await ChatEmbedding.findAll({
+            where: {
+                name
+            },
             order: this.sequelize.literal(`embedding <-> '${formatEmbedding(embedding)}'`),
             order: this.sequelize.literal(`embedding <-> '${formatEmbedding(embedding)}'`),
             limit: 100
             limit: 100
         })
         })
@@ -209,7 +215,7 @@ export class ChatPdfService {
         const keywords = await this.getKeywords(q)
         const keywords = await this.getKeywords(q)
         const { embedding: keywordEmbedding } = await this.getEmbedding(keywords)
         const { embedding: keywordEmbedding } = await this.getEmbedding(keywords)
         const context = this.cutContext((await this.searchEmbedding(name, keywordEmbedding)).map((item) => item.text))
         const context = this.cutContext((await this.searchEmbedding(name, keywordEmbedding)).map((item) => item.text))
-        if (!context.length) {
+        if (!context || !context.length) {
             return {
             return {
                 answer: '未找到相关内容'
                 answer: '未找到相关内容'
             }
             }
@@ -225,7 +231,6 @@ export class ChatPdfService {
         If the context does not mention the content or it is uncertain whether it is correct, 
         If the context does not mention the content or it is uncertain whether it is correct, 
         please answer "Current context cannot provide effective information."
         please answer "Current context cannot provide effective information."
         You must use Chinese to respond.`
         You must use Chinese to respond.`
-        Logger.log(content)
         try {
         try {
             const response = await this.openai.createChatCompletion({
             const response = await this.openai.createChatCompletion({
                 model: 'gpt35',
                 model: 'gpt35',
@@ -237,6 +242,10 @@ export class ChatPdfService {
             return { answer: response.data.choices[0].message.content }
             return { answer: response.data.choices[0].message.content }
         } catch (error) {
         } catch (error) {
             Logger.error(error.message)
             Logger.error(error.message)
+            if (error.response) {
+                Logger.error(error.response.data)
+            }
+            throw new InternalServerErrorException(error.message)
         }
         }
     }
     }
 }
 }