|
|
@@ -195,6 +195,7 @@ export class ChatPdfService {
|
|
|
}
|
|
|
|
|
|
cutContext(context: string[]) {
|
|
|
+ if (!context || !context.length) return []
|
|
|
let max = 4096 - 1024
|
|
|
for (let i = 0; i < context.length; i++) {
|
|
|
max -= this.tokenizer.encode(context[i]).length
|
|
|
@@ -208,6 +209,11 @@ 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) {
|
|
|
+ return {
|
|
|
+ answer: '未找到相关内容'
|
|
|
+ }
|
|
|
+ }
|
|
|
const content = dedent`You are a helpful AI article assistant. '
|
|
|
The following are the relevant article content fragments found from the article.
|
|
|
The relevance is sorted from high to low. '
|