perf: 生成对话框时机

This commit is contained in:
archer
2023-04-23 14:07:17 +08:00
parent 9682c82713
commit c2c73ed23c
25 changed files with 299 additions and 327 deletions

View File

@@ -47,7 +47,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
userId,
status: ModelStatusEnum.running,
service: {
company: modelItem.serviceCompany,
trainId: '',
chatModel: ChatModelNameMap[modelItem.model], // 聊天时用的模型
modelName: modelItem.model // 最底层的模型,不会变,用于计费等核心操作

View File

@@ -36,14 +36,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const textList: string[] = [];
let splitText = '';
/* 取 3k ~ 4K tokens 内容 */
/* 取 2.5k ~ 3.5K tokens 内容 */
chunks.forEach((chunk) => {
const tokens = encode(splitText + chunk).length;
if (tokens >= 4000) {
// 超过 4000不要这块内容
if (tokens >= 3500) {
// 超过 3500不要这块内容
splitText && textList.push(splitText);
splitText = chunk;
} else if (tokens >= 3000) {
} else if (tokens >= 2500) {
// 超过 3000取内容
splitText && textList.push(splitText + chunk);
splitText = '';