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
7f78e584
Commit
7f78e584
authored
Mar 12, 2024
by
Timothy J. Baek
Browse files
refac: image generation error handling
parent
26a187f5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
backend/apps/images/main.py
backend/apps/images/main.py
+8
-5
No files found.
backend/apps/images/main.py
View file @
7f78e584
...
@@ -293,6 +293,7 @@ def generate_image(
...
@@ -293,6 +293,7 @@ def generate_image(
"size"
:
form_data
.
size
if
form_data
.
size
else
app
.
state
.
IMAGE_SIZE
,
"size"
:
form_data
.
size
if
form_data
.
size
else
app
.
state
.
IMAGE_SIZE
,
"response_format"
:
"b64_json"
,
"response_format"
:
"b64_json"
,
}
}
r
=
requests
.
post
(
r
=
requests
.
post
(
url
=
f
"https://api.openai.com/v1/images/generations"
,
url
=
f
"https://api.openai.com/v1/images/generations"
,
json
=
data
,
json
=
data
,
...
@@ -300,7 +301,6 @@ def generate_image(
...
@@ -300,7 +301,6 @@ def generate_image(
)
)
r
.
raise_for_status
()
r
.
raise_for_status
()
res
=
r
.
json
()
res
=
r
.
json
()
images
=
[]
images
=
[]
...
@@ -356,7 +356,10 @@ def generate_image(
...
@@ -356,7 +356,10 @@ def generate_image(
return
images
return
images
except
Exception
as
e
:
except
Exception
as
e
:
print
(
e
)
error
=
e
if
r
:
print
(
r
.
json
())
if
r
!=
None
:
raise
HTTPException
(
status_code
=
400
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(
e
))
data
=
r
.
json
()
if
"error"
in
data
:
error
=
data
[
"error"
][
"message"
]
raise
HTTPException
(
status_code
=
400
,
detail
=
ERROR_MESSAGES
.
DEFAULT
(
error
))
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