|
|
@@ -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:
|