diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index 90583328c9..8a8feb16fe 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -6,7 +6,12 @@ from uuid import uuid4 from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request, Response, status from fastapi.responses import StreamingResponse from fastapi.security import HTTPAuthorizationCredentials -from open_webui.config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT +from open_webui.config import ( + CONTEXT_COMPACTION_RETENTION_PERCENTAGE, + CONTEXT_COMPACTION_TOKEN_THRESHOLD, + ENABLE_ADMIN_CHAT_ACCESS, + ENABLE_ADMIN_EXPORT, +) from open_webui.constants import ERROR_MESSAGES from open_webui.events import EVENTS, publish_event from open_webui.internal.db import get_async_session @@ -192,9 +197,9 @@ async def get_folder_unread_counts(user_id: str, db: AsyncSession | None = None) class ChatConfigForm(BaseModel): CONTEXT_COMPACTION_MODEL: str | None = '' ENABLE_CONTEXT_COMPACTION: bool - CONTEXT_COMPACTION_TOKEN_THRESHOLD: int + CONTEXT_COMPACTION_TOKEN_THRESHOLD: int | None = None CONTEXT_COMPACTION_TOKEN_CAP: int | None = None - CONTEXT_COMPACTION_RETENTION_PERCENTAGE: int = 40 + CONTEXT_COMPACTION_RETENTION_PERCENTAGE: int | None = None CONTEXT_COMPACTION_PROMPT_TEMPLATE: str ENABLE_TOOL_PERMISSIONS: bool = False @@ -874,9 +879,15 @@ async def get_chat_config(user=Depends(get_admin_user)): @router.post('/config', response_model=ChatConfigForm) async def set_chat_config(form_data: ChatConfigForm, user=Depends(get_admin_user)): - threshold = max(1, int(form_data.CONTEXT_COMPACTION_TOKEN_THRESHOLD)) + threshold = form_data.CONTEXT_COMPACTION_TOKEN_THRESHOLD + if threshold is None: + threshold = CONTEXT_COMPACTION_TOKEN_THRESHOLD + threshold = max(1, int(threshold)) token_cap = max(1, int(form_data.CONTEXT_COMPACTION_TOKEN_CAP or threshold)) - retention_percentage = min(50, max(10, int(form_data.CONTEXT_COMPACTION_RETENTION_PERCENTAGE))) + retention_percentage = form_data.CONTEXT_COMPACTION_RETENTION_PERCENTAGE + if retention_percentage is None: + retention_percentage = CONTEXT_COMPACTION_RETENTION_PERCENTAGE + retention_percentage = min(50, max(10, int(retention_percentage))) await Config.upsert( chat_config_updates( { diff --git a/backend/open_webui/routers/tasks.py b/backend/open_webui/routers/tasks.py index 1dd53d8ebe..c2505b0ee0 100644 --- a/backend/open_webui/routers/tasks.py +++ b/backend/open_webui/routers/tasks.py @@ -5,6 +5,7 @@ from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Request, Response, status from fastapi.responses import JSONResponse, RedirectResponse from open_webui.config import ( + AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH, DEFAULT_AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE, DEFAULT_EMOJI_GENERATION_PROMPT_TEMPLATE, DEFAULT_FOLLOW_UP_GENERATION_PROMPT_TEMPLATE, @@ -118,7 +119,7 @@ class TaskConfigForm(BaseModel): TITLE_GENERATION_PROMPT_TEMPLATE: str IMAGE_PROMPT_GENERATION_PROMPT_TEMPLATE: str ENABLE_AUTOCOMPLETE_GENERATION: bool - AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH: int + AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH: int | None = None AUTOCOMPLETE_GENERATION_PROMPT_TEMPLATE: str TAGS_GENERATION_PROMPT_TEMPLATE: str FOLLOW_UP_GENERATION_PROMPT_TEMPLATE: str @@ -134,7 +135,10 @@ class TaskConfigForm(BaseModel): @router.post('/config/update') async def update_task_config(request: Request, form_data: TaskConfigForm, user=Depends(get_admin_user)): - await Config.upsert(config_updates(form_data.model_dump(), TASK_CONFIG_KEYS)) + data = form_data.model_dump() + if data['AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH'] is None: + data['AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH'] = AUTOCOMPLETE_GENERATION_INPUT_MAX_LENGTH + await Config.upsert(config_updates(data, TASK_CONFIG_KEYS)) return await get_config_values(TASK_CONFIG_KEYS) diff --git a/src/lib/components/admin/Settings/Interface.svelte b/src/lib/components/admin/Settings/Interface.svelte index cd68640c6e..99daa73e5e 100644 --- a/src/lib/components/admin/Settings/Interface.svelte +++ b/src/lib/components/admin/Settings/Interface.svelte @@ -1,7 +1,7 @@