mirror of
https://git.mirrors.martin98.com/https://github.com/open-webui/open-webui
synced 2025-08-18 08:45:57 +08:00
refac
This commit is contained in:
parent
73178cf519
commit
4685f523b6
@ -642,8 +642,8 @@ def resolve_hostname(hostname):
|
|||||||
return ipv4_addresses, ipv6_addresses
|
return ipv4_addresses, ipv6_addresses
|
||||||
|
|
||||||
|
|
||||||
@app.post("/websearch")
|
@app.post("/web/search")
|
||||||
def store_websearch(form_data: SearchForm, user=Depends(get_current_user)):
|
def store_web_search(form_data: SearchForm, user=Depends(get_current_user)):
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
web_results = search_web(form_data.query)
|
web_results = search_web(form_data.query)
|
||||||
|
@ -574,6 +574,7 @@ ENABLE_COMMUNITY_SHARING = PersistentConfig(
|
|||||||
os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true",
|
os.environ.get("ENABLE_COMMUNITY_SHARING", "True").lower() == "true",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BannerModel(BaseModel):
|
class BannerModel(BaseModel):
|
||||||
id: str
|
id: str
|
||||||
type: 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_API_KEY = os.getenv("SERPSTACK_API_KEY", "")
|
||||||
SERPSTACK_HTTPS = os.getenv("SERPSTACK_HTTPS", "True").lower() == "true"
|
SERPSTACK_HTTPS = os.getenv("SERPSTACK_HTTPS", "True").lower() == "true"
|
||||||
SERPER_API_KEY = os.getenv("SERPER_API_KEY", "")
|
SERPER_API_KEY = os.getenv("SERPER_API_KEY", "")
|
||||||
|
|
||||||
|
|
||||||
RAG_WEB_SEARCH_ENABLED = (
|
RAG_WEB_SEARCH_ENABLED = (
|
||||||
SEARXNG_QUERY_URL != ""
|
SEARXNG_QUERY_URL != ""
|
||||||
or (GOOGLE_PSE_API_KEY != "" and GOOGLE_PSE_ENGINE_ID != "")
|
or (GOOGLE_PSE_API_KEY != "" and GOOGLE_PSE_ENGINE_ID != "")
|
||||||
@ -779,6 +782,7 @@ RAG_WEB_SEARCH_ENABLED = (
|
|||||||
or SERPSTACK_API_KEY != ""
|
or SERPSTACK_API_KEY != ""
|
||||||
or SERPER_API_KEY != ""
|
or SERPER_API_KEY != ""
|
||||||
)
|
)
|
||||||
|
|
||||||
RAG_WEB_SEARCH_RESULT_COUNT = int(os.getenv("RAG_WEB_SEARCH_RESULT_COUNT", "10"))
|
RAG_WEB_SEARCH_RESULT_COUNT = int(os.getenv("RAG_WEB_SEARCH_RESULT_COUNT", "10"))
|
||||||
RAG_WEB_SEARCH_CONCURRENT_REQUESTS = int(
|
RAG_WEB_SEARCH_CONCURRENT_REQUESTS = int(
|
||||||
os.getenv("RAG_WEB_SEARCH_CONCURRENT_REQUESTS", "10")
|
os.getenv("RAG_WEB_SEARCH_CONCURRENT_REQUESTS", "10")
|
||||||
|
@ -365,7 +365,7 @@ async def get_app_config():
|
|||||||
"auth": WEBUI_AUTH,
|
"auth": WEBUI_AUTH,
|
||||||
"auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER),
|
"auth_trusted_header": bool(webui_app.state.AUTH_TRUSTED_EMAIL_HEADER),
|
||||||
"enable_signup": webui_app.state.config.ENABLE_SIGNUP,
|
"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_image_generation": images_app.state.config.ENABLED,
|
||||||
"enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING,
|
"enable_community_sharing": webui_app.state.config.ENABLE_COMMUNITY_SHARING,
|
||||||
"enable_admin_export": ENABLE_ADMIN_EXPORT,
|
"enable_admin_export": ENABLE_ADMIN_EXPORT,
|
||||||
|
@ -519,7 +519,7 @@ export const runWebSearch = async (
|
|||||||
query: string,
|
query: string,
|
||||||
collection_name?: string
|
collection_name?: string
|
||||||
): Promise<SearchDocument | undefined> => {
|
): Promise<SearchDocument | undefined> => {
|
||||||
return await fetch(`${RAG_API_BASE_URL}/websearch`, {
|
return await fetch(`${RAG_API_BASE_URL}/web/search`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -49,7 +49,6 @@
|
|||||||
import Banner from '../common/Banner.svelte';
|
import Banner from '../common/Banner.svelte';
|
||||||
import { getUserSettings } from '$lib/apis/users';
|
import { getUserSettings } from '$lib/apis/users';
|
||||||
|
|
||||||
|
|
||||||
const i18n: Writable<i18nType> = getContext('i18n');
|
const i18n: Writable<i18nType> = getContext('i18n');
|
||||||
|
|
||||||
export let chatIdProp = '';
|
export let chatIdProp = '';
|
||||||
@ -408,7 +407,7 @@
|
|||||||
responseMessage.userContext = userContext;
|
responseMessage.userContext = userContext;
|
||||||
|
|
||||||
if (useWebSearch) {
|
if (useWebSearch) {
|
||||||
await runWebSearchForPrompt(model.id, parentId, responseMessageId);
|
await getWebSearchResultsAsFiles(model.id, parentId, responseMessageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model?.owned_by === 'openai') {
|
if (model?.owned_by === 'openai') {
|
||||||
@ -425,10 +424,15 @@
|
|||||||
await chats.set(await getChatList(localStorage.token));
|
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];
|
const responseMessage = history.messages[responseId];
|
||||||
responseMessage.progress = $i18n.t('Generating search query');
|
responseMessage.progress = $i18n.t('Generating search query');
|
||||||
messages = messages;
|
messages = messages;
|
||||||
|
|
||||||
const searchQuery = await generateChatSearchQuery(model, parentId);
|
const searchQuery = await generateChatSearchQuery(model, parentId);
|
||||||
if (!searchQuery) {
|
if (!searchQuery) {
|
||||||
toast.warning($i18n.t('No search query generated'));
|
toast.warning($i18n.t('No search query generated'));
|
||||||
@ -436,8 +440,10 @@
|
|||||||
messages = messages;
|
messages = messages;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
responseMessage.progress = $i18n.t("Searching the web for '{{searchQuery}}'", { searchQuery });
|
responseMessage.progress = $i18n.t("Searching the web for '{{searchQuery}}'", { searchQuery });
|
||||||
messages = messages;
|
messages = messages;
|
||||||
|
|
||||||
const searchDocument = await runWebSearch(localStorage.token, searchQuery);
|
const searchDocument = await runWebSearch(localStorage.token, searchQuery);
|
||||||
if (searchDocument === undefined) {
|
if (searchDocument === undefined) {
|
||||||
toast.warning($i18n.t('No search results found'));
|
toast.warning($i18n.t('No search results found'));
|
||||||
@ -445,9 +451,11 @@
|
|||||||
messages = messages;
|
messages = messages;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!responseMessage.files) {
|
if (!responseMessage.files) {
|
||||||
responseMessage.files = [];
|
responseMessage.files = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
responseMessage.files.push({
|
responseMessage.files.push({
|
||||||
collection_name: searchDocument.collection_name,
|
collection_name: searchDocument.collection_name,
|
||||||
name: searchQuery,
|
name: searchQuery,
|
||||||
@ -1157,6 +1165,6 @@
|
|||||||
{messages}
|
{messages}
|
||||||
{submitPrompt}
|
{submitPrompt}
|
||||||
{stopResponse}
|
{stopResponse}
|
||||||
webSearchAvailable={$config.enable_websearch ?? false}
|
webSearchAvailable={$config?.features.enable_web_search ?? false}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
|
|
||||||
export let files = [];
|
export let files = [];
|
||||||
|
|
||||||
export let fileUploadEnabled = true;
|
|
||||||
export let speechRecognitionEnabled = true;
|
export let speechRecognitionEnabled = true;
|
||||||
|
|
||||||
export let webSearchAvailable = false;
|
export let webSearchAvailable = false;
|
||||||
@ -779,8 +778,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class=" flex">
|
<div class=" flex">
|
||||||
{#if fileUploadEnabled}
|
<div class=" ml-1 flex items-center">
|
||||||
<div class=" self-end mb-2 ml-1">
|
|
||||||
<Tooltip content={$i18n.t('Upload files')}>
|
<Tooltip content={$i18n.t('Upload files')}>
|
||||||
<button
|
<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"
|
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"
|
||||||
@ -793,7 +791,7 @@
|
|||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 16 16"
|
viewBox="0 0 16 16"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
class="w-[1.2rem] h-[1.2rem]"
|
class="size-5"
|
||||||
>
|
>
|
||||||
<path
|
<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"
|
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"
|
||||||
@ -802,14 +800,11 @@
|
|||||||
</button>
|
</button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
id="chat-textarea"
|
id="chat-textarea"
|
||||||
bind:this={chatTextAreaElement}
|
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
|
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]"
|
||||||
? ''
|
|
||||||
: ' pl-4'} rounded-xl resize-none h-[48px]"
|
|
||||||
placeholder={chatInputPlaceholder !== ''
|
placeholder={chatInputPlaceholder !== ''
|
||||||
? chatInputPlaceholder
|
? chatInputPlaceholder
|
||||||
: isRecording
|
: isRecording
|
||||||
|
@ -139,7 +139,7 @@ type Config = {
|
|||||||
auth: boolean;
|
auth: boolean;
|
||||||
auth_trusted_header: boolean;
|
auth_trusted_header: boolean;
|
||||||
enable_signup: boolean;
|
enable_signup: boolean;
|
||||||
enable_websearch?: boolean;
|
enable_web_search?: boolean;
|
||||||
enable_image_generation: boolean;
|
enable_image_generation: boolean;
|
||||||
enable_admin_export: boolean;
|
enable_admin_export: boolean;
|
||||||
enable_community_sharing: boolean;
|
enable_community_sharing: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user