diff --git a/application/api/user/routes.py b/application/api/user/routes.py index fa0ff382..af26f7ba 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -176,10 +176,12 @@ class SubmitFeedback(Resource): "FeedbackModel", { "question": fields.String( - required=True, description="The user question" + required=False, description="The user question" ), - "answer": fields.String(required=True, description="The AI answer"), + "answer": fields.String(required=False, description="The AI answer"), "feedback": fields.String(required=True, description="User feedback"), + "question_index":fields.Integer(required=True, description="The question number in that particular conversation"), + "conversation_id":fields.String(required=True, description="id of the particular conversation"), "api_key": fields.String(description="Optional API key"), }, ) @@ -189,23 +191,21 @@ class SubmitFeedback(Resource): ) def post(self): data = request.get_json() - required_fields = ["question", "answer", "feedback"] + required_fields = [ "feedback","conversation_id","question_index"] missing_fields = check_required_fields(data, required_fields) if missing_fields: return missing_fields - new_doc = { - "question": data["question"], - "answer": data["answer"], - "feedback": data["feedback"], - "timestamp": datetime.datetime.now(datetime.timezone.utc), - } - - if "api_key" in data: - new_doc["api_key"] = data["api_key"] - try: - feedback_collection.insert_one(new_doc) + conversations_collection.update_one( + {"_id": ObjectId(data["conversation_id"]), f"queries.{data['question_index']}": {"$exists": True}}, + { + "$set": { + f"queries.{data['question_index']}.feedback": data["feedback"] + } + } + ) + except Exception as err: return make_response(jsonify({"success": False, "error": str(err)}), 400) @@ -1801,4 +1801,4 @@ class TextToSpeech(Resource): 200, ) except Exception as err: - return make_response(jsonify({"success": False, "error": str(err)}), 400) + return make_response(jsonify({"success": False, "error": str(err)}), 400) \ No newline at end of file diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 2614104e..8a36ea5f 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -155,8 +155,22 @@ export default function Conversation() { const handleFeedback = (query: Query, feedback: FEEDBACK, index: number) => { const prevFeedback = query.feedback; dispatch(updateQuery({ index, query: { feedback } })); - handleSendFeedback(query.prompt, query.response!, feedback).catch(() => - dispatch(updateQuery({ index, query: { feedback: prevFeedback } })), + handleSendFeedback( + query.prompt, + query.response!, + feedback, + conversationId as string, + index, + ).catch(() => + handleSendFeedback( + query.prompt, + query.response!, + feedback, + conversationId as string, + index, + ).catch(() => + dispatch(updateQuery({ index, query: { feedback: prevFeedback } })), + ), ); }; diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 62e943dd..d88b249e 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -436,7 +436,8 @@ const ConversationBubble = forwardRef< feedback === 'LIKE' || type !== 'ERROR' ? 'group-hover:lg:visible' : '' - }`} + } + ${feedback === 'DISLIKE' && type !== 'ERROR' ? 'hidden' : ''}`} >