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
1b040143
Commit
1b040143
authored
Feb 05, 2024
by
Timothy J. Baek
Browse files
feat: cache request body
parent
0b8df52c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
backend/apps/openai/main.py
backend/apps/openai/main.py
+10
-2
No files found.
backend/apps/openai/main.py
View file @
1b040143
...
...
@@ -81,10 +81,15 @@ async def speech(request: Request, user=Depends(get_current_user)):
body
=
await
request
.
body
()
filename
=
hashlib
.
sha256
(
body
).
hexdigest
()
+
".mp3"
print
(
body
)
print
(
type
(
body
))
name
=
hashlib
.
sha256
(
body
).
hexdigest
()
SPEECH_CACHE_DIR
=
Path
(
CACHE_DIR
).
joinpath
(
"./audio/speech/"
)
SPEECH_CACHE_DIR
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
file_path
=
SPEECH_CACHE_DIR
.
joinpath
(
filename
)
file_path
=
SPEECH_CACHE_DIR
.
joinpath
(
f
"
{
name
}
.mp3"
)
file_body_path
=
SPEECH_CACHE_DIR
.
joinpath
(
f
"
{
name
}
.json"
)
print
(
file_path
)
...
...
@@ -114,6 +119,9 @@ async def speech(request: Request, user=Depends(get_current_user)):
for
chunk
in
r
.
iter_content
(
chunk_size
=
8192
):
f
.
write
(
chunk
)
with
open
(
file_body_path
,
"w"
)
as
f
:
json
.
dump
(
json
.
loads
(
body
.
decode
(
"utf-8"
)),
f
)
# Return the saved file
return
FileResponse
(
file_path
)
...
...
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