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:
@@ -10,6 +10,10 @@ OPERATING_ENV=production
|
||||
STORAGE_DIR=/public/uploads
|
||||
# Maximum upload size for attachments
|
||||
MAX_UPLOAD_SIZE_MB=5
|
||||
# The number of segments when reaching the maximum Tokens count
|
||||
MAX_RESPONSE_SEGMENTS=5
|
||||
# Default token usage for a single chat
|
||||
MAX_TOKENS=8000
|
||||
|
||||
# Example Context Values for qwen2.5-coder:32b
|
||||
#
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -24,6 +24,8 @@ UPage 使用环境变量进行配置。您可以通过以下方式设置环境
|
||||
| `USAGE_LOG_FILE` | 是否开启文件日志 | `true` | 否 |
|
||||
| `MAX_UPLOAD_SIZE_MB` | 附件上传的最大大小 (MB) | `5` | 否 |
|
||||
| `STORAGE_DIR` | 资源文件存储位置 | `/app/storage` | 否 |
|
||||
| `MAX_RESPONSE_SEGMENTS` | 最大响应分段数 | `5` | 否 |
|
||||
| `MAX_TOKENS` | 最大 token 数 | `8000` | 否 |
|
||||
|
||||
## AI 提供商配置
|
||||
|
||||
|
||||
Reference in New Issue
Block a user