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
587a8c59
Unverified
Commit
587a8c59
authored
Mar 31, 2024
by
Timothy Jaeryang Baek
Committed by
GitHub
Mar 31, 2024
Browse files
Merge pull request #1370 from lainedfles/logging-improvements
Improve logging.
parents
4ddb7e12
144c9059
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
16 deletions
+31
-16
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
+1
-1
backend/apps/rag/main.py
backend/apps/rag/main.py
+3
-3
backend/config.py
backend/config.py
+2
-0
backend/utils/webhook.py
backend/utils/webhook.py
+9
-2
No files found.
backend/apps/images/main.py
View file @
587a8c59
...
...
@@ -325,7 +325,7 @@ def save_url_image(url):
return
image_id
except
Exception
as
e
:
print
(
f
"Error saving image:
{
e
}
"
)
log
.
exception
(
f
"Error saving image:
{
e
}
"
)
return
None
...
...
@@ -397,7 +397,7 @@ def generate_image(
user
.
id
,
app
.
state
.
COMFYUI_BASE_URL
,
)
print
(
res
)
log
.
debug
(
f
"res:
{
res
}
"
)
images
=
[]
...
...
@@ -409,7 +409,7 @@ def generate_image(
with
open
(
file_body_path
,
"w"
)
as
f
:
json
.
dump
(
data
.
model_dump
(
exclude_none
=
True
),
f
)
print
(
images
)
log
.
debug
(
f
"images:
{
images
}
"
)
return
images
else
:
if
form_data
.
model
:
...
...
backend/apps/images/utils/comfyui.py
View file @
587a8c59
...
...
@@ -4,6 +4,12 @@ import json
import
urllib.request
import
urllib.parse
import
random
import
logging
from
config
import
SRC_LOG_LEVELS
log
=
logging
.
getLogger
(
__name__
)
log
.
setLevel
(
SRC_LOG_LEVELS
[
"COMFYUI"
])
from
pydantic
import
BaseModel
...
...
@@ -121,7 +127,7 @@ COMFYUI_DEFAULT_PROMPT = """
def
queue_prompt
(
prompt
,
client_id
,
base_url
):
print
(
"queue_prompt"
)
log
.
info
(
"queue_prompt"
)
p
=
{
"prompt"
:
prompt
,
"client_id"
:
client_id
}
data
=
json
.
dumps
(
p
).
encode
(
"utf-8"
)
req
=
urllib
.
request
.
Request
(
f
"
{
base_url
}
/prompt"
,
data
=
data
)
...
...
@@ -129,7 +135,7 @@ def queue_prompt(prompt, client_id, 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
}
url_values
=
urllib
.
parse
.
urlencode
(
data
)
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):
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
}
url_values
=
urllib
.
parse
.
urlencode
(
data
)
return
f
"
{
base_url
}
/view?
{
url_values
}
"
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
:
return
json
.
loads
(
response
.
read
())
...
...
@@ -212,15 +218,15 @@ def comfyui_generate_image(
try
:
ws
=
websocket
.
WebSocket
()
ws
.
connect
(
f
"ws://
{
host
}
/ws?clientId=
{
client_id
}
"
)
print
(
"WebSocket connection established."
)
log
.
info
(
"WebSocket connection established."
)
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
try
:
images
=
get_images
(
ws
,
comfyui_prompt
,
client_id
,
base_url
)
except
Exception
as
e
:
print
(
f
"Error while receiving images:
{
e
}
"
)
log
.
exception
(
f
"Error while receiving images:
{
e
}
"
)
images
=
None
ws
.
close
()
...
...
backend/apps/ollama/main.py
View file @
587a8c59
...
...
@@ -272,7 +272,7 @@ async def pull_model(
if
request_id
in
REQUEST_POOL
:
yield
chunk
else
:
pr
in
t
(
"User: canceled request"
)
log
.
warn
in
g
(
"User: canceled request"
)
break
finally
:
if
hasattr
(
r
,
"close"
):
...
...
backend/apps/rag/main.py
View file @
587a8c59
...
...
@@ -333,7 +333,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
if
overwrite
:
for
collection
in
CHROMA_CLIENT
.
list_collections
():
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
)
collection
=
CHROMA_CLIENT
.
create_collection
(
...
...
@@ -346,7 +346,7 @@ def store_docs_in_vector_db(docs, collection_name, overwrite: bool = False) -> b
)
return
True
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
if
e
.
__class__
.
__name__
==
"UniqueConstraintError"
:
return
True
...
...
@@ -575,7 +575,7 @@ def scan_docs_dir(user=Depends(get_admin_user)):
),
)
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
pass
except
Exception
as
e
:
...
...
backend/config.py
View file @
587a8c59
...
...
@@ -119,6 +119,7 @@ log.info(f"GLOBAL_LOG_LEVEL: {GLOBAL_LOG_LEVEL}")
log_sources
=
[
"AUDIO"
,
"COMFYUI"
,
"CONFIG"
,
"DB"
,
"IMAGES"
,
...
...
@@ -128,6 +129,7 @@ log_sources = [
"OLLAMA"
,
"OPENAI"
,
"RAG"
,
"WEBHOOK"
,
]
SRC_LOG_LEVELS
=
{}
...
...
backend/utils/webhook.py
View file @
587a8c59
import
json
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
:
...
...
@@ -39,9 +44,11 @@ def post_webhook(url: str, message: str, event_data: dict) -> bool:
else
:
payload
=
{
**
event_data
}
log
.
debug
(
f
"payload:
{
payload
}
"
)
r
=
requests
.
post
(
url
,
json
=
payload
)
r
.
raise_for_status
()
log
.
debug
(
f
"r.text:
{
r
.
text
}
"
)
return
True
except
Exception
as
e
:
print
(
e
)
log
.
exception
(
e
)
return
False
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