perf: 文本截取

This commit is contained in:
archer
2023-04-17 09:02:39 +08:00
parent 426eceac22
commit 0db413ab52
6 changed files with 10 additions and 38 deletions

View File

@@ -116,8 +116,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
});
} else {
// 有匹配情况下,添加知识库内容。
// 系统提示词过滤,最多 2800 tokens
const systemPrompt = systemPromptFilter(formatRedisPrompt, 2800);
// 系统提示词过滤,最多 2000 tokens
const systemPrompt = systemPromptFilter(formatRedisPrompt, 2000);
prompts.unshift({
obj: 'SYSTEM',

View File

@@ -28,10 +28,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw new Error('无权操作该模型');
}
const replaceText = text.replace(/(\\n|\n)+/g, ' ');
const replaceText = text.replace(/\\n/g, '\n');
// 文本拆分成 chunk
const chunks = replaceText.match(/[^!?.。]+[!?.。]/g) || [];
const chunks = replaceText.split('\n').filter((item) => item.trim());
const textList: string[] = [];
let splitText = '';

View File

@@ -1,18 +0,0 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import axios from 'axios';
import { connectToDatabase, User, Pay } from '@/service/mongo';
import { authToken } from '@/service/utils/tools';
import { PaySchema } from '@/types/mongoSchema';
import dayjs from 'dayjs';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
res.send('');
} catch (err) {
jsonRes(res, {
code: 500,
error: err
});
}
}