diff --git a/backend/apps/rag/main.py b/backend/apps/rag/main.py index fd2ebd25c..15dbcc5cb 100644 --- a/backend/apps/rag/main.py +++ b/backend/apps/rag/main.py @@ -642,8 +642,8 @@ def resolve_hostname(hostname): return ipv4_addresses, ipv6_addresses -@app.post("/websearch") -def store_websearch(form_data: SearchForm, user=Depends(get_current_user)): +@app.post("/web/search") +def store_web_search(form_data: SearchForm, user=Depends(get_current_user)): try: try: web_results = search_web(form_data.query) diff --git a/backend/config.py b/backend/config.py index cb720031e..202c75b90 100644 --- a/backend/config.py +++ b/backend/config.py @@ -574,6 +574,7 @@ ENABLE_COMMUNITY_SHARING = PersistentConfig( os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true", ) + class BannerModel(BaseModel): id: str type: str @@ -772,6 +773,8 @@ BRAVE_SEARCH_API_KEY = os.getenv("BRAVE_SEARCH_API_KEY", "") SERPSTACK_API_KEY = os.getenv("SERPSTACK_API_KEY", "") SERPSTACK_HTTPS = os.getenv("SERPSTACK_HTTPS", "True").lower() == "true" SERPER_API_KEY = os.getenv("SERPER_API_KEY", "") + + RAG_WEB_SEARCH_ENABLED = ( SEARXNG_QUERY_URL != "" or (GOOGLE_PSE_API_KEY != "" and GOOGLE_PSE_ENGINE_ID != "") @@ -779,6 +782,7 @@ RAG_WEB_SEARCH_ENABLED = ( or SERPSTACK_API_KEY != "" or SERPER_API_KEY != "" ) + RAG_WEB_SEARCH_RESULT_COUNT = int(os.getenv("RAG_WEB_SEARCH_RESULT_COUNT", "10")) RAG_WEB_SEARCH_CONCURRENT_REQUESTS = int( os.getenv("RAG_WEB_SEARCH_CONCURRENT_REQUESTS", "10") diff --git a/backend/main.py b/backend/main.py index d2d79d2c0..d9a8c07b7 100644 --- a/backend/main.py +++ b/backend/main.py @@ -365,7 +365,7 @@ async def get_app_config(): "auth": WEBUI_AUTH, "auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER), "enable_signup": webui_app.state.config.ENABLE_SIGNUP, - "enable_websearch": RAG_WEB_SEARCH_ENABLED, + "enable_web_search": RAG_WEB_SEARCH_ENABLED, "enable_image_generation": images_app.state.config.ENABLED, "enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING, "enable_admin_export": ENABLE_ADMIN_EXPORT, diff --git a/src/lib/apis/rag/index.ts b/src/lib/apis/rag/index.ts index b434b8a95..15085260b 100644 --- a/src/lib/apis/rag/index.ts +++ b/src/lib/apis/rag/index.ts @@ -519,7 +519,7 @@ export const runWebSearch = async ( query: string, collection_name?: string ): Promise => { - return await fetch(`${RAG_API_BASE_URL}/websearch`, { + return await fetch(`${RAG_API_BASE_URL}/web/search`, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index fa5280c24..d237cc58c 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -48,8 +48,7 @@ import { runWebSearch } from '$lib/apis/rag'; import Banner from '../common/Banner.svelte'; import { getUserSettings } from '$lib/apis/users'; - - + const i18n: Writable = getContext('i18n'); export let chatIdProp = ''; @@ -408,7 +407,7 @@ responseMessage.userContext = userContext; if (useWebSearch) { - await runWebSearchForPrompt(model.id, parentId, responseMessageId); + await getWebSearchResultsAsFiles(model.id, parentId, responseMessageId); } if (model?.owned_by === 'openai') { @@ -425,10 +424,15 @@ await chats.set(await getChatList(localStorage.token)); }; - const runWebSearchForPrompt = async (model: string, parentId: string, responseId: string) => { + const getWebSearchResultsAsFiles = async ( + model: string, + parentId: string, + responseId: string + ) => { const responseMessage = history.messages[responseId]; responseMessage.progress = $i18n.t('Generating search query'); messages = messages; + const searchQuery = await generateChatSearchQuery(model, parentId); if (!searchQuery) { toast.warning($i18n.t('No search query generated')); @@ -436,8 +440,10 @@ messages = messages; return; } + responseMessage.progress = $i18n.t("Searching the web for '{{searchQuery}}'", { searchQuery }); messages = messages; + const searchDocument = await runWebSearch(localStorage.token, searchQuery); if (searchDocument === undefined) { toast.warning($i18n.t('No search results found')); @@ -445,9 +451,11 @@ messages = messages; return; } + if (!responseMessage.files) { responseMessage.files = []; } + responseMessage.files.push({ collection_name: searchDocument.collection_name, name: searchQuery, @@ -1157,6 +1165,6 @@ {messages} {submitPrompt} {stopResponse} - webSearchAvailable={$config.enable_websearch ?? false} + webSearchAvailable={$config?.features.enable_web_search ?? false} /> {/if} diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 2af6575bd..310f370e7 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -46,7 +46,6 @@ export let files = []; - export let fileUploadEnabled = true; export let speechRecognitionEnabled = true; export let webSearchAvailable = false; @@ -779,37 +778,33 @@ {/if}
- {#if fileUploadEnabled} -
- - - -
- {/if} + + + + +