|
@@ -617,32 +617,15 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
|
|
content={"detail": str(e)},
|
|
content={"detail": str(e)},
|
|
)
|
|
)
|
|
|
|
|
|
- # Extract valves from the request body
|
|
|
|
- valves = None
|
|
|
|
- if "valves" in body:
|
|
|
|
- valves = body["valves"]
|
|
|
|
- del body["valves"]
|
|
|
|
-
|
|
|
|
- # 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}
|
|
|
|
- )
|
|
|
|
|
|
+ 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),
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ __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
|
|
# 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"] = {
|
|
|
|
- "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")
|
|
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
|