wangqifan 2 lat temu
rodzic
commit
7e7ccc93fe

+ 2 - 1
src/chat-pdf/chat-pdf.module.ts

@@ -3,9 +3,10 @@ import { ChatPdfService } from './chat-pdf.service'
 import { ChatPdfController } from './chat-pdf.controller'
 import { TypeOrmModule } from '@nestjs/typeorm'
 import { ConfigModule } from '@nestjs/config'
+import { SysConfigModule } from '../sys-config/sys-config.module'
 
 @Module({
-    imports: [ConfigModule],
+    imports: [ConfigModule,SysConfigModule],
     providers: [ChatPdfService],
     controllers: [ChatPdfController]
 })

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

@@ -10,6 +10,7 @@ import { Sequelize, Model, DataTypes } from 'sequelize'
 import { ConfigService } from '@nestjs/config'
 import { ChatEmbedding } from './entities/chat-embedding.entity'
 import { VECTOR } from './pgvector'
+import { SysConfigService } from '../sys-config/sys-config.service'
 
 function formatEmbedding(embedding: number[]) {
     return `[${embedding.join(', ')}]`
@@ -20,7 +21,7 @@ export class ChatPdfService {
     private readonly tokenizer: Tiktoken
     private readonly openai: OpenAIApi
     private readonly sequelize: Sequelize
-    constructor(private readonly configService: ConfigService) {
+    constructor(private readonly sysConfigService: SysConfigService, private readonly configService: ConfigService) {
         this.tokenizer = get_encoding('cl100k_base')
         this.openai = new OpenAIApi(
             new Configuration({
@@ -251,6 +252,7 @@ export class ChatPdfService {
     }
 
     async customerAsk(q: string, name: string) {
+        const defSysMsg = (await this.sysConfigService.findByName('customer_system_message'))?.value
         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))
@@ -259,7 +261,7 @@ export class ChatPdfService {
                 answer: '客服无法回答这个问题,换个试试吧'
             }
         }
-        const content = dedent`You are a helpful AI article assistant. '
+        const content = dedent`${defSysMsg}'
         The following are the relevant article content fragments found from the article. 
         The relevance is sorted from high to low. '
         You can only answer according to the following content: