mominah commited on
Commit
4a4df8f
·
verified ·
1 Parent(s): adca0cc

Update routes.py

Browse files
Files changed (1) hide show
  1. routes.py +6 -1
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
- return history
 
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
+