Browse Source

Merge pull request #5699 from open-webui/dev

0.3.29
Timothy Jaeryang Baek 7 tháng trước cách đây
mục cha
commit
82cda6e522

+ 9 - 0
CHANGELOG.md

@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
 The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 
+## [0.3.29] - 2023-09-25
+
+### Fixed
+
+- **🔧 KaTeX Rendering Improvement**: Resolved specific corner cases in KaTeX rendering to enhance the display of complex mathematical notation.
+- **📞 'Call' URL Parameter Fix**: Corrected functionality for 'call' URL search parameter ensuring reliable activation of voice calls through URL triggers.
+- **🔄 Configuration Reset Fix**: Fixed the RESET_CONFIG_ON_START to ensure settings revert to default correctly upon each startup, improving reliability in configuration management.
+- **🌍 Filter Outlet Hook Fix**: Addressed issues in the filter outlet hook, ensuring all filter functions operate as intended.
+
 ## [0.3.28] - 2024-09-24
 ## [0.3.28] - 2024-09-24
 
 
 ### Fixed
 ### Fixed

+ 6 - 0
backend/open_webui/config.py

@@ -87,6 +87,12 @@ def save_to_db(data):
         db.commit()
         db.commit()
 
 
 
 
+def reset_config():
+    with get_db() as db:
+        db.query(Config).delete()
+        db.commit()
+
+
 # When initializing, check if config.json exists and migrate it to the database
 # When initializing, check if config.json exists and migrate it to the database
 if os.path.exists(f"{DATA_DIR}/config.json"):
 if os.path.exists(f"{DATA_DIR}/config.json"):
     data = load_json_config()
     data = load_json_config()

+ 4 - 12
backend/open_webui/env.py

@@ -234,18 +234,6 @@ if FROM_INIT_PY:
     ).resolve()
     ).resolve()
 
 
 
 
-RESET_CONFIG_ON_START = (
-    os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
-)
-
-if RESET_CONFIG_ON_START:
-    try:
-        os.remove(f"{DATA_DIR}/config.json")
-        with open(f"{DATA_DIR}/config.json", "w") as f:
-            f.write("{}")
-    except Exception:
-        pass
-
 ####################################
 ####################################
 # Database
 # Database
 ####################################
 ####################################
@@ -265,6 +253,10 @@ if "postgres://" in DATABASE_URL:
     DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://")
     DATABASE_URL = DATABASE_URL.replace("postgres://", "postgresql://")
 
 
 
 
+RESET_CONFIG_ON_START = (
+    os.environ.get("RESET_CONFIG_ON_START", "False").lower() == "true"
+)
+
 ####################################
 ####################################
 # WEBUI_AUTH (Required for security)
 # WEBUI_AUTH (Required for security)
 ####################################
 ####################################

+ 5 - 0
backend/open_webui/main.py

