Spaces:
Sleeping
Sleeping
Commit
·
6b9cfa1
1
Parent(s):
c1a55aa
Enforced chat_name along with chat_id (#1)
Browse files- Enforced chat_name along with chat_id (c2201953887a18526296e481ed7e1016349d1f23)
Co-authored-by: Swastik <stellar413@users.noreply.huggingface.co>
- api_routes_v2.py +13 -2
api_routes_v2.py
CHANGED
|
@@ -58,6 +58,7 @@ class ChatResponse(BaseModel):
|
|
| 58 |
api_response: Dict[str, Any]
|
| 59 |
intent: Dict[str, Any]
|
| 60 |
chat_id: str
|
|
|
|
| 61 |
state: str
|
| 62 |
# REMOVED: history field (use separate endpoint to get messages)
|
| 63 |
file: Optional[bool] = None
|
|
@@ -649,6 +650,7 @@ def _assistant_response_payload(
|
|
| 649 |
|
| 650 |
# Get file metadata from session
|
| 651 |
session = session_manager.get_session(chat_id) or {}
|
|
|
|
| 652 |
file_metadata = session.get("file_metadata", {})
|
| 653 |
|
| 654 |
return ChatResponse(
|
|
@@ -661,6 +663,7 @@ def _assistant_response_payload(
|
|
| 661 |
api_response=api_data,
|
| 662 |
intent=intent,
|
| 663 |
chat_id=chat_id,
|
|
|
|
| 664 |
state=state,
|
| 665 |
file=file_metadata.get("has_file", False),
|
| 666 |
fileName=file_metadata.get("file_name"),
|
|
@@ -1689,7 +1692,11 @@ async def chat_unified_stream(
|
|
| 1689 |
|
| 1690 |
def emit(obj: Dict[str, Any]) -> bytes:
|
| 1691 |
obj.setdefault("chat_id", chat_id)
|
| 1692 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1693 |
return (json.dumps(obj, ensure_ascii=False) + "\n").encode("utf-8")
|
| 1694 |
|
| 1695 |
def stream_gen() -> Generator[bytes, None, None]:
|
|
@@ -2035,7 +2042,10 @@ async def chat_unified_stream(
|
|
| 2035 |
@router.post("/chats")
|
| 2036 |
def create_chat():
|
| 2037 |
chat_id = session_manager.create_session()
|
| 2038 |
-
|
|
|
|
|
|
|
|
|
|
| 2039 |
|
| 2040 |
# ========================
|
| 2041 |
# FILE UPLOAD (to S3, no presigned URLs) — still available
|
|
@@ -2061,6 +2071,7 @@ async def upload_file_to_chat(chat_id: str, file: UploadFile = File(...)):
|
|
| 2061 |
"presigned_expires_at": meta.get("presigned_expires_at")
|
| 2062 |
},
|
| 2063 |
"chat_id": chat_id,
|
|
|
|
| 2064 |
"next_action": "💬 Now tell me what you'd like to do with this document"
|
| 2065 |
}
|
| 2066 |
|
|
|
|
| 58 |
api_response: Dict[str, Any]
|
| 59 |
intent: Dict[str, Any]
|
| 60 |
chat_id: str
|
| 61 |
+
chat_name: Optional[str] = None
|
| 62 |
state: str
|
| 63 |
# REMOVED: history field (use separate endpoint to get messages)
|
| 64 |
file: Optional[bool] = None
|
|
|
|
| 650 |
|
| 651 |
# Get file metadata from session
|
| 652 |
session = session_manager.get_session(chat_id) or {}
|
| 653 |
+
chat_name = session.get("chat_name")
|
| 654 |
file_metadata = session.get("file_metadata", {})
|
| 655 |
|
| 656 |
return ChatResponse(
|
|
|
|
| 663 |
api_response=api_data,
|
| 664 |
intent=intent,
|
| 665 |
chat_id=chat_id,
|
| 666 |
+
chat_name=chat_name,
|
| 667 |
state=state,
|
| 668 |
file=file_metadata.get("has_file", False),
|
| 669 |
fileName=file_metadata.get("file_name"),
|
|
|
|
| 1692 |
|
| 1693 |
def emit(obj: Dict[str, Any]) -> bytes:
|
| 1694 |
obj.setdefault("chat_id", chat_id)
|
| 1695 |
+
# CHANGE: Fetch latest chat_name from session_manager to ensure it's up-to-date
|
| 1696 |
+
# (e.g. if generated during the stream)
|
| 1697 |
+
current_session = session_manager.get_session(chat_id) or {}
|
| 1698 |
+
obj.setdefault("chat_name", current_session.get("chat_name"))
|
| 1699 |
+
obj.setdefault("state", current_session.get("state", "initial"))
|
| 1700 |
return (json.dumps(obj, ensure_ascii=False) + "\n").encode("utf-8")
|
| 1701 |
|
| 1702 |
def stream_gen() -> Generator[bytes, None, None]:
|
|
|
|
| 2042 |
@router.post("/chats")
|
| 2043 |
def create_chat():
|
| 2044 |
chat_id = session_manager.create_session()
|
| 2045 |
+
session = session_manager.get_session(chat_id)
|
| 2046 |
+
return {"chat_id": chat_id,
|
| 2047 |
+
"chat_name": session.get("chat_name")
|
| 2048 |
+
}
|
| 2049 |
|
| 2050 |
# ========================
|
| 2051 |
# FILE UPLOAD (to S3, no presigned URLs) — still available
|
|
|
|
| 2071 |
"presigned_expires_at": meta.get("presigned_expires_at")
|
| 2072 |
},
|
| 2073 |
"chat_id": chat_id,
|
| 2074 |
+
"chat_name": (session_manager.get_session(chat_id) or {}).get("chat_name"),
|
| 2075 |
"next_action": "💬 Now tell me what you'd like to do with this document"
|
| 2076 |
}
|
| 2077 |
|