diff --git a/frontend/utils/feedback.py b/frontend/utils/feedback.py index 9c87ecf3..3cdf8c83 100644 --- a/frontend/utils/feedback.py +++ b/frontend/utils/feedback.py @@ -5,6 +5,9 @@ from dotenv import load_dotenv import os from typing import Optional, Any +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__)))) +from common.mongoClient import submit_feedback load_dotenv() @@ -57,6 +60,43 @@ def format_context(context: list[str]) -> str: return "\n".join(context) +def submit_feedback_to_mongoDB( + question: str, + answer: str, + sources: list[str], + context: list[str], + issue: str, + version: str, +) -> None: + """ + Submit feedback to a specific MongoDB database. + + Args: + - question (str): The question for which feedback is being submitted. + - answer (str): The generated answer to the question. + - sources (list[str]): Source data used for the answer. + - context (list[str]): Additional context from the RAG. + - issue (str): Details about the issue. + - version (str): Version information. + + Returns: + - None + """ + try: + result = submit_feedback( + question=question, + answer=answer, + sources=sources, + context=context, + issue=issue, + version=version, + ) + if not result: + st.sidebar.error("Failed to submit feedback to MongoDB") + except Exception as e: + st.sidebar.error(f"Error submitting feedback to MongoDB: {e}") + + def submit_feedback_to_google_sheet( question: str, answer: str, @@ -191,6 +231,14 @@ def show_feedback_form( issue=feedback, version=os.getenv("RAG_VERSION", get_git_commit_hash()), ) + submit_feedback_to_mongoDB( + question=selected_question, + answer=gen_ans, + sources=sources, # Now passing as list + context=context, # Now passing as list + issue=feedback, + version=os.getenv("RAG_VERSION", get_git_commit_hash()), + ) st.session_state.submitted = True