Skip to content

Commit 352391f

Browse files
committed
chore: format
1 parent 2cb2836 commit 352391f

69 files changed

Lines changed: 124 additions & 33 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/open_webui/config.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,11 @@ def feishu_oauth_register(oauth: OAuth):
850850
if FEISHU_CLIENT_ID.value:
851851
configured_providers.append("Feishu")
852852

853-
if configured_providers and not OPENID_PROVIDER_URL.value and not OPENID_END_SESSION_ENDPOINT.value:
853+
if (
854+
configured_providers
855+
and not OPENID_PROVIDER_URL.value
856+
and not OPENID_END_SESSION_ENDPOINT.value
857+
):
854858
provider_list = ", ".join(configured_providers)
855859
log.warning(
856860
f"⚠️ OAuth providers configured ({provider_list}) but OPENID_PROVIDER_URL not set - logout will not work!"
@@ -2371,7 +2375,8 @@ class BannerModel(BaseModel):
23712375
MARIADB_VECTOR_DB_URL = os.environ.get("MARIADB_VECTOR_DB_URL", "").strip()
23722376

23732377
MARIADB_VECTOR_INITIALIZE_MAX_VECTOR_LENGTH = int(
2374-
os.environ.get("MARIADB_VECTOR_INITIALIZE_MAX_VECTOR_LENGTH", "1536").strip() or "1536"
2378+
os.environ.get("MARIADB_VECTOR_INITIALIZE_MAX_VECTOR_LENGTH", "1536").strip()
2379+
or "1536"
23752380
)
23762381

23772382
# Distance strategy:
@@ -2382,7 +2387,9 @@ class BannerModel(BaseModel):
23822387
)
23832388

23842389
# HNSW M parameter (MariaDB VECTOR INDEX ... M=<int>)
2385-
MARIADB_VECTOR_INDEX_M = int(os.environ.get("MARIADB_VECTOR_INDEX_M", "8").strip() or "8")
2390+
MARIADB_VECTOR_INDEX_M = int(
2391+
os.environ.get("MARIADB_VECTOR_INDEX_M", "8").strip() or "8"
2392+
)
23862393

23872394
# Pooling (MariaDB-Vector)
23882395
MARIADB_VECTOR_POOL_SIZE = os.environ.get("MARIADB_VECTOR_POOL_SIZE", None)

