mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-15 13:55:19 +00:00
simplify main.py
This commit is contained in:
parent
deec41d29a
commit
22a5e196c9
1 changed files with 9 additions and 32 deletions
|
|
@ -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
|
__event_emitter__ = get_event_emitter(metadata)
|
||||||
session_id = None
|
__event_call__ = get_event_call(metadata)
|
||||||
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}
|
|
||||||
)
|
|
||||||
|
|
||||||
# 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):
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue