mirror of
https://github.com/open-webui/open-webui
synced 2025-02-20 03:48:48 +00:00
simplify main.py
This commit is contained in:
parent
deec41d29a
commit
22a5e196c9
@ -617,32 +617,15 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
||||
content={"detail": str(e)},
|
||||
)
|
||||
|
||||
# Extract valves from the request body
|
||||
valves = None
|
||||
if "valves" in body:
|
||||
valves = body["valves"]
|
||||
del body["valves"]
|
||||
metadata = {
|
||||
"chat_id": body.pop("chat_id", None),
|
||||
"message_id": body.pop("id", None),
|
||||
"session_id": body.pop("session_id", None),
|
||||
"valves": body.pop("valves", None),
|
||||
}
|
||||
|
||||
# Extract session_id, chat_id and message_id from the request body
|
||||
session_id = None
|
||||
if "session_id" in body:
|
||||
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}
|
||||
)
|
||||
__event_emitter__ = get_event_emitter(metadata)
|
||||
__event_call__ = get_event_call(metadata)
|
||||
|
||||
# Initialize data_items to store additional data to be sent to the client
|
||||
data_items = []
|
||||
@ -707,13 +690,7 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
||||
if len(citations) > 0:
|
||||
data_items.append({"citations": citations})
|
||||
|
||||
body["metadata"] = {
|
||||
"session_id": session_id,
|
||||
"chat_id": chat_id,
|
||||
"message_id": message_id,
|
||||
"valves": valves,
|
||||
}
|
||||
|
||||
body["metadata"] = metadata
|
||||
modified_body_bytes = json.dumps(body).encode("utf-8")
|
||||
# Replace the request body with the modified one
|
||||
request._body = modified_body_bytes
|
||||
|
Loading…
Reference in New Issue
Block a user