mirror of
https://github.com/open-webui/open-webui
synced 2025-01-18 00:30:51 +00:00
refac
This commit is contained in:
parent
73178cf519
commit
4685f523b6
@ -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)
|
||||
|
@ -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")
|
||||
|
@ -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,
|
||||
|
@ -519,7 +519,7 @@ export const runWebSearch = async (
|
||||
query: string,
|
||||
collection_name?: string
|
||||
): Promise<SearchDocument | undefined> => {
|
||||
return await fetch(`${RAG_API_BASE_URL}/websearch`, {
|
||||
return await fetch(`${RAG_API_BASE_URL}/web/search`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
@ -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<i18nType> = 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}
|
||||
|
@ -46,7 +46,6 @@
|
||||
|
||||
export let files = [];
|
||||
|
||||
export let fileUploadEnabled = true;
|
||||
export let speechRecognitionEnabled = true;
|
||||
|
||||
export let webSearchAvailable = false;
|
||||
@ -779,37 +778,33 @@
|
||||
{/if}
|
||||
|
||||
<div class=" flex">
|
||||
{#if fileUploadEnabled}
|
||||
<div class=" self-end mb-2 ml-1">
|
||||
<Tooltip content={$i18n.t('Upload files')}>
|
||||
<button
|
||||
class="bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:text-white dark:hover:bg-gray-800 transition rounded-full p-1.5"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
filesInputElement.click();
|
||||
}}
|
||||
<div class=" ml-1 flex items-center">
|
||||
<Tooltip content={$i18n.t('Upload files')}>
|
||||
<button
|
||||
class="bg-gray-50 hover:bg-gray-100 text-gray-800 dark:bg-gray-850 dark:text-white dark:hover:bg-gray-800 transition rounded-full p-1.5"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
filesInputElement.click();
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="size-5"
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="w-[1.2rem] h-[1.2rem]"
|
||||
>
|
||||
<path
|
||||
d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
{/if}
|
||||
<path
|
||||
d="M8.75 3.75a.75.75 0 0 0-1.5 0v3.5h-3.5a.75.75 0 0 0 0 1.5h3.5v3.5a.75.75 0 0 0 1.5 0v-3.5h3.5a.75.75 0 0 0 0-1.5h-3.5v-3.5Z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<textarea
|
||||
id="chat-textarea"
|
||||
bind:this={chatTextAreaElement}
|
||||
class="scrollbar-hidden bg-gray-50 dark:bg-gray-850 dark:text-gray-100 outline-none w-full py-3 px-3 {fileUploadEnabled
|
||||
? ''
|
||||
: ' pl-4'} rounded-xl resize-none h-[48px]"
|
||||
class="scrollbar-hidden bg-gray-50 dark:bg-gray-850 dark:text-gray-100 outline-none w-full py-3 px-3 rounded-xl resize-none h-[48px]"
|
||||
placeholder={chatInputPlaceholder !== ''
|
||||
? chatInputPlaceholder
|
||||
: isRecording
|
||||
|
@ -138,8 +138,8 @@ type Config = {
|
||||
features: {
|
||||
auth: boolean;
|
||||
auth_trusted_header: boolean;
|
||||
enable_signup: boolean;
|
||||
enable_websearch?: boolean;
|
||||
enable_signup: boolean;
|
||||
enable_web_search?: boolean;
|
||||
enable_image_generation: boolean;
|
||||
enable_admin_export: boolean;
|
||||
enable_community_sharing: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user