backend/open_webui/retrieval/utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,9 @@ def generate_openai_batch_embeddings(
590590
if "data" in data:
591591
return [elem["embedding"] for elem in data["data"]]
592592
else:
593-
raise ValueError("Unexpected OpenAI embeddings response: missing 'data' key")
593+
raise ValueError(
594+
"Unexpected OpenAI embeddings response: missing 'data' key"
595+
)
594596
except Exception as e:
595597
log.exception(f"Error generating openai batch embeddings: {e}")
596598
return None
@@ -767,7 +769,9 @@ def generate_ollama_batch_embeddings(
767769
if "embeddings" in data:
768770
return data["embeddings"]
769771
else:
770-
raise ValueError("Unexpected Ollama embeddings response: missing 'embeddings' key")
772+
raise ValueError(
773+
"Unexpected Ollama embeddings response: missing 'embeddings' key"
774+
)
771775
except Exception as e:
772776
log.exception(f"Error generating ollama batch embeddings: {e}")
773777
return None

backend/open_webui/retrieval/vector/dbs/mariadb_vector.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
MARIADB_VECTOR_POOL_TIMEOUT,
2323
MARIADB_VECTOR_POOL_RECYCLE,
2424
)
25-
from open_webui.retrieval.vector.main import GetResult, SearchResult, VectorDBBase, VectorItem
25+
from open_webui.retrieval.vector.main import (
26+
GetResult,
27+
SearchResult,
28+
VectorDBBase,
29+
VectorItem,
30+
)
2631
from open_webui.retrieval.vector.utils import process_metadata
2732

2833
log = logging.getLogger(__name__)
@@ -157,8 +162,7 @@ def _init_schema(self) -> None:
157162
with conn.cursor() as cur:
158163
try:
159164
dist = self.distance_strategy
160-
cur.execute(
161-
f"""
165+
cur.execute(f"""
162166
CREATE TABLE IF NOT EXISTS document_chunk (
163167
-- MariaDB Vector requires the table PRIMARY KEY used with a VECTOR INDEX to be <= 256 bytes.
164168
-- VARCHAR has internal length/metadata overhead, so VARCHAR(255) can exceed the 256-byte limit.
@@ -173,8 +177,7 @@ def _init_schema(self) -> None:
173177
VECTOR INDEX (embedding) M={self.index_m} DISTANCE={dist},
174178
INDEX idx_document_chunk_collection_name (collection_name)
175179
) ENGINE=InnoDB;
176-
"""
177-
)
180+
""")
178181
conn.commit()
179182
except Exception as e:
180183
conn.rollback()
@@ -220,7 +223,11 @@ def _dist_fn(self) -> str:
220223
"""
221224
Return the MariaDB Vector distance function name for the configured strategy.
222225
"""
223-
return "vec_distance_cosine" if self.distance_strategy == "cosine" else "vec_distance_euclidean"
226+
return (
227+
"vec_distance_cosine"
228+
if self.distance_strategy == "cosine"
229+
else "vec_distance_euclidean"
230+
)
224231

225232
def _score_from_dist(self, dist: float) -> float:
226233
"""
@@ -442,12 +449,19 @@ def search(
442449
documents[q_idx].append(rtext)
443450
metadatas[q_idx].append(_safe_json(rmeta))
444451

445-
return SearchResult(ids=ids, distances=distances, documents=documents, metadatas=metadatas)
452+
return SearchResult(
453+
ids=ids,
454+
distances=distances,
455+
documents=documents,
456+
metadatas=metadatas,
457+
)
446458
except Exception as e:
447459
log.exception(f"[MARIADB_VECTOR] search() failed: {e}")
448460
return None
449461

450-
def query(self, collection_name: str, filter: Dict[str, Any], limit: Optional[int] = None) -> Optional[GetResult]:
462+
def query(
463+
self, collection_name: str, filter: Dict[str, Any], limit: Optional[int] = None
464+
) -> Optional[GetResult]:
451465
"""
452466
Retrieve documents by metadata filter (non-vector query).
453467
"""
@@ -472,7 +486,9 @@ def query(self, collection_name: str, filter: Dict[str, Any], limit: Optional[in
472486
metadatas = [[_safe_json(r[2]) for r in rows]]
473487
return GetResult(ids=ids, documents=documents, metadatas=metadatas)
474488

475-
def get(self, collection_name: str, limit: Optional[int] = None) -> Optional[GetResult]:
489+
def get(
490+
self, collection_name: str, limit: Optional[int] = None
491+
) -> Optional[GetResult]:
476492
"""
477493
Retrieve documents in a collection without filtering (optionally limited).
478494
"""
@@ -549,7 +565,10 @@ def has_collection(self, collection_name: str) -> bool:
549565
try:
550566
with self._connect() as conn:
551567
with conn.cursor() as cur:
552-
cur.execute("SELECT 1 FROM document_chunk WHERE collection_name = ? LIMIT 1", (collection_name,))
568+
cur.execute(
569+
"SELECT 1 FROM document_chunk WHERE collection_name = ? LIMIT 1",
570+
(collection_name,),
571+
)
553572
return cur.fetchone() is not None
554573
except Exception:
555574
return False

backend/open_webui/retrieval/vector/factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def get_vector(vector_type: str) -> VectorDBBase:
5858

5959
return OpenGaussClient()
6060
case VectorType.MARIADB_VECTOR:
61-
from open_webui.retrieval.vector.dbs.mariadb_vector import MariaDBVectorClient
61+
from open_webui.retrieval.vector.dbs.mariadb_vector import (
62+
MariaDBVectorClient,
63+
)
6264

6365
return MariaDBVectorClient()
6466
case VectorType.ELASTICSEARCH:

backend/open_webui/routers/files.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ def update_file_data_content_by_id(
583583
request,
584584
ProcessFileForm(file_id=id, content=form_data.content),
585585
user=user,
586+
db=db,
586587
)
587588
file = Files.get_file_by_id(id=id, db=db)
588589
except Exception as e:

backend/open_webui/routers/ollama.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,9 @@ async def download_file_stream(
17471747

17481748
yield f"data: {json.dumps(res)}\n\n"
17491749
else:
1750-
raise RuntimeError("Ollama: Could not create blob, Please try again.")
1750+
raise RuntimeError(
1751+
"Ollama: Could not create blob, Please try again."
1752+
)
17511753

17521754

17531755
# url = "https://huggingface.co/TheBloke/stablelm-zephyr-3b-GGUF/resolve/main/stablelm-zephyr-3b.Q2_K.gguf"

backend/open_webui/utils/oauth.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1706,7 +1706,9 @@ async def handle_callback(self, request, provider, response, db=None):
17061706
redirect_url = f"{redirect_base_url}/auth"
17071707

17081708
if error_message:
1709-
redirect_url = f"{redirect_url}?error={urllib.parse.quote_plus(error_message)}"
1709+
redirect_url = (
1710+
f"{redirect_url}?error={urllib.parse.quote_plus(error_message)}"
1711+
)
17101712
return RedirectResponse(url=redirect_url, headers=response.headers)
17111713

17121714
response = RedirectResponse(url=redirect_url, headers=response.headers)

backend/open_webui/utils/task.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def truncate_content(content: str, max_chars: int, mode: str = "middletruncate")
162162
return f"{content[:half]}...{content[-(max_chars - half):]}"
163163

164164

165-
def apply_content_filter(
166-
messages: list[dict], filter_str: str
167-
) -> list[dict]:
165+
def apply_content_filter(messages: list[dict], filter_str: str) -> list[dict]:
168166
"""Apply a content filter to each message's content.
169167
170168
filter_str is like 'middletruncate:500', 'start:200', or 'end:200'.
@@ -238,9 +236,7 @@ def replacement_function(match):
238236
else:
239237
half = mid // 2
240238
start_msgs = messages[:half]
241-
end_msgs = (
242-
messages[-half:] if mid % 2 == 0 else messages[-(half + 1) :]
243-
)
239+
end_msgs = messages[-half:] if mid % 2 == 0 else messages[-(half + 1) :]
244240
selected = start_msgs + end_msgs
245241
content_filter = middle_filter
246242
else:

backend/open_webui/utils/webhook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ async def post_webhook(name: str, url: str, message: str, event_data: dict) -> b
3232
else:
3333
user_dict = json.loads(user_data)
3434
facts = [
35-
{"name": name, "value": value}
36-
for name, value in user_dict.items()
35+
{"name": name, "value": value} for name, value in user_dict.items()
3736
]
3837
payload = {
3938
"@type": "MessageCard",

src/lib/components/chat/MessageInput/QueuedMessageItem.svelte

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,11 @@
3333
file.url?.startsWith('data') || file.url?.startsWith('http')
3434
? file.url
3535
: `${WEBUI_API_BASE_URL}/files/${file.url}${file?.content_type ? '/content' : ''}`}
36-
<Image
37-
src={fileUrl}
38-
alt=""
39-
imageClassName="size-6 rounded-md object-cover"
40-
/>
36+
<Image src={fileUrl} alt="" imageClassName="size-6 rounded-md object-cover" />
4137
{:else}
42-
<div class="flex items-center px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-gray-800 text-xs text-gray-500 dark:text-gray-400">
38+
<div
39+
class="flex items-center px-1.5 py-0.5 rounded-md bg-gray-100 dark:bg-gray-800 text-xs text-gray-500 dark:text-gray-400"
40+
>
4341
<span class="max-w-[80px] truncate">{file.name ?? 'file'}</span>
4442
</div>
4543
{/if}
@@ -50,7 +48,9 @@
5048
{#if content}
5149
<p class="text-sm text-gray-600 dark:text-gray-300 truncate">{content}</p>
5250
{:else if files.length === 0}
53-
<p class="text-sm text-gray-400 dark:text-gray-500 truncate italic">{$i18n.t('Empty message')}</p>
51+
<p class="text-sm text-gray-400 dark:text-gray-500 truncate italic">
52+
{$i18n.t('Empty message')}
53+
</p>
5454
{/if}
5555
</div>
5656

0 commit comments

Comments
 (0)