feat: Make MAX_TOKENS and MAX_RESPONSE_SEGMENTS configurable

Added MAX_TOKENS and MAX_RESPONSE_SEGMENTS to .env.example and documentation. Updated constants to read from environment variables, allowing configuration of token and response segment limits.
This commit is contained in:
LIlGG
2025-09-29 17:19:07 +08:00
parent 48d81e92bb
commit ad5741879a
4 changed files with 11 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
// see https://docs.anthropic.com/en/docs/about-claude/models
export const MAX_TOKENS = 8000;
export const MAX_TOKENS = process.env.MAX_TOKENS ? parseInt(process.env.MAX_TOKENS) : 8000;
// limits the number of model responses that can be returned in a single request
export const MAX_RESPONSE_SEGMENTS = 3;
export const MAX_RESPONSE_SEGMENTS = process.env.MAX_RESPONSE_SEGMENTS
? parseInt(process.env.MAX_RESPONSE_SEGMENTS)
: 5;

View File

@@ -331,7 +331,7 @@ export async function chatAction({ request, userId }: ChatActionArgs) {
const continueMessage = async (text: string) => {
logger.info(
`达到最大 token 限制 (${MAX_TOKENS}): 继续消息, 还可以响应 (${MAX_RESPONSE_SEGMENTS - streamSwitches} 个分段)`,
`达到最大 token 限制 (${DEFAULT_MODEL_DETAILS?.maxTokenAllowed || MAX_TOKENS}): 继续消息, 还可以响应 (${MAX_RESPONSE_SEGMENTS - streamSwitches} 个分段)`,
);
messages.push({
id: generateId(),