Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
4685f523
Commit
4685f523
authored
May 27, 2024
by
Timothy J. Baek
Browse files
refac
parent
73178cf5
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
38 deletions
+45
-38
backend/apps/rag/main.py
backend/apps/rag/main.py
+2
-2
backend/config.py
backend/config.py
+4
-0
backend/main.py
backend/main.py
+1
-1
src/lib/apis/rag/index.ts
src/lib/apis/rag/index.ts
+1
-1
src/lib/components/chat/Chat.svelte
src/lib/components/chat/Chat.svelte
+13
-5
src/lib/components/chat/MessageInput.svelte
src/lib/components/chat/MessageInput.svelte
+22
-27
src/lib/stores/index.ts
src/lib/stores/index.ts
+2
-2
No files found.
backend/apps/rag/main.py
View file @
4685f523
...
@@ -642,8 +642,8 @@ def resolve_hostname(hostname):
...
@@ -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
)
...
...
backend/config.py
View file @
4685f523
...
@@ -574,6 +574,7 @@ ENABLE_COMMUNITY_SHARING = PersistentConfig(
...
@@ -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", "")
...
@@ -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 = (
...
@@ -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"
)
...
...
backend/main.py
View file @
4685f523
...
@@ -365,7 +365,7 @@ async def get_app_config():
...
@@ -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
,
...
...
src/lib/apis/rag/index.ts
View file @
4685f523
...
@@ -519,7 +519,7 @@ export const runWebSearch = async (
...
@@ -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
'
,
...
...
src/lib/components/chat/Chat.svelte
View file @
4685f523
...
@@ -49,7 +49,6 @@
...
@@ -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 @@
...
@@ -408,7 +407,7 @@
responseMessage
.
userContext
=
userContext
;
responseMessage
.
userContext
=
userContext
;
if
(
useWebSearch
)
{
if
(
useWebSearch
)
{
await
run
WebSearch
ForPrompt
(
model
.
id
,
parentId
,
responseMessageId
);
await
get
WebSearch
ResultsAsFiles
(
model
.
id
,
parentId
,
responseMessageId
);
}
}
if
(
model
?.
owned_by
===
'openai'
)
{
if
(
model
?.
owned_by
===
'openai'
)
{
...
@@ -425,10 +424,15 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -1157,6 +1165,6 @@
{messages}
{messages}
{submitPrompt}
{submitPrompt}
{stopResponse}
{stopResponse}
webSearchAvailable={$config.enable_websearch ?? false}
webSearchAvailable={$config
?.features
.enable_web
_
search ?? false}
/>
/>
{/if}
{/if}
src/lib/components/chat/MessageInput.svelte
View file @
4685f523
...
@@ -46,7 +46,6 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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 @@
...
@@ -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
...
...
src/lib/stores/index.ts
View file @
4685f523
...
@@ -139,7 +139,7 @@ type Config = {
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment