Skip to content

Commit 74bbf50

Browse files
Merge branch 'open-webui:dev' into dev
2 parents 18e0e60 + 284b97b commit 74bbf50

9 files changed

Lines changed: 62 additions & 22 deletions

File tree

backend/open_webui/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,9 @@ async def dispatch(self, request: Request, call_next):
13291329
token = None
13301330

13311331
if auth_header:
1332-
scheme, token = auth_header.split(" ")
1332+
parts = auth_header.split(" ", 1)
1333+
if len(parts) == 2:
1334+
token = parts[1]
13331335

13341336
# Only apply restrictions if an sk- API key is used
13351337
if token and token.startswith("sk-"):

backend/open_webui/routers/retrieval.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,25 @@ async def update_rag_config(
10421042
)
10431043

10441044
# File upload settings
1045-
request.app.state.config.FILE_MAX_SIZE = form_data.FILE_MAX_SIZE
1046-
request.app.state.config.FILE_MAX_COUNT = form_data.FILE_MAX_COUNT
1045+
request.app.state.config.FILE_MAX_SIZE = (
1046+
form_data.FILE_MAX_SIZE
1047+
if form_data.FILE_MAX_SIZE is not None
1048+
else request.app.state.config.FILE_MAX_SIZE
1049+
)
1050+
request.app.state.config.FILE_MAX_COUNT = (
1051+
form_data.FILE_MAX_COUNT
1052+
if form_data.FILE_MAX_COUNT is not None
1053+
else request.app.state.config.FILE_MAX_COUNT
1054+
)
10471055
request.app.state.config.FILE_IMAGE_COMPRESSION_WIDTH = (
10481056
form_data.FILE_IMAGE_COMPRESSION_WIDTH
1057+
if form_data.FILE_IMAGE_COMPRESSION_WIDTH is not None
1058+
else request.app.state.config.FILE_IMAGE_COMPRESSION_WIDTH
10491059
)
10501060
request.app.state.config.FILE_IMAGE_COMPRESSION_HEIGHT = (
10511061
form_data.FILE_IMAGE_COMPRESSION_HEIGHT
1062+
if form_data.FILE_IMAGE_COMPRESSION_HEIGHT is not None
1063+
else request.app.state.config.FILE_IMAGE_COMPRESSION_HEIGHT
10521064
)
10531065
request.app.state.config.ALLOWED_FILE_EXTENSIONS = (
10541066
form_data.ALLOWED_FILE_EXTENSIONS

backend/open_webui/tools/builtin.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from open_webui.models.channels import Channels, ChannelMember, Channel
3737
from open_webui.models.messages import Messages, Message
3838
from open_webui.models.groups import Groups
39-
from open_webui.utils.sanitize import strip_markdown_code_fences
39+
from open_webui.utils.sanitize import sanitize_code
4040

4141
log = logging.getLogger(__name__)
4242

@@ -371,8 +371,8 @@ async def execute_code(
371371
return json.dumps({"error": "Request context not available"})
372372

373373
try:
374-
# Strip markdown fences if model included them
375-
code = strip_markdown_code_fences(code)
374+
# Sanitize code (strips ANSI codes and markdown fences)
375+
code = sanitize_code(code)
376376

377377
# Import blocked modules from config (same as middleware)
378378
from open_webui.config import CODE_INTERPRETER_BLOCKED_MODULES

backend/open_webui/utils/middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
from open_webui.retrieval.utils import get_sources_from_items
7474

7575

76-
from open_webui.utils.sanitize import strip_markdown_code_fences
76+
from open_webui.utils.sanitize import sanitize_code
7777
from open_webui.utils.chat import generate_chat_completion
7878
from open_webui.utils.task import (
7979
get_task_model_id,
@@ -4175,8 +4175,8 @@ async def flush_pending_delta_data(threshold: int = 0):
41754175
try:
41764176
if content_blocks[-1]["attributes"].get("type") == "code":
41774177
code = content_blocks[-1]["content"]
4178-
# Strip markdown fences if model included them
4179-
code = strip_markdown_code_fences(code)
4178+
# Sanitize code (strips ANSI codes and markdown fences)
4179+
code = sanitize_code(code)
41804180

41814181
if CODE_INTERPRETER_BLOCKED_MODULES:
41824182
blocking_code = textwrap.dedent(

backend/open_webui/utils/sanitize.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
import re
22

3+
# ANSI escape code pattern - matches all common ANSI sequences
4+
# This includes color codes, cursor movement, and other terminal control sequences
5+
ANSI_ESCAPE_PATTERN = re.compile(r'\x1b\[[0-9;]*[A-Za-z]|\x1b\([AB]|\x1b[PX^_].*?\x1b\\|\x1b\].*?(?:\x07|\x1b\\)')
6+
7+
8+
def strip_ansi_codes(text: str) -> str:
9+
"""
10+
Strip ANSI escape codes from text.
11+
12+
ANSI escape codes can be introduced by LLMs that include terminal
13+
color codes in their output. These codes cause syntax errors when
14+
the code is sent to Jupyter for execution.
15+
16+
Common ANSI codes include:
17+
- Color codes: \x1b[31m (red), \x1b[32m (green), etc.
18+
- Reset codes: \x1b[0m, \x1b[39m
19+
- Cursor movement: \x1b[1A, \x1b[2J, etc.
20+
"""
21+
return ANSI_ESCAPE_PATTERN.sub('', text)
22+
323

424
def strip_markdown_code_fences(code: str) -> str:
525
"""
@@ -19,3 +39,20 @@ def strip_markdown_code_fences(code: str) -> str:
1939
# Remove closing fence
2040
code = re.sub(r"\n?```\s*$", "", code)
2141
return code.strip()
42+
43+
44+
def sanitize_code(code: str) -> str:
45+
"""
46+
Sanitize code for execution by applying all necessary cleanup steps.
47+
48+
This is the recommended function to use before sending code to
49+
interpreters like Jupyter or Pyodide.
50+
51+
Steps applied:
52+
1. Strip ANSI escape codes (from LLM output)
53+
2. Strip markdown code fences (if model included them)
54+
"""
55+
code = strip_ansi_codes(code)
56+
code = strip_markdown_code_fences(code)
57+
return code
58+

src/lib/components/chat/MessageInput.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@
17441744
<!-- {$i18n.t('Create Note')} -->
17451745
<Tooltip content={$i18n.t('Create note')} className=" flex items-center">
17461746
<button
1747-
id="send-message-button"
1747+
id="create-note-button"
17481748
class=" text-gray-600 dark:text-gray-300 hover:text-gray-700 dark:hover:text-gray-200 transition rounded-full p-1.5 self-center"
17491749
type="button"
17501750
disabled={prompt === '' && files.length === 0}

src/lib/components/chat/Messages/Markdown/MarkdownTokens.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
<div class="scrollbar-hidden relative overflow-x-auto max-w-full">
135135
<table
136136
class=" w-full text-sm text-left text-gray-500 dark:text-gray-400 max-w-full rounded-xl"
137+
dir="auto"
137138
>
138139
<thead
139140
class="text-xs text-gray-700 uppercase bg-white dark:bg-gray-900 dark:text-gray-400 border-none"

src/lib/components/layout/Sidebar.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -815,9 +815,6 @@
815815
{#if $config?.features?.enable_user_status}
816816
<div class="absolute -bottom-0.5 -right-0.5">
817817
<span class="relative flex size-2.5">
818-
<span
819-
class="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"
820-
></span>
821818
<span
822819
class="relative inline-flex size-2.5 rounded-full {true
823820
? 'bg-green-500'
@@ -1384,9 +1381,6 @@
13841381
{#if $config?.features?.enable_user_status}
13851382
<div class="absolute -bottom-0.5 -right-0.5">
13861383
<span class="relative flex size-2.5">
1387-
<span
1388-
class="absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"
1389-
></span>
13901384
<span
13911385
class="relative inline-flex size-2.5 rounded-full {true
13921386
? 'bg-green-500'

src/lib/components/layout/Sidebar/UserMenu.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@
110110
{#if $user?.is_active ?? true}
111111
<div>
112112
<span class="relative flex size-2">
113-
<span
114-
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
115-
/>
116113
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
117114
</span>
118115
</div>
@@ -371,9 +368,6 @@
371368
>
372369
<div class=" flex items-center">
373370
<span class="relative flex size-2">
374-
<span
375-
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"
376-
/>
377371
<span class="relative inline-flex rounded-full size-2 bg-green-500" />
378372
</span>
379373
</div>

0 commit comments

Comments
 (0)