feat(server): improve session modify (#12928)

fix AI-248
This commit is contained in:
DarkSky
2025-06-25 20:02:21 +08:00
committed by GitHub
parent 697e0bf9ba
commit e32c9a814a
11 changed files with 282 additions and 270 deletions
@@ -3,8 +3,8 @@ import { Logger } from '@nestjs/common';
import { AiPrompt } from '@prisma/client';
import Mustache from 'mustache';
import { getTokenEncoder } from '../../../native';
import { PromptConfig, PromptMessage, PromptParams } from '../providers';
import { getTokenEncoder } from '../types';
// disable escaping
Mustache.escape = (text: string) => text;
@@ -56,8 +56,7 @@ export class ChatPrompt {
private readonly messages: PromptMessage[]
) {
this.encoder = getTokenEncoder(model);
this.promptTokenSize =
this.encoder?.count(messages.map(m => m.content).join('') || '') || 0;
this.promptTokenSize = this.encode(messages.map(m => m.content).join(''));
this.templateParamKeys = extractMustacheParams(
messages.map(m => m.content).join('')
);