Spaces:
Sleeping
Sleeping
Upload 157 files
Browse files
src/apis/controllers/__pycache__/post_controller.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/controllers/__pycache__/post_controller.cpython-311.pyc and b/src/apis/controllers/__pycache__/post_controller.cpython-311.pyc differ
|
|
|
src/apis/controllers/chat_controller.py
CHANGED
|
@@ -52,19 +52,19 @@ async def save_history(user_id, human_message, ai_message, intent):
|
|
| 52 |
{"session_id": user_id}, {"intent": intent}
|
| 53 |
)
|
| 54 |
logger.info("History updated")
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
return {"message": "History created"}
|
| 69 |
|
| 70 |
|
|
@@ -211,10 +211,10 @@ async def get_intent_function(session_id):
|
|
| 211 |
return record["intent"]
|
| 212 |
|
| 213 |
|
| 214 |
-
async def get_history_function(
|
| 215 |
-
history = chat_messages_history(
|
| 216 |
try:
|
| 217 |
-
|
| 218 |
history_messages = None
|
| 219 |
if not history_messages:
|
| 220 |
logger.info("History not found in redis")
|
|
@@ -222,9 +222,11 @@ async def get_history_function(session_id):
|
|
| 222 |
history_messages = [
|
| 223 |
i.model_dump(include=["type", "content"]) for i in history_messages
|
| 224 |
]
|
| 225 |
-
intent = await get_intent_function(
|
| 226 |
logger.info(F"INTENT {intent}")
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
history_messages = eval(history_messages)
|
| 229 |
return history_messages
|
| 230 |
except Exception as e:
|
|
|
|
| 52 |
{"session_id": user_id}, {"intent": intent}
|
| 53 |
)
|
| 54 |
logger.info("History updated")
|
| 55 |
+
history_cache = await get_key_redis(f"chat_history_{user_id}")
|
| 56 |
+
if history_cache is not None:
|
| 57 |
+
history_cache = eval(history_cache)
|
| 58 |
+
history_cache["message"] = (
|
| 59 |
+
history_cache["message"] + messages_add_to_history_dict
|
| 60 |
+
)
|
| 61 |
+
history_cache["intent"] = intent
|
| 62 |
+
await set_key_redis(
|
| 63 |
+
f"chat_history_{user_id}",
|
| 64 |
+
str(history_cache),
|
| 65 |
+
)
|
| 66 |
+
return {"message": "History updated"}
|
| 67 |
+
await set_key_redis(f"chat_history_{user_id}", str(messages_add_to_history_cache))
|
| 68 |
return {"message": "History created"}
|
| 69 |
|
| 70 |
|
|
|
|
| 211 |
return record["intent"]
|
| 212 |
|
| 213 |
|
| 214 |
+
async def get_history_function(user_id, background_tasks: BackgroundTasks):
|
| 215 |
+
history = chat_messages_history(user_id, 50)
|
| 216 |
try:
|
| 217 |
+
history_messages = await get_key_redis(f"chat_history_{user_id}")
|
| 218 |
history_messages = None
|
| 219 |
if not history_messages:
|
| 220 |
logger.info("History not found in redis")
|
|
|
|
| 222 |
history_messages = [
|
| 223 |
i.model_dump(include=["type", "content"]) for i in history_messages
|
| 224 |
]
|
| 225 |
+
intent = await get_intent_function(user_id)
|
| 226 |
logger.info(F"INTENT {intent}")
|
| 227 |
+
result = {"message": history_messages, "intent": intent}
|
| 228 |
+
background_tasks.add_task(set_key_redis, f"chat_history_{user_id}", str(result))
|
| 229 |
+
return result
|
| 230 |
history_messages = eval(history_messages)
|
| 231 |
return history_messages
|
| 232 |
except Exception as e:
|
src/apis/models/__pycache__/post_models.cpython-311.pyc
CHANGED
|
Binary files a/src/apis/models/__pycache__/post_models.cpython-311.pyc and b/src/apis/models/__pycache__/post_models.cpython-311.pyc differ
|
|
|
src/apis/models/post_models.py
CHANGED
|
@@ -18,7 +18,6 @@ class Comment(BaseDocument):
|
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
-
|
| 22 |
class Reaction(BaseDocument):
|
| 23 |
user_id: str = Field("", description="User's id")
|
| 24 |
post_id: str = Field("", description="Post's id")
|
|
|
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
|
|
|
| 21 |
class Reaction(BaseDocument):
|
| 22 |
user_id: str = Field("", description="User's id")
|
| 23 |
post_id: str = Field("", description="Post's id")
|
src/apis/routes/chat_route.py
CHANGED
|
@@ -47,10 +47,10 @@ async def get_chat_history(user: user_dependency, background_tasks: BackgroundTa
|
|
| 47 |
if user is None:
|
| 48 |
return JSONResponse(content={"message": "User not found"}, status_code=404)
|
| 49 |
user_id = user["id"]
|
| 50 |
-
result = await get_history_function(user_id)
|
| 51 |
if result is None:
|
| 52 |
return JSONResponse(content={"message": [], "intent": None}, status_code=500)
|
| 53 |
-
|
| 54 |
return JSONResponse(content=result, status_code=200)
|
| 55 |
|
| 56 |
|
|
|
|
| 47 |
if user is None:
|
| 48 |
return JSONResponse(content={"message": "User not found"}, status_code=404)
|
| 49 |
user_id = user["id"]
|
| 50 |
+
result = await get_history_function(user_id, background_tasks)
|
| 51 |
if result is None:
|
| 52 |
return JSONResponse(content={"message": [], "intent": None}, status_code=500)
|
| 53 |
+
background_tasks.add_task(set_key_redis, f"chat_history_{user_id}", str(result))
|
| 54 |
return JSONResponse(content=result, status_code=200)
|
| 55 |
|
| 56 |
|
src/apis/routes/post_router.py
CHANGED
|
@@ -67,12 +67,12 @@ async def get_post(post_id: str):
|
|
| 67 |
|
| 68 |
@router.get("/list", status_code=status.HTTP_200_OK)
|
| 69 |
async def list_all_posts(background_tasks: BackgroundTasks):
|
| 70 |
-
|
| 71 |
result = None
|
| 72 |
result = eval(result) if result else None
|
| 73 |
if not result:
|
| 74 |
result = await list_all_posts_controller()
|
| 75 |
-
|
| 76 |
if result["status"] == "error":
|
| 77 |
return JSONResponse(content=result, status_code=404)
|
| 78 |
else:
|
|
|
|
| 67 |
|
| 68 |
@router.get("/list", status_code=status.HTTP_200_OK)
|
| 69 |
async def list_all_posts(background_tasks: BackgroundTasks):
|
| 70 |
+
result = await get_key_redis("all_posts")
|
| 71 |
result = None
|
| 72 |
result = eval(result) if result else None
|
| 73 |
if not result:
|
| 74 |
result = await list_all_posts_controller()
|
| 75 |
+
background_tasks.add_task(set_key_redis, "all_posts", str(result),20)
|
| 76 |
if result["status"] == "error":
|
| 77 |
return JSONResponse(content=result, status_code=404)
|
| 78 |
else:
|