Unverified Commit 8a9c18dd authored by Timothy Jaeryang Baek's avatar Timothy Jaeryang Baek Committed by GitHub
Browse files

Merge branch 'dev' into dev

parents 2d1a890e 3729771f
import logging
import requests
from typing import List
from apps.rag.search.main import SearchResult
from config import SRC_LOG_LEVELS
......@@ -9,20 +10,52 @@ log = logging.getLogger(__name__)
log.setLevel(SRC_LOG_LEVELS["RAG"])
def search_searxng(query_url: str, query: str, count: int) -> list[SearchResult]:
"""Search a SearXNG instance for a query and return the results as a list of SearchResult objects.
def search_searxng(query_url: str, query: str, count: int, **kwargs) -> List[SearchResult]:
"""
Search a SearXNG instance for a given query and return the results as a list of SearchResult objects.
The function allows passing additional parameters such as language or time_range to tailor the search result.
Args:
query_url (str): The URL of the SearXNG instance to search. Must contain "<query>" as a placeholder
query (str): The query to search for
query_url (str): The base URL of the SearXNG server with a placeholder for the query "<query>".
query (str): The search term or question to find in the SearXNG database.
count (int): The maximum number of results to retrieve from the search.
Keyword Args:
language (str): Language filter for the search results; e.g., "en-US". Defaults to an empty string.
time_range (str): Time range for filtering results by date; e.g., "2023-04-05..today" or "all-time". Defaults to ''.
categories: (Optional[List[str]]): Specific categories within which the search should be performed, defaulting to an empty string if not provided.
Returns:
List[SearchResult]: A list of SearchResults sorted by relevance score in descending order.
Raise:
requests.exceptions.RequestException: If a request error occurs during the search process.
"""
url = query_url.replace("<query>", query)
if "&format=json" not in url:
url += "&format=json"
log.debug(f"searching {url}")
r = requests.get(
url,
# Default values for optional parameters are provided as empty strings or None when not specified.
language = kwargs.get('language', 'en-US')
time_range = kwargs.get('time_range', '')
categories = ''.join(kwargs.get('categories', []))
params = {
"q": query,
"format": "json",
"pageno": 1,
"results_per_page": count,
'language': language,
'time_range': time_range,
'engines': '',
'categories': categories,
'theme': 'simple',
'image_proxy': 0
}
log.debug(f"searching {query_url}")
response = requests.get(
query_url,
headers={
"User-Agent": "Open WebUI (https://github.com/open-webui/open-webui) RAG Bot",
"Accept": "text/html",
......@@ -30,15 +63,17 @@ def search_searxng(query_url: str, query: str, count: int) -> list[SearchResult]
"Accept-Language": "en-US,en;q=0.5",
"Connection": "keep-alive",
},
params=params,
)
r.raise_for_status()
json_response = r.json()
response.raise_for_status() # Raise an exception for HTTP errors.
json_response = response.json()
results = json_response.get("results", [])
sorted_results = sorted(results, key=lambda x: x.get("score", 0), reverse=True)
return [
SearchResult(
link=result["url"], title=result.get("title"), snippet=result.get("content")
)
for result in sorted_results[:count]
for result in sorted_results
]
......@@ -810,10 +810,7 @@
? $i18n.t('Listening...')
: $i18n.t('Send a Message')}
bind:value={prompt}
on:keypress={(e) => {}}
on:keydown={async (e) => {
// Check if the device is not a mobile device or if it is a mobile device, check if it is not a touch device
// This is to prevent the Enter key from submitting the prompt on mobile devices
on:keypress={(e) => {
if (
!$mobile ||
!(
......@@ -822,22 +819,18 @@
navigator.msMaxTouchPoints > 0
)
) {
// Check if Enter is pressed
// Check if Shift key is not pressed
// Prevent Enter key from creating a new line
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
}
if (e.key === 'Enter' && !e.shiftKey && prompt !== '') {
// Submit the prompt when Enter key is pressed
if (prompt !== '' && e.key === 'Enter' && !e.shiftKey) {
submitPrompt(prompt, user);
return;
}
if (e.key === 'Enter' && e.shiftKey && prompt !== '') {
return;
}
}
}}
on:keydown={async (e) => {
const isCtrlPressed = e.ctrlKey || e.metaKey; // metaKey is for Cmd key on Mac
// Check if Ctrl + R is pressed
......@@ -898,7 +891,9 @@
...document.getElementsByClassName('selected-command-option-button')
]?.at(-1);
if (commandOptionButton) {
if (e.shiftKey) {
prompt = `${prompt}\n`;
} else if (commandOptionButton) {
commandOptionButton?.click();
} else {
document.getElementById('send-message-button')?.click();
......
......@@ -3,6 +3,7 @@
import { user, settings } from '$lib/stores';
import { createEventDispatcher, onMount, getContext } from 'svelte';
import { toast } from 'svelte-sonner';
import Switch from '$lib/components/common/Switch.svelte';
const dispatch = createEventDispatcher();
const i18n = getContext('i18n');
......@@ -13,6 +14,7 @@
let OpenAIUrl = '';
let OpenAIKey = '';
let OpenAISpeaker = '';
let STTEngines = ['', 'openai'];
let STTEngine = '';
......@@ -20,6 +22,7 @@
let conversationMode = false;
let speechAutoSend = false;
let responseAutoPlayback = false;
let nonLocalVoices = false;
let TTSEngines = ['', 'openai'];
let TTSEngine = '';
......@@ -86,14 +89,14 @@
url: OpenAIUrl,
key: OpenAIKey,
model: model,
speaker: speaker
speaker: OpenAISpeaker
});
if (res) {
OpenAIUrl = res.OPENAI_API_BASE_URL;
OpenAIKey = res.OPENAI_API_KEY;
model = res.OPENAI_API_MODEL;
speaker = res.OPENAI_API_VOICE;
OpenAISpeaker = res.OPENAI_API_VOICE;
}
}
};
......@@ -105,6 +108,7 @@
STTEngine = $settings?.audio?.STTEngine ?? '';
TTSEngine = $settings?.audio?.TTSEngine ?? '';
nonLocalVoices = $settings.audio?.nonLocalVoices ?? false;
speaker = $settings?.audio?.speaker ?? '';
model = $settings?.audio?.model ?? '';
......@@ -122,7 +126,10 @@
OpenAIUrl = res.OPENAI_API_BASE_URL;
OpenAIKey = res.OPENAI_API_KEY;
model = res.OPENAI_API_MODEL;
speaker = res.OPENAI_API_VOICE;
OpenAISpeaker = res.OPENAI_API_VOICE;
if (TTSEngine === 'openai') {
speaker = OpenAISpeaker;
}
}
}
});
......@@ -138,8 +145,14 @@
audio: {
STTEngine: STTEngine !== '' ? STTEngine : undefined,
TTSEngine: TTSEngine !== '' ? TTSEngine : undefined,
speaker: speaker !== '' ? speaker : undefined,
model: model !== '' ? model : undefined
speaker:
(TTSEngine === 'openai' ? OpenAISpeaker : speaker) !== ''
? TTSEngine === 'openai'
? OpenAISpeaker
: speaker
: undefined,
model: model !== '' ? model : undefined,
nonLocalVoices: nonLocalVoices
}
});
dispatch('save');
......@@ -227,7 +240,7 @@
on:change={(e) => {
if (e.target.value === 'openai') {
getOpenAIVoices();
speaker = 'alloy';
OpenAISpeaker = 'alloy';
model = 'tts-1';
} else {
getWebAPIVoices();
......@@ -290,16 +303,27 @@
<select
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={speaker}
placeholder="Select a voice"
>
<option value="" selected>{$i18n.t('Default')}</option>
{#each voices.filter((v) => v.localService === true) as voice}
<option value={voice.name} class="bg-gray-100 dark:bg-gray-700">{voice.name}</option
<option value="" selected={speaker !== ''}>{$i18n.t('Default')}</option>
{#each voices.filter((v) => nonLocalVoices || v.localService === true) as voice}
<option
value={voice.name}
class="bg-gray-100 dark:bg-gray-700"
selected={speaker === voice.name}>{voice.name}</option
>
{/each}
</select>
</div>
</div>
<div class="flex items-center justify-between mb-1">
<div class="text-sm">
{$i18n.t('Allow non-local voices')}
</div>
<div class="mt-1">
<Switch bind:state={nonLocalVoices} />
</div>
</div>
</div>
{:else if TTSEngine === 'openai'}
<div>
......@@ -309,7 +333,7 @@
<input
list="voice-list"
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={speaker}
bind:value={OpenAISpeaker}
placeholder="Select a voice"
/>
......
......@@ -37,6 +37,7 @@
"All Users": "جميع المستخدمين",
"Allow": "يسمح",
"Allow Chat Deletion": "يستطيع حذف المحادثات",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "الأحرف الأبجدية الرقمية والواصلات",
"Already have an account?": "هل تملك حساب ؟",
"an assistant": "مساعد",
......@@ -206,6 +207,7 @@
"Experimental": "تجريبي",
"Export": "تصدير",
"Export All Chats (All Users)": "تصدير جميع الدردشات (جميع المستخدمين)",
"Export chat (.json)": "",
"Export Chats": "تصدير جميع الدردشات",
"Export Documents Mapping": "تصدير وثائق الخرائط",
"Export Models": "نماذج التصدير",
......
......@@ -37,6 +37,7 @@
"All Users": "Всички Потребители",
"Allow": "Позволи",
"Allow Chat Deletion": "Позволи Изтриване на Чат",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "алфанумерични знаци и тире",
"Already have an account?": "Вече имате акаунт? ",
"an assistant": "асистент",
......@@ -206,6 +207,7 @@
"Experimental": "Експериментално",
"Export": "Износ",
"Export All Chats (All Users)": "Експортване на всички чатове (За всички потребители)",
"Export chat (.json)": "",
"Export Chats": "Експортване на чатове",
"Export Documents Mapping": "Експортване на документен мапинг",
"Export Models": "Експортиране на модели",
......
......@@ -37,6 +37,7 @@
"All Users": "সব ইউজার",
"Allow": "অনুমোদন",
"Allow Chat Deletion": "চ্যাট ডিলিট করতে দিন",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "ইংরেজি অক্ষর, সংখ্যা এবং হাইফেন",
"Already have an account?": "আগে থেকেই একাউন্ট আছে?",
"an assistant": "একটা এসিস্ট্যান্ট",
......@@ -206,6 +207,7 @@
"Experimental": "পরিক্ষামূলক",
"Export": "রপ্তানি",
"Export All Chats (All Users)": "সব চ্যাট এক্সপোর্ট করুন (সব ইউজারের)",
"Export chat (.json)": "",
"Export Chats": "চ্যাটগুলো এক্সপোর্ট করুন",
"Export Documents Mapping": "ডকুমেন্টসমূহ ম্যাপিং এক্সপোর্ট করুন",
"Export Models": "রপ্তানি মডেল",
......
......@@ -37,6 +37,7 @@
"All Users": "Tots els Usuaris",
"Allow": "Permet",
"Allow Chat Deletion": "Permet la Supressió del Xat",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "caràcters alfanumèrics i guions",
"Already have an account?": "Ja tens un compte?",
"an assistant": "un assistent",
......@@ -206,6 +207,7 @@
"Experimental": "Experimental",
"Export": "Exportar",
"Export All Chats (All Users)": "Exporta Tots els Xats (Tots els Usuaris)",
"Export chat (.json)": "",
"Export Chats": "Exporta Xats",
"Export Documents Mapping": "Exporta el Mapatge de Documents",
"Export Models": "Models d'exportació",
......
......@@ -37,6 +37,7 @@
"All Users": "Ang tanan nga mga tiggamit",
"Allow": "Sa pagtugot",
"Allow Chat Deletion": "Tugoti nga mapapas ang mga chat",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "alphanumeric nga mga karakter ug hyphen",
"Already have an account?": "Naa na kay account ?",
"an assistant": "usa ka katabang",
......@@ -206,6 +207,7 @@
"Experimental": "Eksperimento",
"Export": "",
"Export All Chats (All Users)": "I-export ang tanan nga mga chat (Tanan nga tiggamit)",
"Export chat (.json)": "",
"Export Chats": "I-export ang mga chat",
"Export Documents Mapping": "I-export ang pagmapa sa dokumento",
"Export Models": "",
......
......@@ -37,6 +37,7 @@
"All Users": "Alle Benutzer",
"Allow": "Erlauben",
"Allow Chat Deletion": "Chat Löschung erlauben",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "alphanumerische Zeichen und Bindestriche",
"Already have an account?": "Hast du vielleicht schon ein Account?",
"an assistant": "ein Assistent",
......@@ -206,6 +207,7 @@
"Experimental": "Experimentell",
"Export": "Exportieren",
"Export All Chats (All Users)": "Alle Chats exportieren (alle Benutzer)",
"Export chat (.json)": "",
"Export Chats": "Chats exportieren",
"Export Documents Mapping": "Dokumentenmapping exportieren",
"Export Models": "Modelle exportieren",
......
......@@ -37,6 +37,7 @@
"All Users": "All Users",
"Allow": "Allow",
"Allow Chat Deletion": "Allow Delete Chats",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "so alpha, many hyphen",
"Already have an account?": "Such account exists?",
"an assistant": "such assistant",
......@@ -206,6 +207,7 @@
"Experimental": "Much Experiment",
"Export": "",
"Export All Chats (All Users)": "Export All Chats (All Doggos)",
"Export chat (.json)": "",
"Export Chats": "Export Barks",
"Export Documents Mapping": "Export Mappings of Dogos",
"Export Models": "",
......
......@@ -37,6 +37,7 @@
"All Users": "",
"Allow": "",
"Allow Chat Deletion": "",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "",
"Already have an account?": "",
"an assistant": "",
......@@ -206,6 +207,7 @@
"Experimental": "",
"Export": "",
"Export All Chats (All Users)": "",
"Export chat (.json)": "",
"Export Chats": "",
"Export Documents Mapping": "",
"Export Models": "",
......
......@@ -37,6 +37,7 @@
"All Users": "",
"Allow": "",
"Allow Chat Deletion": "",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "",
"Already have an account?": "",
"an assistant": "",
......@@ -206,6 +207,7 @@
"Experimental": "",
"Export": "",
"Export All Chats (All Users)": "",
"Export chat (.json)": "",
"Export Chats": "",
"Export Documents Mapping": "",
"Export Models": "",
......
......@@ -37,6 +37,7 @@
"All Users": "Todos los Usuarios",
"Allow": "Permitir",
"Allow Chat Deletion": "Permitir Borrar Chats",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "caracteres alfanuméricos y guiones",
"Already have an account?": "¿Ya tienes una cuenta?",
"an assistant": "un asistente",
......@@ -206,6 +207,7 @@
"Experimental": "Experimental",
"Export": "Exportar",
"Export All Chats (All Users)": "Exportar todos los chats (Todos los usuarios)",
"Export chat (.json)": "",
"Export Chats": "Exportar Chats",
"Export Documents Mapping": "Exportar el mapeo de documentos",
"Export Models": "Modelos de exportación",
......
......@@ -37,6 +37,7 @@
"All Users": "همه کاربران",
"Allow": "اجازه دادن",
"Allow Chat Deletion": "اجازه حذف گپ",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "حروف الفبایی و خط فاصله",
"Already have an account?": "از قبل حساب کاربری دارید؟",
"an assistant": "یک دستیار",
......@@ -206,6 +207,7 @@
"Experimental": "آزمایشی",
"Export": "صادرات",
"Export All Chats (All Users)": "اکسپورت از همه گپ\u200cها(همه کاربران)",
"Export chat (.json)": "",
"Export Chats": "اکسپورت از گپ\u200cها",
"Export Documents Mapping": "اکسپورت از نگاشت اسناد",
"Export Models": "مدل های صادرات",
......
......@@ -37,6 +37,7 @@
"All Users": "Kaikki käyttäjät",
"Allow": "Salli",
"Allow Chat Deletion": "Salli keskustelujen poisto",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "kirjaimia, numeroita ja väliviivoja",
"Already have an account?": "Onko sinulla jo tili?",
"an assistant": "avustaja",
......@@ -206,6 +207,7 @@
"Experimental": "Kokeellinen",
"Export": "Vienti",
"Export All Chats (All Users)": "Vie kaikki keskustelut (kaikki käyttäjät)",
"Export chat (.json)": "",
"Export Chats": "Vie keskustelut",
"Export Documents Mapping": "Vie asiakirjakartoitus",
"Export Models": "Vie malleja",
......
......@@ -37,6 +37,7 @@
"All Users": "Tous les utilisateurs",
"Allow": "Autoriser",
"Allow Chat Deletion": "Autoriser la suppression des discussions",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "caractères alphanumériques et tirets",
"Already have an account?": "Vous avez déjà un compte ?",
"an assistant": "un assistant",
......@@ -206,6 +207,7 @@
"Experimental": "Expérimental",
"Export": "Exportation",
"Export All Chats (All Users)": "Exporter toutes les discussions (Tous les utilisateurs)",
"Export chat (.json)": "",
"Export Chats": "Exporter les discussions",
"Export Documents Mapping": "Exporter le mappage des documents",
"Export Models": "Modèles d’exportation",
......
......@@ -37,6 +37,7 @@
"All Users": "Tous les Utilisateurs",
"Allow": "Autoriser",
"Allow Chat Deletion": "Autoriser la suppression du chat",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "caractères alphanumériques et tirets",
"Already have an account?": "Vous avez déjà un compte ?",
"an assistant": "un assistant",
......@@ -206,6 +207,7 @@
"Experimental": "Expérimental",
"Export": "Exportation",
"Export All Chats (All Users)": "Exporter Tous les Chats (Tous les Utilisateurs)",
"Export chat (.json)": "",
"Export Chats": "Exporter les Chats",
"Export Documents Mapping": "Exporter la Correspondance des Documents",
"Export Models": "Exporter les Modèles",
......
......@@ -37,6 +37,7 @@
"All Users": "כל המשתמשים",
"Allow": "אפשר",
"Allow Chat Deletion": "אפשר מחיקת צ'אט",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "תווים אלפאנומריים ומקפים",
"Already have an account?": "כבר יש לך חשבון?",
"an assistant": "עוזר",
......@@ -206,6 +207,7 @@
"Experimental": "ניסיוני",
"Export": "ייצא",
"Export All Chats (All Users)": "ייצוא כל הצ'אטים (כל המשתמשים)",
"Export chat (.json)": "",
"Export Chats": "ייצוא צ'אטים",
"Export Documents Mapping": "ייצוא מיפוי מסמכים",
"Export Models": "ייצוא מודלים",
......
......@@ -37,6 +37,7 @@
"All Users": "सभी उपयोगकर्ता",
"Allow": "अनुमति दें",
"Allow Chat Deletion": "चैट हटाने की अनुमति दें",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "अल्फ़ान्यूमेरिक वर्ण और हाइफ़न",
"Already have an account?": "क्या आपके पास पहले से एक खाता मौजूद है?",
"an assistant": "एक सहायक",
......@@ -206,6 +207,7 @@
"Experimental": "प्रयोगात्मक",
"Export": "निर्यातित माल",
"Export All Chats (All Users)": "सभी चैट निर्यात करें (सभी उपयोगकर्ताओं की)",
"Export chat (.json)": "",
"Export Chats": "चैट निर्यात करें",
"Export Documents Mapping": "निर्यात दस्तावेज़ मैपिंग",
"Export Models": "निर्यात मॉडल",
......
......@@ -37,6 +37,7 @@
"All Users": "Svi korisnici",
"Allow": "Dopusti",
"Allow Chat Deletion": "Dopusti brisanje razgovora",
"Allow non-local voices": "",
"alphanumeric characters and hyphens": "alfanumerički znakovi i crtice",
"Already have an account?": "Već imate račun?",
"an assistant": "asistent",
......@@ -206,6 +207,7 @@
"Experimental": "Eksperimentalno",
"Export": "Izvoz",
"Export All Chats (All Users)": "Izvoz svih razgovora (svi korisnici)",
"Export chat (.json)": "",
"Export Chats": "Izvoz razgovora",
"Export Documents Mapping": "Izvoz mapiranja dokumenata",
"Export Models": "Izvezi modele",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment