Skip to content

Commit

Permalink
Fixed the feedback issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Niharika0104 committed Nov 26, 2024
1 parent 8d8423b commit e9a2b8f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
24 changes: 14 additions & 10 deletions application/api/user/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
)
Expand All @@ -189,23 +191,25 @@ 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)

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/conversation/Conversation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ 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(() =>
handleSendFeedback(query.prompt, query.response!, feedback,conversationId as string,index).catch(() =>
dispatch(updateQuery({ index, query: { feedback: prevFeedback } })),
);
};
Expand Down
20 changes: 17 additions & 3 deletions frontend/src/conversation/ConversationBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ const ConversationBubble = forwardRef<
feedback === 'LIKE' || type !== 'ERROR'
? 'group-hover:lg:visible'
: ''
}
${
feedback === 'DISLIKE' && type !== 'ERROR'
? ' hidden'
: ''
}`}
>
<div>
Expand All @@ -445,11 +450,14 @@ const ConversationBubble = forwardRef<
isLikeClicked || feedback === 'LIKE'
? 'fill-white-3000 stroke-purple-30 dark:fill-transparent'
: 'fill-none stroke-gray-4000'
}`}
} `}
onClick={() => {
if(feedback===undefined){
console.log("liked")
handleFeedback?.('LIKE');
setIsLikeClicked(true);
setIsDislikeClicked(false);
}
}}
onMouseEnter={() => setIsLikeHovered(true)}
onMouseLeave={() => setIsLikeHovered(false)}
Expand All @@ -462,9 +470,13 @@ const ConversationBubble = forwardRef<
!isDislikeClicked ? 'lg:invisible' : ''
} ${
feedback === 'DISLIKE' || type !== 'ERROR'
? 'group-hover:lg:visible'
? ' group-hover:lg:visible'
: ''
}`}
} ${
feedback === 'LIKE' && type !== 'ERROR'
? ' hidden'
: ''
} `}
>
<div>
<div
Expand All @@ -481,9 +493,11 @@ const ConversationBubble = forwardRef<
: 'fill-none stroke-gray-4000'
}`}
onClick={() => {
if(feedback===undefined){
handleFeedback?.('DISLIKE');
setIsDislikeClicked(true);
setIsLikeClicked(false);
}
}}
onMouseEnter={() => setIsDislikeHovered(true)}
onMouseLeave={() => setIsDislikeHovered(false)}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/conversation/conversationHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,16 @@ export function handleSendFeedback(
prompt: string,
response: string,
feedback: FEEDBACK,
conversation_id:string,
prompt_index:number
) {
return conversationService
.feedback({
question: prompt,
answer: response,
feedback: feedback,
conversation_id:conversation_id,
question_index:prompt_index
})
.then((response) => {
if (response.ok) {
Expand Down

0 comments on commit e9a2b8f

Please sign in to comment.