Skip to content

Commit 003a820

Browse files
committed
Revert "perf: keep chat model"
1 parent 04c6480 commit 003a820

88 files changed

Lines changed: 946 additions & 1340 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.

.github/workflows/build-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Release
33
on:
44
push:
55
branches:
6-
- main # or whatever branch you want to use
6+
- master # or whatever branch you want to use
77

88
jobs:
99
release:

README.md

Lines changed: 65 additions & 192 deletions
Large diffs are not rendered by default.

backend/open_webui/config.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ def feishu_oauth_register(oauth: OAuth):
956956
ENABLE_OLLAMA_API = PersistentConfig(
957957
"ENABLE_OLLAMA_API",
958958
"ollama.enable",
959-
os.environ.get("ENABLE_OLLAMA_API", "True").lower() == "true",
959+
os.environ.get("ENABLE_OLLAMA_API", "False").lower() == "true",
960960
)
961961

962962
OLLAMA_API_BASE_URL = os.environ.get(
@@ -1114,14 +1114,14 @@ def feishu_oauth_register(oauth: OAuth):
11141114
(
11151115
False
11161116
if not WEBUI_AUTH
1117-
else os.environ.get("ENABLE_SIGNUP", "True").lower() == "true"
1117+
else os.environ.get("ENABLE_SIGNUP", "False").lower() == "true"
11181118
),
11191119
)
11201120

11211121
ENABLE_LOGIN_FORM = PersistentConfig(
11221122
"ENABLE_LOGIN_FORM",
11231123
"ui.ENABLE_LOGIN_FORM",
1124-
os.environ.get("ENABLE_LOGIN_FORM", "True").lower() == "true",
1124+
os.environ.get("ENABLE_LOGIN_FORM", "False").lower() == "true",
11251125
)
11261126

11271127

@@ -1322,11 +1322,11 @@ def feishu_oauth_register(oauth: OAuth):
13221322
)
13231323

13241324
USER_PERMISSIONS_CHAT_TTS = (
1325-
os.environ.get("USER_PERMISSIONS_CHAT_TTS", "True").lower() == "true"
1325+
os.environ.get("USER_PERMISSIONS_CHAT_TTS", "False").lower() == "true"
13261326
)
13271327

13281328
USER_PERMISSIONS_CHAT_CALL = (
1329-
os.environ.get("USER_PERMISSIONS_CHAT_CALL", "True").lower() == "true"
1329+
os.environ.get("USER_PERMISSIONS_CHAT_CALL", "False").lower() == "true"
13301330
)
13311331

13321332
USER_PERMISSIONS_CHAT_MULTIPLE_MODELS = (
@@ -1426,13 +1426,13 @@ def feishu_oauth_register(oauth: OAuth):
14261426
ENABLE_NOTES = PersistentConfig(
14271427
"ENABLE_NOTES",
14281428
"notes.enable",
1429-
os.environ.get("ENABLE_NOTES", "True").lower() == "true",
1429+
os.environ.get("ENABLE_NOTES", "False").lower() == "true",
14301430
)
14311431

14321432
ENABLE_EVALUATION_ARENA_MODELS = PersistentConfig(
14331433
"ENABLE_EVALUATION_ARENA_MODELS",
14341434
"evaluation.arena.enable",
1435-
os.environ.get("ENABLE_EVALUATION_ARENA_MODELS", "True").lower() == "true",
1435+
os.environ.get("ENABLE_EVALUATION_ARENA_MODELS", "False").lower() == "true",
14361436
)
14371437
EVALUATION_ARENA_MODELS = PersistentConfig(
14381438
"EVALUATION_ARENA_MODELS",
@@ -1475,7 +1475,7 @@ def feishu_oauth_register(oauth: OAuth):
14751475
ENABLE_COMMUNITY_SHARING = PersistentConfig(
14761476
"ENABLE_COMMUNITY_SHARING",
14771477
"ui.enable_community_sharing",
1478-
os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true",
1478+
os.environ.get("ENABLE_COMMUNITY_SHARING", "False").lower() == "true",
14791479
)
14801480

14811481
ENABLE_MESSAGE_RATING = PersistentConfig(
@@ -1595,26 +1595,49 @@ class BannerModel(BaseModel):
15951595
"task.title.prompt_template",
15961596
os.environ.get("TITLE_GENERATION_PROMPT_TEMPLATE", ""),
15971597
)
1598+
# TODO: re-enable examples after testing
1599+
# DEFAULT_TITLE_GENERATION_PROMPT_TEMPLATE = """### Task:
1600+
# Generate a concise, 3-5 word title with an emoji summarizing the chat history.
1601+
# ### Guidelines:
1602+
# - The title should clearly represent the main theme or subject of the conversation.
1603+
# - Use emojis that enhance understanding of the topic, but avoid quotation marks or special formatting.
1604+
# - Write the title in the chat's primary language; default to English if multilingual.
1605+
# - Prioritize accuracy over excessive creativity; keep it clear and simple.
1606+
# - Your entire response must consist solely of the JSON object, without any introductory or concluding text.
1607+
# - The output must be a single, raw JSON object, without any markdown code fences or other encapsulating text.
1608+
# - Ensure no conversational text, affirmations, or explanations precede or follow the raw JSON output, as this will cause direct parsing failure.
1609+
# ### Output:
1610+
# JSON format: { "title": "your concise title here" }
1611+
# ### Examples:
1612+
# - { "title": "📉 Stock Market Trends" },
1613+
# - { "title": "🍪 Perfect Chocolate Chip Recipe" },
1614+
# - { "title": "Evolution of Music Streaming" },
1615+
# - { "title": "Remote Work Productivity Tips" },
1616+
# - { "title": "Artificial Intelligence in Healthcare" },
1617+
# - { "title": "🎮 Video Game Development Insights" }
1618+
# ### Chat History:
1619+
# <chat_history>
1620+
# {{MESSAGES:END:2}}
1621+
# </chat_history>"""
15981622

15991623
DEFAULT_TITLE_GENERATION_PROMPT_TEMPLATE = """### Task:
1600-
Generate a concise, 3-5 word title with an emoji summarizing the chat history.
1624+
Generate a concise, 3-5 word title.
16011625
### Guidelines:
16021626
- The title should clearly represent the main theme or subject of the conversation.
1603-
- Use emojis that enhance understanding of the topic, but avoid quotation marks or special formatting.
1604-
- Write the title in the chat's primary language; default to English if multilingual.
1627+
- Use the primary language of the chat to write the title; if the chat contains multiple languages, generate the title in the primary language used.
16051628
- Prioritize accuracy over excessive creativity; keep it clear and simple.
16061629
- Your entire response must consist solely of the JSON object, without any introductory or concluding text.
16071630
- The output must be a single, raw JSON object, without any markdown code fences or other encapsulating text.
16081631
- Ensure no conversational text, affirmations, or explanations precede or follow the raw JSON output, as this will cause direct parsing failure.
16091632
### Output:
16101633
JSON format: { "title": "your concise title here" }
16111634
### Examples:
1612-
- { "title": "📉 Stock Market Trends" },
1613-
- { "title": "🍪 Perfect Chocolate Chip Recipe" },
1635+
- { "title": "Stock Market Trends" },
1636+
- { "title": "Perfect Chocolate Chip Recipe" },
16141637
- { "title": "Evolution of Music Streaming" },
16151638
- { "title": "Remote Work Productivity Tips" },
16161639
- { "title": "Artificial Intelligence in Healthcare" },
1617-
- { "title": "🎮 Video Game Development Insights" }
1640+
- { "title": "Video Game Development Insights" }
16181641
### Chat History:
16191642
<chat_history>
16201643
{{MESSAGES:END:2}}

backend/open_webui/env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
log.setLevel(SRC_LOG_LEVELS["CONFIG"])
113113

114-
WEBUI_NAME = os.environ.get("WEBUI_NAME", "Open WebUI")
114+
WEBUI_NAME = os.environ.get("WEBUI_NAME", "JumpServer Chat AI &")
115115
if WEBUI_NAME != "Open WebUI":
116116
WEBUI_NAME += " (Open WebUI)"
117117

backend/open_webui/jms/chat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ class ChatHandler(BaseWisp):
1818
def list(self, query: Optional[Dict[str, Any]] = None) -> List[dict]:
1919
query = self._normalize_query(query)
2020
resp = self._request("GET", CHAT_URL, query=query, action="list chats")
21-
return self._loads(resp.body)
21+
return self._loads(CHAT_URL, resp.body)
2222

2323
def retrieve(self, chat_id: str) -> dict:
2424
self._ensure_id(chat_id)
2525
path = f"{CHAT_URL}{chat_id}/"
2626
resp = self._request("GET", path, action=f"retrieve chat {chat_id}")
27-
return self._loads(resp.body)
27+
return self._loads(path, resp.body)
2828

2929
def create(self, data: Dict[str, Any]) -> dict:
3030
body = self._dumps(data)
3131
resp = self._request("POST", CHAT_URL, body=body, action="create chat")
32-
return self._loads(resp.body)
32+
return self._loads(CHAT_URL, resp.body)
3333

3434
def update(self, chat_id: Optional[str] = None, data: Dict[str, Any] = None, query: Dict[str, Any] = None) -> dict:
3535
self._ensure_id(chat_id)
3636
path = f"{CHAT_URL}{chat_id}/"
3737
body = self._dumps(data)
3838
resp = self._request("PATCH", path, query=query, body=body, action=f"update chat {chat_id}")
39-
return self._loads(resp.body)
39+
return self._loads(path, resp.body)
4040

4141
def destroy(self, chat_id: Optional[str] = None, query: Dict[str, Any] = None) -> None:
4242
"""
@@ -100,11 +100,11 @@ def _dumps(data: Dict[str, Any]) -> bytes:
100100
raise WispError(f"Failed to serialize request body: {e}") from e
101101

102102
@staticmethod
103-
def _loads(b: bytes) -> Any:
103+
def _loads(path: str, b: bytes) -> Any:
104104
try:
105105
return json.loads(b.decode("utf-8")) if b else None
106106
except (UnicodeDecodeError, json.JSONDecodeError) as e:
107-
raise WispError(f"Failed to parse response body: {e}") from e
107+
raise WispError(f"Failed to parse response body: {e} path {path}") from e
108108

109109
@staticmethod
110110
def _safe_decode(b: Optional[bytes]) -> str:

backend/open_webui/models/chats.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class ChatResponse(BaseModel):
114114
archived: bool
115115
pinned: Optional[bool] = False
116116
meta: dict = {}
117+
session_info: dict = {}
117118
folder_id: Optional[str] = None
118119

119120

@@ -150,7 +151,7 @@ def insert_new_chat(self, form_data: ChatForm, sid: str, request: Request, user:
150151
'title': form_data.chat['title'] if 'title' in form_data.chat else 'New Chat',
151152
'chat': form_data.chat,
152153
'socket_id': sid,
153-
'folder_id': form_data.folder_id,
154+
'folder_id': form_data.folder_id or '',
154155
'session_info': {
155156
'org_id': session.org_id,
156157
'asset': session.asset,
@@ -194,7 +195,7 @@ def import_chat(
194195
}
195196
)
196197

197-
result = Chat(**chat.model_dump())
198+
result = Chat(**chat)
198199
db.add(result)
199200
db.commit()
200201
db.refresh(result)
@@ -230,7 +231,7 @@ def update_chat_tags_by_id(
230231

231232
self.delete_all_tags_by_id_and_user_id(id, user.id)
232233

233-
for tag in chat.meta.get("tags", []):
234+
for tag in chat['meta'].get("tags", []):
234235
if self.count_chats_by_tag_name_and_user_id(tag, user.id) == 0:
235236
Tags.delete_tag_by_name_and_user_id(tag, user.id)
236237

@@ -315,19 +316,19 @@ def insert_shared_chat_by_chat_id(self, chat_id: str) -> Optional[ChatModel]:
315316
# Get the existing chat to share
316317
chat = db.get(Chat, chat_id)
317318
# Check if the chat is already shared
318-
if chat.share_id:
319-
return self.get_chat_by_id_and_user_id(chat.share_id, "shared")
319+
if chat['share_id']:
320+
return self.get_chat_by_id_and_user_id(chat['share_id'], "shared")
320321
# Create a new chat with the same data, but with a new ID
321322
shared_chat = ChatModel(
322323
**{
323324
"id": str(uuid.uuid4()),
324325
"user_id": f"shared-{chat_id}",
325-
"title": chat.title,
326-
"chat": chat.chat,
327-
"meta": chat.meta,
328-
"pinned": chat.pinned,
329-
"folder_id": chat.folder_id,
330-
"created_at": chat.created_at,
326+
"title": chat['title'],
327+
"chat": chat['chat'],
328+
"meta": chat['meta'],
329+
"pinned": chat['pinned'],
330+
"folder_id": chat['folder_id'],
331+
"created_at": chat['created_at'],
331332
"updated_at": int(time.time()),
332333
}
333334
)
@@ -357,11 +358,11 @@ def update_shared_chat_by_chat_id(self, chat_id: str) -> Optional[ChatModel]:
357358
if shared_chat is None:
358359
return self.insert_shared_chat_by_chat_id(chat_id)
359360

360-
shared_chat.title = chat.title
361-
shared_chat.chat = chat.chat
362-
shared_chat.meta = chat.meta
363-
shared_chat.pinned = chat.pinned
364-
shared_chat.folder_id = chat.folder_id
361+
shared_chat.title = chat['title']
362+
shared_chat.chat = chat['chat']
363+
shared_chat.meta = chat['meta']
364+
shared_chat.pinned = chat['pinned']
365+
shared_chat.folder_id = chat['folder_id']
365366
shared_chat.updated_at = int(time.time())
366367
db.commit()
367368
db.refresh(shared_chat)
@@ -702,7 +703,7 @@ def update_chat_folder_id_by_id_and_user_id(
702703
def get_chat_tags_by_id_and_user_id(self, id: str, user_id: str) -> list[TagModel]:
703704
with get_db() as db:
704705
chat = db.get(Chat, id)
705-
tags = chat.meta.get("tags", [])
706+
tags = chat['meta'].get("tags", [])
706707
return [Tags.get_tag_by_name_and_user_id(tag, user_id) for tag in tags]
707708

708709
# TODO
@@ -749,10 +750,10 @@ def add_chat_tag_by_id_and_user_id_and_tag_name(
749750
chat = db.get(Chat, _id)
750751

751752
tag_id = tag.id
752-
if tag_id not in chat.meta.get("tags", []):
753+
if tag_id not in chat['meta'].get("tags", []):
753754
chat.meta = {
754-
**chat.meta,
755-
"tags": list(set(chat.meta.get("tags", []) + [tag_id])),
755+
**chat['meta'],
756+
"tags": list(set(chat['meta'].get("tags", []) + [tag_id])),
756757
}
757758

758759
db.commit()
@@ -882,7 +883,7 @@ def delete_shared_chats_by_user_id(self, user_id: str) -> bool:
882883
try:
883884
with get_db() as db:
884885
chats_by_user = db.query(Chat).filter_by(user_id=user_id).all()
885-
shared_chat_ids = [f"shared-{chat.id}" for chat in chats_by_user]
886+
shared_chat_ids = [f"shared-{chat['id']}" for chat in chats_by_user]
886887

887888
db.query(Chat).filter(Chat.user_id.in_(shared_chat_ids)).delete()
888889
db.commit()

backend/open_webui/retrieval/models/external.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ def predict(
4949
{
5050
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
5151
"X-OpenWebUI-User-Id": user.id,
52-
"X-OpenWebUI-User-Email": user.email,
53-
"X-OpenWebUI-User-Role": user.role,
52+
"X-OpenWebUI-User-Username": user.username,
53+
"X-OpenWebUI-User-Role": 'admin',
5454
}
5555
if ENABLE_FORWARD_USER_INFO_HEADERS and user
5656
else {}

backend/open_webui/retrieval/utils.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,9 @@ def get_sources_from_items(
595595
# Chat Attached
596596
chat = Chats.get_chat_by_id(item.get("id"))
597597

598-
if chat and (user.role == "admin" or chat.user_id == user.id):
599-
messages_map = chat.chat.get("history", {}).get("messages", {})
600-
message_id = chat.chat.get("history", {}).get("currentId")
598+
if chat and (user.role == "admin" or chat['user_id'] == user.id):
599+
messages_map = chat['chat'].get("history", {}).get("messages", {})
600+
message_id = chat['chat'].get("history", {}).get("currentId")
601601

602602
if messages_map and message_id:
603603
# Reconstruct the message list in order
@@ -612,7 +612,7 @@ def get_sources_from_items(
612612
# User has access to the chat
613613
query_result = {
614614
"documents": [[message_history]],
615-
"metadatas": [[{"file_id": chat.id, "name": chat.title}]],
615+
"metadatas": [[{"file_id": chat['id'], "name": chat['title']}]],
616616
}
617617

618618
elif item.get("type") == "url":
@@ -797,6 +797,7 @@ def get_sources_from_items(
797797

798798
def get_model_path(model: str, update_model: bool = False):
799799
# Construct huggingface_hub kwargs with local_files_only to return the snapshot path
800+
return
800801
cache_dir = os.getenv("SENTENCE_TRANSFORMERS_HOME")
801802

802803
local_files_only = not update_model
@@ -861,8 +862,8 @@ def generate_openai_batch_embeddings(
861862
{
862863
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
863864
"X-OpenWebUI-User-Id": user.id,
864-
"X-OpenWebUI-User-Email": user.email,
865-
"X-OpenWebUI-User-Role": user.role,
865+
"X-OpenWebUI-User-Username": user.username,
866+
"X-OpenWebUI-User-Role": 'admin',
866867
}
867868
if ENABLE_FORWARD_USER_INFO_HEADERS and user
868869
else {}
@@ -910,8 +911,8 @@ def generate_azure_openai_batch_embeddings(
910911
{
911912
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
912913
"X-OpenWebUI-User-Id": user.id,
913-
"X-OpenWebUI-User-Email": user.email,
914-
"X-OpenWebUI-User-Role": user.role,
914+
"X-OpenWebUI-User-Username": user.username,
915+
"X-OpenWebUI-User-Role": 'admin',
915916
}
916917
if ENABLE_FORWARD_USER_INFO_HEADERS and user
917918
else {}
@@ -960,8 +961,8 @@ def generate_ollama_batch_embeddings(
960961
{
961962
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
962963
"X-OpenWebUI-User-Id": user.id,
963-
"X-OpenWebUI-User-Email": user.email,
964-
"X-OpenWebUI-User-Role": user.role,
964+
"X-OpenWebUI-User-Username": user.username,
965+
"X-OpenWebUI-User-Role": 'admin',
965966
}
966967
if ENABLE_FORWARD_USER_INFO_HEADERS
967968
else {}

backend/open_webui/routers/audio.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ async def speech(request: Request, user=Depends(get_verified_user)):
374374
{
375375
"X-OpenWebUI-User-Name": quote(user.name, safe=" "),
376376
"X-OpenWebUI-User-Id": user.id,
377-
"X-OpenWebUI-User-Email": user.email,
378-
"X-OpenWebUI-User-Role": user.role,
377+
"X-OpenWebUI-User-Username": user.username,
378+
"X-OpenWebUI-User-Role": 'admin',
379379
}
380380
if ENABLE_FORWARD_USER_INFO_HEADERS
381381
else {}

0 commit comments

Comments
 (0)