fix(teacher): 区分词元预算与传输字节避免短问题被拦截

This commit is contained in:
2026-09-24 11:09:29 +08:00
parent eb3dc85a2f
commit de72b1cd94
10 changed files with 187 additions and 35 deletions

View File

@@ -169,9 +169,10 @@ export function prepareCloudTeacher(
? undefined
: createTeacherReadTools(access);
return {
// Leave room for routine JSON escaping. The exact wire size is checked below
// so unusually escape-heavy material cannot silently exceed the input budget.
inputLimit: Math.max(0, topic.definition.limits.max_input_tokens - 256),
// The cloud query contract is byte-bounded. Compile against the exact JSON
// envelope instead of reserving a fixed amount for unpredictable escaping.
inputLimit: topic.definition.limits.max_input_tokens,
measureInput: (messages: TeacherModelMessage[]) => Buffer.byteLength(JSON.stringify({ messages }), 'utf8'),
async run(
messages: TeacherModelMessage[],
signal: AbortSignal,
@@ -186,7 +187,7 @@ export function prepareCloudTeacher(
throw new TeacherError(
422,
'teacher_context_too_long',
'问题、引用或老师指令超过上下文预算,请缩短引用或新建话题。'
'本次问题或引用超过上下文预算,请缩短问题或引用后重试。'
);
}
const currentRequest = topic.requests.find((item) => item.id === requestId);