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
edeff20e
Unverified
Commit
edeff20e
authored
Mar 31, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Mar 31, 2024
Browse files
Merge pull request #1374 from open-webui/dev
fix
parents
86aa2ca6
eda157e3
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
60 additions
and
33 deletions
+60
-33
.github/workflows/format-backend.yaml
.github/workflows/format-backend.yaml
+1
-1
Makefile
Makefile
+2
-0
backend/apps/images/main.py
backend/apps/images/main.py
+3
-3
backend/apps/images/utils/comfyui.py
backend/apps/images/utils/comfyui.py
+13
-7
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+2
-2
backend/apps/rag/main.py
backend/apps/rag/main.py
+3
-3
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+2
-0
backend/config.py
backend/config.py
+2
-0
backend/main.py
backend/main.py
+8
-5
backend/utils/webhook.py
backend/utils/webhook.py
+9
-2
package.json
package.json
+1
-0
src/app.css
src/app.css
+4
-0
src/routes/(app)/+page.svelte
src/routes/(app)/+page.svelte
+5
-5
src/routes/(app)/c/[id]/+page.svelte
src/routes/(app)/c/[id]/+page.svelte
+5
-5
No files found.
.github/workflows/format-backend.yaml
View file @
edeff20e
...
@@ -33,7 +33,7 @@ jobs:
...
@@ -33,7 +33,7 @@ jobs:
pip install black
pip install black
-
name
:
Format backend
-
name
:
Format backend
run
:
black . --exclude "/venv/"
run
:
npm run format:backend
-
name
:
Check for changes after format
-
name
:
Check for changes after format
run
:
git diff --exit-code
run
:
git diff --exit-code
Makefile
View file @
edeff20e
...
@@ -8,6 +8,8 @@ remove:
...
@@ -8,6 +8,8 @@ remove:
start
:
start
:
@
docker-compose start
@
docker-compose start
startAndBuild
:
docker-compose up
-d
--build
stop
:
stop
:
@
docker-compose stop
@
docker-compose stop
...
...
backend/apps/images/main.py
View file @
edeff20e
...
@@ -325,7 +325,7 @@ def save_url_image(url):
...
@@ -325,7 +325,7 @@ def save_url_image(url):
return
image_id
return
image_id
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"Error saving image:
{
e
}
"
)
log
.
exception
(
f
"Error saving image:
{
e
}
"
)
return
None
return
None
...
@@ -397,7 +397,7 @@ def generate_image(
...
@@ -397,7 +397,7 @@ def generate_image(
user
.
id
,
user
.
id
,
app
.
state
.
COMFYUI_BASE_URL
,
app
.
state
.
COMFYUI_BASE_URL
,
)
)
print
(
res
)
log
.
debug
(
f
"res:
{
res
}
"
)
images
=
[]
images
=
[]
...
@@ -409,7 +409,7 @@ def generate_image(
...
@@ -409,7 +409,7 @@ def generate_image(
with
open
(
file_body_path
,
"w"
)
as
f
:
with
open
(
file_body_path
,
"w"
)
as
f
:
json
.
dump
(
data
.
model_dump
(
exclude_none
=
True
),
f
)
json
.
dump
(
data
.
model_dump
(
exclude_none
=
True
),
f
)
print
(
images
)
log
.
debug
(
f
"images:
{
images
}
"
)
return
images
return
images
else
:
else
:
if
form_data
.
model
:
if
form_data
.
model
:
...
...
backend/apps/images/utils/comfyui.py
View file @
edeff20e
...
@@ -4,6 +4,12 @@ import json
...
@@ -4,6 +4,12 @@ import json
import
urllib.request
import
urllib.request
import
urllib.parse
import
urllib.parse
import
random
import
random
import
logging
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"COMFYUI"
])
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
...
@@ -121,7 +127,7 @@ COMFYUI_DEFAULT_PROMPT = """
...
@@ -121,7 +127,7 @@ COMFYUI_DEFAULT_PROMPT = """
def
queue_prompt
(
prompt
,
client_id
,
base_url
):
def
queue_prompt
(
prompt
,
client_id
,
base_url
):
print
(
"queue_prompt"
)
log
.
info
(
"queue_prompt"
)
p
=
{
"prompt"
:
prompt
,
"client_id"
:
client_id
}
p
=
{
"prompt"
:
prompt
,
"client_id"
:
client_id
}
data
=
json
.
dumps
(
p
).
encode
(
"utf-8"
)
data
=
json
.
dumps
(
p
).
encode
(
"utf-8"
)
req
=
urllib
.
request
.
Request
(
f
"
{
base_url
}
/prompt"
,
data
=
data
)
req
=
urllib
.
request
.
Request
(
f
"
{
base_url
}
/prompt"
,
data
=
data
)
...
@@ -129,7 +135,7 @@ def queue_prompt(prompt, client_id, base_url):
...
@@ -129,7 +135,7 @@ def queue_prompt(prompt, client_id, base_url):
def
get_image
(
filename
,
subfolder
,
folder_type
,
base_url
):
def
get_image
(
filename
,
subfolder
,
folder_type
,
base_url
):
print
(
"get_image"
)
log
.
info
(
"get_image"
)
data
=
{
"filename"
:
filename
,
"subfolder"
:
subfolder
,
"type"
:
folder_type
}
data
=
{
"filename"
:
filename
,
"subfolder"
:
subfolder
,
"type"
:
folder_type
}
url_values
=
urllib
.
parse
.
urlencode
(
data
)
url_values
=
urllib
.
parse
.
urlencode
(
data
)
with
urllib
.
request
.
urlopen
(
f
"
{
base_url
}
/view?
{
url_values
}
"
)
as
response
:
with
urllib
.
request
.
urlopen
(
f
"
{
base_url
}
/view?
{
url_values
}
"
)
as
response
:
...
@@ -137,14 +143,14 @@ def get_image(filename, subfolder, folder_type, base_url):
...
@@ -137,14 +143,14 @@ def get_image(filename, subfolder, folder_type, base_url):
def
get_image_url
(
filename
,
subfolder
,
folder_type
,
base_url
):
def
get_image_url
(
filename
,
subfolder
,
folder_type
,
base_url
):
print
(
"get_image"
)
log
.
info
(
"get_image"
)
data
=
{
"filename"
:
filename
,
"subfolder"
:
subfolder
,
"type"
:
folder_type
}
data
=
{
"filename"
:
filename
,
"subfolder"
:
subfolder
,
"type"
:
folder_type
}
url_values
=
urllib
.
parse
.
urlencode
(
data
)
url_values
=
urllib
.
parse
.
urlencode
(
data
)
return
f
"
{
base_url
}
/view?
{
url_values
}
"
return
f
"
{
base_url
}
/view?
{
url_values
}
"
def
get_history
(
prompt_id
,
base_url
):
def
get_history
(
prompt_id
,
base_url
):
print
(
"get_history"
)
log
.
info
(
"get_history"
)
with
urllib
.
request
.
urlopen
(
f
"
{
base_url
}
/history/
{
prompt_id
}
"
)
as
response
:
with
urllib
.
request
.
urlopen
(
f
"
{
base_url
}
/history/
{
prompt_id
}
"
)
as
response
:
return
json
.
loads
(
response
.
read
())
return
json
.
loads
(
response
.
read
())
...
@@ -212,15 +218,15 @@ def comfyui_generate_image(
...
@@ -212,15 +218,15 @@ def comfyui_generate_image(
try
:
try
:
ws
=
websocket
.
WebSocket
()
ws
=
websocket
.
WebSocket
()
ws
.
connect
(
f
"ws://
{
host
}
/ws?clientId=
{
client_id
}
"
)
ws
.
connect
(
f
"ws://
{
host
}
/ws?clientId=
{
client_id
}
"
)
print
(
"WebSocket connection established."
)
log
.
info
(
"WebSocket connection established."
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"Failed to connect to WebSocket server:
{
e
}
"
)
log
.
exception
(
f
"Failed to connect to WebSocket server:
{
e
}
"
)
return
None
return
None
try
:
try
:
images
=
get_images
(
ws
,
comfyui_prompt
,
client_id
,
base_url
)
images
=
get_images
(
ws
,
comfyui_prompt
,
client_id
,
base_url
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"Error while receiving images:
{
e
}
"
)
log
.
exception
(
f
"Error while receiving images:
{
e
}
"
)
images
=
None
images
=
None
ws
.
close
()
ws
.
close
()
...
...
backend/apps/ollama/main.py
View file @
edeff20e
...
@@ -272,7 +272,7 @@ async def pull_model(
...
@@ -272,7 +272,7 @@ async def pull_model(
if
request_id
in
REQUEST_POOL
:
if
request_id
in
REQUEST_POOL
:
yield
chunk
yield
chunk
else
:
else
:
pr
in
t
(
"User: canceled request"
)
log
.
warn
in
g
(
"User: canceled request"
)
break
break
finally
:
finally
:
if
hasattr
(
r
,
"close"
):
if
hasattr
(
r
,
"close"
):
...
@@ -670,7 +670,7 @@ async def generate_completion(
...
@@ -670,7 +670,7 @@ async def generate_completion(
else
:
else
:
raise
HTTPException
(
raise
HTTPException
(
status_code
=
400
,
status_code
=
400
,
detail
=
"err
or_d
e
ta
il"
,
detail
=
ERROR_MESSAGES
.
MODEL_NOT_FOUND
(
f
or
m
_d
a
ta
.
model
)
,
)
)
url
=
app
.
state
.
OLLAMA_BASE_URLS
[
url_idx
]
url
=
app
.
state
.
OLLAMA_BASE_URLS
[
url_idx
]
...
...
backend/apps/rag/main.py
View file @
edeff20e
...
@@ -333,7 +333,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
...
@@ -333,7 +333,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
if
overwrite
:
if
overwrite
:
for
collection
in
CHROMA_CLIENT
.
list_collections
():
for
collection
in
CHROMA_CLIENT
.
list_collections
():
if
collection_name
==
collection
.
name
:
if
collection_name
==
collection
.
name
:
print
(
f
"deleting existing collection
{
collection_name
}
"
)
log
.
info
(
f
"deleting existing collection
{
collection_name
}
"
)
CHROMA_CLIENT
.
delete_collection
(
name
=
collection_name
)
CHROMA_CLIENT
.
delete_collection
(
name
=
collection_name
)
collection
=
CHROMA_CLIENT
.
create_collection
(
collection
=
CHROMA_CLIENT
.
create_collection
(
...
@@ -346,7 +346,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
...
@@ -346,7 +346,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
)
)
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
if
e
.
__class__
.
__name__
==
"UniqueConstraintError"
:
if
e
.
__class__
.
__name__
==
"UniqueConstraintError"
:
return
True
return
True
...
@@ -575,7 +575,7 @@ def scan_docs_dir(user=Depends(get_admin_user)):
...
@@ -575,7 +575,7 @@ def scan_docs_dir(user=Depends(get_admin_user)):
),
),
)
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
pass
pass
except
Exception
as
e
:
except
Exception
as
e
:
...
...
backend/apps/rag/utils.py
View file @
edeff20e
...
@@ -156,6 +156,8 @@ def rag_messages(docs, messages, template, k, embedding_function):
...
@@ -156,6 +156,8 @@ def rag_messages(docs, messages, template, k, embedding_function):
relevant_contexts
.
append
(
context
)
relevant_contexts
.
append
(
context
)
log
.
debug
(
f
"relevant_contexts:
{
relevant_contexts
}
"
)
context_string
=
""
context_string
=
""
for
context
in
relevant_contexts
:
for
context
in
relevant_contexts
:
if
context
:
if
context
:
...
...
backend/config.py
View file @
edeff20e
...
@@ -119,6 +119,7 @@ log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")
...
@@ -119,6 +119,7 @@ log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")
log_sources
=
[
log_sources
=
[
"AUDIO"
,
"AUDIO"
,
"COMFYUI"
,
"CONFIG"
,
"CONFIG"
,
"DB"
,
"DB"
,
"IMAGES"
,
"IMAGES"
,
...
@@ -128,6 +129,7 @@ log_sources = [
...
@@ -128,6 +129,7 @@ log_sources = [
"OLLAMA"
,
"OLLAMA"
,
"OPENAI"
,
"OPENAI"
,
"RAG"
,
"RAG"
,
"WEBHOOK"
,
]
]
SRC_LOG_LEVELS
=
{}
SRC_LOG_LEVELS
=
{}
...
...
backend/main.py
View file @
edeff20e
...
@@ -164,15 +164,18 @@ app.mount("/rag/api/v1", rag_app)
...
@@ -164,15 +164,18 @@ app.mount("/rag/api/v1", rag_app)
@
app
.
get
(
"/api/config"
)
@
app
.
get
(
"/api/config"
)
async
def
get_app_config
():
async
def
get_app_config
():
# Checking and Handling the Absence of 'ui' in CONFIG_DATA
default_locale
=
"en-US"
if
"ui"
in
CONFIG_DATA
:
default_locale
=
CONFIG_DATA
[
"ui"
].
get
(
"default_locale"
,
"en-US"
)
# The Rest of the Function Now Uses the Variables Defined Above
return
{
return
{
"status"
:
True
,
"status"
:
True
,
"name"
:
WEBUI_NAME
,
"name"
:
WEBUI_NAME
,
"version"
:
VERSION
,
"version"
:
VERSION
,
"default_locale"
:
(
"default_locale"
:
default_locale
,
CONFIG_DATA
[
"ui"
][
"default_locale"
]
if
"ui"
in
CONFIG_DATA
and
"default_locale"
in
CONFIG_DATA
[
"ui"
]
else
"en-US"
),
"images"
:
images_app
.
state
.
ENABLED
,
"images"
:
images_app
.
state
.
ENABLED
,
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_models"
:
webui_app
.
state
.
DEFAULT_MODELS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
"default_prompt_suggestions"
:
webui_app
.
state
.
DEFAULT_PROMPT_SUGGESTIONS
,
...
...
backend/utils/webhook.py
View file @
edeff20e
import
json
import
json
import
requests
import
requests
from
config
import
VERSION
,
WEBUI_FAVICON_URL
,
WEBUI_NAME
import
logging
from
config
import
SRC_LOG_LEVELS
,
VERSION
,
WEBUI_FAVICON_URL
,
WEBUI_NAME
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"WEBHOOK"
])
def
post_webhook
(
url
:
str
,
message
:
str
,
event_data
:
dict
)
->
bool
:
def
post_webhook
(
url
:
str
,
message
:
str
,
event_data
:
dict
)
->
bool
:
...
@@ -39,9 +44,11 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
...
@@ -39,9 +44,11 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
else
:
else
:
payload
=
{
**
event_data
}
payload
=
{
**
event_data
}
log
.
debug
(
f
"payload:
{
payload
}
"
)
r
=
requests
.
post
(
url
,
json
=
payload
)
r
=
requests
.
post
(
url
,
json
=
payload
)
r
.
raise_for_status
()
r
.
raise_for_status
()
log
.
debug
(
f
"r.text:
{
r
.
text
}
"
)
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
return
False
return
False
package.json
View file @
edeff20e
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
"lint:types"
:
"npm run check"
,
"lint:types"
:
"npm run check"
,
"lint:backend"
:
"pylint backend/"
,
"lint:backend"
:
"pylint backend/"
,
"format"
:
"prettier --plugin-search-dir --write '**/*.{js,ts,svelte,css,md,html,json}'"
,
"format"
:
"prettier --plugin-search-dir --write '**/*.{js,ts,svelte,css,md,html,json}'"
,
"format:backend"
:
"black . --exclude
\"
/venv/
\"
"
,
"i18n:parse"
:
"i18next --config i18next-parser.config.ts && prettier --write 'src/lib/i18n/**/*.{js,json}'"
"i18n:parse"
:
"i18next --config i18next-parser.config.ts && prettier --write 'src/lib/i18n/**/*.{js,json}'"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
...
...
src/app.css
View file @
edeff20e
...
@@ -78,3 +78,7 @@ select {
...
@@ -78,3 +78,7 @@ select {
/* for Chrome */
/* for Chrome */
-webkit-appearance
:
none
;
-webkit-appearance
:
none
;
}
}
.katex-mathml
{
display
:
none
;
}
src/routes/(app)/+page.svelte
View file @
edeff20e
...
@@ -520,11 +520,6 @@
...
@@ -520,11 +520,6 @@
const
sendPromptOpenAI
=
async
(
model
,
userPrompt
,
responseMessageId
,
_chatId
)
=>
{
const
sendPromptOpenAI
=
async
(
model
,
userPrompt
,
responseMessageId
,
_chatId
)
=>
{
const
responseMessage
=
history
.
messages
[
responseMessageId
];
const
responseMessage
=
history
.
messages
[
responseMessageId
];
//
Wait
until
history
/
message
have
been
updated
await
tick
();
scrollToBottom
();
const
docs
=
messages
const
docs
=
messages
.
filter
((
message
)
=>
message
?.
files
??
null
)
.
filter
((
message
)
=>
message
?.
files
??
null
)
.
map
((
message
)
=>
.
map
((
message
)
=>
...
@@ -593,6 +588,11 @@
...
@@ -593,6 +588,11 @@
:
`${
OPENAI_API_BASE_URL
}`
:
`${
OPENAI_API_BASE_URL
}`
);
);
//
Wait
until
history
/
message
have
been
updated
await
tick
();
scrollToBottom
();
if
(
res
&&
res
.
ok
)
{
if
(
res
&&
res
.
ok
)
{
const
reader
=
res
.
body
const
reader
=
res
.
body
.
pipeThrough
(
new
TextDecoderStream
())
.
pipeThrough
(
new
TextDecoderStream
())
...
...
src/routes/(app)/c/[id]/+page.svelte
View file @
edeff20e
...
@@ -536,11 +536,6 @@
...
@@ -536,11 +536,6 @@
const
sendPromptOpenAI
=
async
(
model
,
userPrompt
,
responseMessageId
,
_chatId
)
=>
{
const
sendPromptOpenAI
=
async
(
model
,
userPrompt
,
responseMessageId
,
_chatId
)
=>
{
const
responseMessage
=
history
.
messages
[
responseMessageId
];
const
responseMessage
=
history
.
messages
[
responseMessageId
];
//
Wait
until
history
/
message
have
been
updated
await
tick
();
scrollToBottom
();
const
docs
=
messages
const
docs
=
messages
.
filter
((
message
)
=>
message
?.
files
??
null
)
.
filter
((
message
)
=>
message
?.
files
??
null
)
.
map
((
message
)
=>
.
map
((
message
)
=>
...
@@ -607,6 +602,11 @@
...
@@ -607,6 +602,11 @@
:
`${
OPENAI_API_BASE_URL
}`
:
`${
OPENAI_API_BASE_URL
}`
);
);
//
Wait
until
history
/
message
have
been
updated
await
tick
();
scrollToBottom
();
if
(
res
&&
res
.
ok
)
{
if
(
res
&&
res
.
ok
)
{
const
reader
=
res
.
body
const
reader
=
res
.
body
.
pipeThrough
(
new
TextDecoderStream
())
.
pipeThrough
(
new
TextDecoderStream
())
...
...
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