Spaces:
Running
Running
Update routes.py
Browse files
routes.py
CHANGED
@@ -108,11 +108,16 @@ def list_chats(bot_id: str):
|
|
108 |
except Exception as e:
|
109 |
raise HTTPException(status_code=500, detail=str(e))
|
110 |
|
|
|
|
|
|
|
111 |
@router.get("/chat_history/{chat_id}")
|
112 |
def chat_history(chat_id: str, bot_id: str):
|
113 |
trainer = get_trainer()
|
114 |
try:
|
115 |
history = trainer.get_chat_by_id(chat_id=chat_id)
|
116 |
-
|
|
|
117 |
except Exception as e:
|
118 |
raise HTTPException(status_code=500, detail=str(e))
|
|
|
|
108 |
except Exception as e:
|
109 |
raise HTTPException(status_code=500, detail=str(e))
|
110 |
|
111 |
+
from fastapi.encoders import jsonable_encoder
|
112 |
+
from bson import ObjectId
|
113 |
+
|
114 |
@router.get("/chat_history/{chat_id}")
|
115 |
def chat_history(chat_id: str, bot_id: str):
|
116 |
trainer = get_trainer()
|
117 |
try:
|
118 |
history = trainer.get_chat_by_id(chat_id=chat_id)
|
119 |
+
# Convert ObjectId instances to strings before returning the response.
|
120 |
+
return jsonable_encoder(history, custom_encoder={ObjectId: str})
|
121 |
except Exception as e:
|
122 |
raise HTTPException(status_code=500, detail=str(e))
|
123 |
+
|