@@ -75,21 +75,45 @@ class ChatSessionResponse(BaseModel):
7575 session_id : str
7676 title : str
7777
78- @app .get ("/sessions " ) #, response_model=List[ChatSessionResponse])
78+ @app .get ("/session/list " ) #, response_model=List[ChatSessionResponse])
7979def list_sessions ():
8080 """
8181 Endpoint to list all chat sessions.
8282 """
8383 try :
8484 # Query to get all sessions in the chat_session_container
85- query = "SELECT c.session_id , c.title FROM c"
85+ query = "SELECT c.id , c.title FROM c"
8686 sessions = list (chat_session_container .query_items (
8787 query = query ,
8888 enable_cross_partition_query = True
8989 ))
9090
9191 # Convert the sessions into a list of ChatSessionResponse objects
92- session_responses = [ChatSessionResponse (session_id = session ['session_id ' ], title = session ['title' ]) for session in sessions ]
92+ session_responses = [ChatSessionResponse (session_id = session ['id ' ], title = session ['title' ]) for session in sessions ]
9393 return session_responses
9494 except Exception as e :
9595 raise HTTPException (status_code = 500 , detail = f"Failed to retrieve sessions: { str (e )} " )
96+
97+ # GET /session/load/{session_id}
98+ @app .get ("/session/load/{session_id}" )
99+ def load_session (session_id : str ):
100+ """
101+ Endpoint to load a chat session by session_id.
102+ """
103+ try :
104+ # Query to get the chat session with the provided session_id
105+ query = f"SELECT * FROM c WHERE c.id = '{ session_id } '"
106+ session = list (chat_session_container .query_items (
107+ query = query ,
108+ enable_cross_partition_query = True
109+ ))
110+
111+ # If the session exists, return it
112+ if session :
113+ return session [0 ]
114+ else :
115+ raise HTTPException (status_code = 404 , detail = "Session not found" )
116+ except Exception as e :
117+ raise HTTPException (status_code = 500 , detail = f"Failed to retrieve session: { str (e )} " )
118+
119+
0 commit comments