From 2faa819257f969a6121ddffcfb9d8ef63afa21e1 Mon Sep 17 00:00:00 2001 From: tro16 Date: Sun, 13 Oct 2024 09:02:18 +0200 Subject: [PATCH 1/4] eagr --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 32271f8087e..1cf1debf025 100644 --- a/.gitignore +++ b/.gitignore @@ -307,3 +307,5 @@ dist cypress/videos cypress/screenshots .vscode/settings.json + +npm_rebuild.sh \ No newline at end of file From 773fefc379733f2f059c1184030580a9124c0834 Mon Sep 17 00:00:00 2001 From: tro16 Date: Mon, 20 Jan 2025 20:20:16 +0100 Subject: [PATCH 2/4] making DEFAULT_PROMPT_SUGGESTIONS env var --- backend/open_webui/config.py | 119 +++++++++++++---------------------- 1 file changed, 45 insertions(+), 74 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index a6ec2e0d3ac..7e0201986e6 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -105,51 +105,6 @@ def reset_config(): "version": 0, "ui": { "default_locale": "", - "prompt_suggestions": [ - { - "title": [ - "Help me study", - "vocabulary for a college entrance exam", - ], - "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.", - }, - { - "title": [ - "Give me ideas", - "for what to do with my kids' art", - ], - "content": "What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter.", - }, - { - "title": ["Tell me a fun fact", "about the Roman Empire"], - "content": "Tell me a random fun fact about the Roman Empire", - }, - { - "title": [ - "Show me a code snippet", - "of a website's sticky header", - ], - "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.", - }, - { - "title": [ - "Explain options trading", - "if I'm familiar with buying and selling stocks", - ], - "content": "Explain options trading in simple terms if I'm familiar with buying and selling stocks.", - }, - { - "title": ["Overcome procrastination", "give me tips"], - "content": "Could you start by asking me about instances when I procrastinate the most and then give me some suggestions to overcome it?", - }, - { - "title": [ - "Grammar check", - "rewrite it for better readability ", - ], - "content": 'Check the following sentence for grammar and clarity: "[sentence]". Rewrite it for better readability while maintaining its original meaning.', - }, - ], }, } @@ -828,38 +783,54 @@ def oidc_oauth_register(client): "DEFAULT_MODELS", "ui.default_models", os.environ.get("DEFAULT_MODELS", None) ) + +class PromptSuggestionModel(BaseModel): + title: list[str] + content: str + +prompt_suggestions_default = [ + { + "title": ["Help me study", "vocabulary for a college entrance exam"], + "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.", + }, + { + "title": ["Give me ideas", "for what to do with my kids' art"], + "content": "What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter.", + }, + { + "title": ["Tell me a fun fact", "about the Roman Empire"], + "content": "Tell me a random fun fact about the Roman Empire", + }, + { + "title": ["Show me a code snippet", "of a website's sticky header"], + "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.", + }, + { + "title": [ + "Explain options trading", + "if I'm familiar with buying and selling stocks", + ], + "content": "Explain options trading in simple terms if I'm familiar with buying and selling stocks.", + }, + { + "title": ["Overcome procrastination", "give me tips"], + "content": "Could you start by asking me about instances when I procrastinate the most and then give me some suggestions to overcome it?", + }, +] + +try: + prompt_suggestions = json.loads(os.environ.get("DEFAULT_PROMPT_SUGGESTIONS", prompt_suggestions_default)) + prompt_suggestions = [ + PromptSuggestionModel(**prompt_suggestion) for prompt_suggestion in prompt_suggestions + ] +except Exception as e: + logging.error(f"Error loading DEFAULT_PROMPT_SUGGESTIONS: {e}") + prompt_suggestions = [] + DEFAULT_PROMPT_SUGGESTIONS = PersistentConfig( "DEFAULT_PROMPT_SUGGESTIONS", "ui.prompt_suggestions", - [ - { - "title": ["Help me study", "vocabulary for a college entrance exam"], - "content": "Help me study vocabulary: write a sentence for me to fill in the blank, and I'll try to pick the correct option.", - }, - { - "title": ["Give me ideas", "for what to do with my kids' art"], - "content": "What are 5 creative things I could do with my kids' art? I don't want to throw them away, but it's also so much clutter.", - }, - { - "title": ["Tell me a fun fact", "about the Roman Empire"], - "content": "Tell me a random fun fact about the Roman Empire", - }, - { - "title": ["Show me a code snippet", "of a website's sticky header"], - "content": "Show me a code snippet of a website's sticky header in CSS and JavaScript.", - }, - { - "title": [ - "Explain options trading", - "if I'm familiar with buying and selling stocks", - ], - "content": "Explain options trading in simple terms if I'm familiar with buying and selling stocks.", - }, - { - "title": ["Overcome procrastination", "give me tips"], - "content": "Could you start by asking me about instances when I procrastinate the most and then give me some suggestions to overcome it?", - }, - ], + prompt_suggestions, ) MODEL_ORDER_LIST = PersistentConfig( From b54f7ea758e0f852aa84413f7efca78a11e181fd Mon Sep 17 00:00:00 2001 From: tro16 Date: Mon, 20 Jan 2025 21:28:56 +0100 Subject: [PATCH 3/4] refactor: update PromptSuggestionModel to use Tuple for title and improve error logging --- backend/open_webui/config.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 7e0201986e6..f15f02b68bb 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -4,7 +4,7 @@ import shutil from datetime import datetime from pathlib import Path -from typing import Generic, Optional, TypeVar +from typing import Generic, Optional, TypeVar, Tuple from urllib.parse import urlparse import chromadb @@ -785,9 +785,10 @@ def oidc_oauth_register(client): class PromptSuggestionModel(BaseModel): - title: list[str] + title: Tuple[str, str] content: str + prompt_suggestions_default = [ { "title": ["Help me study", "vocabulary for a college entrance exam"], @@ -819,12 +820,15 @@ class PromptSuggestionModel(BaseModel): ] try: - prompt_suggestions = json.loads(os.environ.get("DEFAULT_PROMPT_SUGGESTIONS", prompt_suggestions_default)) + prompt_suggestions = json.loads( + os.environ.get("DEFAULT_PROMPT_SUGGESTIONS", prompt_suggestions_default) + ) prompt_suggestions = [ - PromptSuggestionModel(**prompt_suggestion) for prompt_suggestion in prompt_suggestions + PromptSuggestionModel(**prompt_suggestion) + for prompt_suggestion in prompt_suggestions ] except Exception as e: - logging.error(f"Error loading DEFAULT_PROMPT_SUGGESTIONS: {e}") + logging.error("Error loading DEFAULT_PROMPT_SUGGESTIONS: %s", e) prompt_suggestions = [] DEFAULT_PROMPT_SUGGESTIONS = PersistentConfig( From 587e546b3ca62d166afd68a70b00391b43bd555b Mon Sep 17 00:00:00 2001 From: tro16 Date: Wed, 22 Jan 2025 13:28:44 +0100 Subject: [PATCH 4/4] revert gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1cf1debf025..32271f8087e 100644 --- a/.gitignore +++ b/.gitignore @@ -307,5 +307,3 @@ dist cypress/videos cypress/screenshots .vscode/settings.json - -npm_rebuild.sh \ No newline at end of file