@@ -79,6 +79,7 @@ from open_webui.config import (
     WEBUI_NAME,
     WEBUI_NAME,
     AppConfig,
     AppConfig,
     run_migrations,
     run_migrations,
+    reset_config,
 )
 )
 from open_webui.constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES
 from open_webui.constants import ERROR_MESSAGES, TASKS, WEBHOOK_MESSAGES
 from open_webui.env import (
 from open_webui.env import (
@@ -92,6 +93,7 @@ from open_webui.env import (
     WEBUI_SESSION_COOKIE_SAME_SITE,
     WEBUI_SESSION_COOKIE_SAME_SITE,
     WEBUI_SESSION_COOKIE_SECURE,
     WEBUI_SESSION_COOKIE_SECURE,
     WEBUI_URL,
     WEBUI_URL,
+    RESET_CONFIG_ON_START,
 )
 )
 from fastapi import (
 from fastapi import (
     Depends,
     Depends,
@@ -187,6 +189,9 @@ https://github.com/open-webui/open-webui
 async def lifespan(app: FastAPI):
 async def lifespan(app: FastAPI):
     run_migrations()
     run_migrations()
 
 
+    if RESET_CONFIG_ON_START:
+        reset_config()
+
     asyncio.create_task(periodic_usage_pool_cleanup())
     asyncio.create_task(periodic_usage_pool_cleanup())
     yield
     yield
 
 

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
 	"name": "open-webui",
 	"name": "open-webui",
-	"version": "0.3.28",
+	"version": "0.3.29",
 	"lockfileVersion": 3,
 	"lockfileVersion": 3,
 	"requires": true,
 	"requires": true,
 	"packages": {
 	"packages": {
 		"": {
 		"": {
 			"name": "open-webui",
 			"name": "open-webui",
-			"version": "0.3.28",
+			"version": "0.3.29",
 			"dependencies": {
 			"dependencies": {
 				"@codemirror/lang-javascript": "^6.2.2",
 				"@codemirror/lang-javascript": "^6.2.2",
 				"@codemirror/lang-python": "^6.1.6",
 				"@codemirror/lang-python": "^6.1.6",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
 	"name": "open-webui",
 	"name": "open-webui",
-	"version": "0.3.28",
+	"version": "0.3.29",
 	"private": true,
 	"private": true,
 	"scripts": {
 	"scripts": {
 		"dev": "npm run pyodide:fetch && vite dev --host",
 		"dev": "npm run pyodide:fetch && vite dev --host",

+ 19 - 17
src/lib/components/chat/Chat.svelte

@@ -357,6 +357,7 @@
 
 
 		if ($page.url.searchParams.get('call') === 'true') {
 		if ($page.url.searchParams.get('call') === 'true') {
 			showCallOverlay.set(true);
 			showCallOverlay.set(true);
+			showControls.set(true);
 		}
 		}
 
 
 		selectedModels = selectedModels.map((modelId) =>
 		selectedModels = selectedModels.map((modelId) =>
@@ -482,11 +483,12 @@
 			}
 			}
 		}
 		}
 
 
+		await tick();
+
 		if ($chatId == chatId) {
 		if ($chatId == chatId) {
 			if (!$temporaryChatEnabled) {
 			if (!$temporaryChatEnabled) {
 				chat = await updateChatById(localStorage.token, chatId, {
 				chat = await updateChatById(localStorage.token, chatId, {
 					models: selectedModels,
 					models: selectedModels,
-					messages: messages,
 					history: history,
 					history: history,
 					params: params,
 					params: params,
 					files: chatFiles
 					files: chatFiles
@@ -1133,13 +1135,6 @@
 					}
 					}
 				}
 				}
 			}
 			}
-
-			await chatCompletedHandler(
-				_chatId,
-				model.id,
-				responseMessageId,
-				createMessagesList(responseMessageId)
-			);
 		} else {
 		} else {
 			if (res !== null) {
 			if (res !== null) {
 				const error = await res.json();
 				const error = await res.json();
@@ -1168,11 +1163,18 @@
 					(status) => status.action !== 'knowledge_search'
 					(status) => status.action !== 'knowledge_search'
 				);
 				);
 			}
 			}
-
-			history.messages[responseMessageId] = responseMessage;
 		}
 		}
 		await saveChatHandler(_chatId);
 		await saveChatHandler(_chatId);
 
 
+		history.messages[responseMessageId] = responseMessage;
+
+		await chatCompletedHandler(
+			_chatId,
+			model.id,
+			responseMessageId,
+			createMessagesList(responseMessageId)
+		);
+
 		stopResponseFlag = false;
 		stopResponseFlag = false;
 		await tick();
 		await tick();
 
 
@@ -1429,13 +1431,6 @@
 					}
 					}
 				}
 				}
 
 
-				await chatCompletedHandler(
-					_chatId,
-					model.id,
-					responseMessageId,
-					createMessagesList(responseMessageId)
-				);
-
 				if ($settings.notificationEnabled && !document.hasFocus()) {
 				if ($settings.notificationEnabled && !document.hasFocus()) {
 					const notification = new Notification(`${model.id}`, {
 					const notification = new Notification(`${model.id}`, {
 						body: responseMessage.content,
 						body: responseMessage.content,
@@ -1463,6 +1458,13 @@
 
 
 		history.messages[responseMessageId] = responseMessage;
 		history.messages[responseMessageId] = responseMessage;
 
 
+		await chatCompletedHandler(
+			_chatId,
+			model.id,
+			responseMessageId,
+			createMessagesList(responseMessageId)
+		);
+
 		stopResponseFlag = false;
 		stopResponseFlag = false;
 		await tick();
 		await tick();
 
 

+ 17 - 12
src/lib/utils/marked/katex-extension.ts

@@ -1,14 +1,13 @@
 import katex from 'katex';
 import katex from 'katex';
 
 
 const DELIMITER_LIST = [
 const DELIMITER_LIST = [
-	{ left: '$$\n', right: '\n$$', display: true },
-	{ left: '$$', right: '$$', display: false }, // This should be on top to prevent conflict with $ delimiter
+	{ left: '$$', right: '$$', display: true },
 	{ left: '$', right: '$', display: false },
 	{ left: '$', right: '$', display: false },
 	{ left: '\\pu{', right: '}', display: false },
 	{ left: '\\pu{', right: '}', display: false },
 	{ left: '\\ce{', right: '}', display: false },
 	{ left: '\\ce{', right: '}', display: false },
 	{ left: '\\(', right: '\\)', display: false },
 	{ left: '\\(', right: '\\)', display: false },
-	{ left: '\\[\n', right: '\n\\]', display: true },
-	{ left: '\\[', right: '\\]', display: false }
+	{ left: '\\[', right: '\\]', display: true },
+	{ left: '\\begin{equation}', right: '\\end{equation}', display: true }
 ];
 ];
 
 
 // const DELIMITER_LIST = [
 // const DELIMITER_LIST = [
@@ -34,14 +33,21 @@ function generateRegexRules(delimiters) {
 		const escapedRight = escapeRegex(right);
 		const escapedRight = escapeRegex(right);
 
 
 		if (!display) {
 		if (!display) {
+			// For inline delimiters, we match everyting
 			inlinePatterns.push(`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`);
 			inlinePatterns.push(`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`);
 		} else {
 		} else {
-			blockPatterns.push(`${escapedLeft}((?:\\\\[^]|[^\\\\])+?)${escapedRight}`);
+			// Block delimiters doubles as inline delimiters when not followed by a newline
+			inlinePatterns.push(`${escapedLeft}(?!\\n)((?:\\\\[^]|[^\\\\])+?)(?!\\n)${escapedRight}`);
+			blockPatterns.push(`${escapedLeft}\\n((?:\\\\[^]|[^\\\\])+?)\\n${escapedRight}`);
 		}
 		}
 	});
 	});
 
 
-	const inlineRule = new RegExp(`^(${inlinePatterns.join('|')})(?=[\\s?!.,:?!。,:]|$)`, 'u');
-	const blockRule = new RegExp(`^(${blockPatterns.join('|')})(?=[\\s?!.,:?!。,:]|$)`, 'u');
+	// Math formulas can end in special characters
+	const inlineRule = new RegExp(
+		`^(${inlinePatterns.join('|')})(?=[\\s?。,!-\/:-@[-\`{-~]|$)`,
+		'u'
+	);
+	const blockRule = new RegExp(`^(${blockPatterns.join('|')})(?=[\\s?。,!-\/:-@[-\`{-~]|$)`, 'u');
 
 
 	return { inlineRule, blockRule };
 	return { inlineRule, blockRule };
 }
 }
@@ -50,10 +56,7 @@ const { inlineRule, blockRule } = generateRegexRules(DELIMITER_LIST);
 
 
 export default function (options = {}) {
 export default function (options = {}) {
 	return {
 	return {
-		extensions: [
-			blockKatex(options), // This should be on top to prevent conflict with inline delimiters.
-			inlineKatex(options)
-		]
+		extensions: [inlineKatex(options), blockKatex(options)]
 	};
 	};
 }
 }
 
 
@@ -86,7 +89,9 @@ function katexStart(src, displayMode: boolean) {
 			return;
 			return;
 		}
 		}
 
 
-		const f = index === 0 || indexSrc.charAt(index - 1) === ' ';
+		// Check if the delimiter is preceded by a special character.
+		// If it does, then it's potentially a math formula.
+		const f = index === 0 || indexSrc.charAt(index - 1).match(/[\s?。,!-\/:-@[-`{-~]/);
 		if (f) {
 		if (f) {
 			const possibleKatex = indexSrc.substring(index);
 			const possibleKatex = indexSrc.substring(index);