diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index a6ec2e0d3ac..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 @@ -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,58 @@ def oidc_oauth_register(client): "DEFAULT_MODELS", "ui.default_models", os.environ.get("DEFAULT_MODELS", None) ) + +class PromptSuggestionModel(BaseModel): + title: Tuple[str, 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("Error loading DEFAULT_PROMPT_SUGGESTIONS: %s", 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(