redhairedshanks1 commited on
Commit
65b8488
·
1 Parent(s): 9becbae

Update api_routes_v2.py

Browse files
Files changed (1) hide show
  1. api_routes_v2.py +31 -2
api_routes_v2.py CHANGED
@@ -1879,12 +1879,41 @@ def get_chat(chat_id: str):
1879
  }
1880
 
1881
 
1882
- @router.get("/chats/{chat_id}/history", response_model=List[Message])
 
 
 
 
 
 
 
1883
  def get_chat_history(chat_id: str):
 
 
 
 
 
 
 
 
 
1884
  s = session_manager.get_session(chat_id)
1885
  if not s:
1886
  raise HTTPException(status_code=404, detail="Chat not found")
1887
- return [m.dict() for m in _normalize_history_for_api(chat_id)]
 
 
 
 
 
 
 
 
 
 
 
 
 
1888
 
1889
 
1890
  @router.get("/chats/{chat_id}/stats")
 
1879
  }
1880
 
1881
 
1882
+ # @router.get("/chats/{chat_id}/history", response_model=List[Message])
1883
+ # def get_chat_history(chat_id: str):
1884
+ # s = session_manager.get_session(chat_id)
1885
+ # if not s:
1886
+ # raise HTTPException(status_code=404, detail="Chat not found")
1887
+ # return [m.dict() for m in _normalize_history_for_api(chat_id)]
1888
+
1889
+ @router.get("/chats/{chat_id}/history", response_model=Dict[str, Any])
1890
  def get_chat_history(chat_id: str):
1891
+ """
1892
+ Get conversation history for a specific chat
1893
+
1894
+ Args:
1895
+ chat_id: Chat identifier
1896
+
1897
+ Returns:
1898
+ Chat history with session ID included
1899
+ """
1900
  s = session_manager.get_session(chat_id)
1901
  if not s:
1902
  raise HTTPException(status_code=404, detail="Chat not found")
1903
+
1904
+ # Get the normalized history
1905
+ history = [m.dict() for m in _normalize_history_for_api(chat_id)]
1906
+
1907
+ # Return with session_id included
1908
+ return {
1909
+ "session_id": chat_id, # chat_id is the session_id in this context
1910
+ "chat_id": chat_id, # Keep for backward compatibility
1911
+ "history": history,
1912
+ "count": len(history),
1913
+ "state": s.get("state", "initial"),
1914
+ "created_at": s.get("created_at"),
1915
+ "updated_at": s.get("updated_at")
1916
+ }
1917
 
1918
 
1919
  @router.get("/chats/{chat_id}/stats")