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
22a5e196
"...git@developer.sourcefind.cn:chenpangpang/open-webui.git" did not exist on "e5703a588fa8c178afbf8daffb17bfbb49dbb876"
Commit
22a5e196
authored
Jul 31, 2024
by
Michael Poluektov
Browse files
simplify main.py
parent
deec41d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
33 deletions
+10
-33
backend/main.py
backend/main.py
+10
-33
No files found.
backend/main.py
View file @
22a5e196
...
@@ -617,32 +617,15 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -617,32 +617,15 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
content
=
{
"detail"
:
str
(
e
)},
content
=
{
"detail"
:
str
(
e
)},
)
)
# Extract valves from the request body
metadata
=
{
valves
=
None
"chat_id"
:
body
.
pop
(
"chat_id"
,
None
),
if
"valves"
in
body
:
"message_id"
:
body
.
pop
(
"id"
,
None
),
valves
=
body
[
"valves"
]
"session_id"
:
body
.
pop
(
"session_id"
,
None
),
del
body
[
"valves"
]
"valves"
:
body
.
pop
(
"valves"
,
None
),
}
# Extract session_id, chat_id and message_id from the request body
session_id
=
None
__event_emitter__
=
get_event_emitter
(
metadata
)
if
"session_id"
in
body
:
__event_call__
=
get_event_call
(
metadata
)
session_id
=
body
[
"session_id"
]
del
body
[
"session_id"
]
chat_id
=
None
if
"chat_id"
in
body
:
chat_id
=
body
[
"chat_id"
]
del
body
[
"chat_id"
]
message_id
=
None
if
"id"
in
body
:
message_id
=
body
[
"id"
]
del
body
[
"id"
]
__event_emitter__
=
get_event_emitter
(
{
"chat_id"
:
chat_id
,
"message_id"
:
message_id
,
"session_id"
:
session_id
}
)
__event_call__
=
get_event_call
(
{
"chat_id"
:
chat_id
,
"message_id"
:
message_id
,
"session_id"
:
session_id
}
)
# Initialize data_items to store additional data to be sent to the client
# Initialize data_items to store additional data to be sent to the client
data_items
=
[]
data_items
=
[]
...
@@ -707,13 +690,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
...
@@ -707,13 +690,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
if
len
(
citations
)
>
0
:
if
len
(
citations
)
>
0
:
data_items
.
append
({
"citations"
:
citations
})
data_items
.
append
({
"citations"
:
citations
})
body
[
"metadata"
]
=
{
body
[
"metadata"
]
=
metadata
"session_id"
:
session_id
,
"chat_id"
:
chat_id
,
"message_id"
:
message_id
,
"valves"
:
valves
,
}
modified_body_bytes
=
json
.
dumps
(
body
).
encode
(
"utf-8"
)
modified_body_bytes
=
json
.
dumps
(
body
).
encode
(
"utf-8"
)
# Replace the request body with the modified one
# Replace the request body with the modified one
request
.
_body
=
modified_body_bytes
request
.
_body
=
modified_body_bytes
...
...
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