Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DH-5014] Fix duplicated questions #255

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions dataherald/api/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,24 @@ def answer_question(
run_evaluator: bool = True,
generate_csv: bool = False,
question_request: QuestionRequest = None,
user_question: Question | None = None,
) -> Response:
"""Takes in an English question and answers it based on content from the registered databases"""
logger.info(f"Answer question: {question_request.question}")
sql_generation = self.system.instance(SQLGenerator)
context_store = self.system.instance(ContextStore)

user_question = Question(
question=question_request.question,
db_connection_id=question_request.db_connection_id,
)

question_repository = QuestionRepository(self.storage)
user_question = question_repository.insert(user_question)
if not user_question:
user_question = Question(
question=question_request.question,
db_connection_id=question_request.db_connection_id,
)
question_repository = QuestionRepository(self.storage)
user_question = question_repository.insert(user_question)
logger.info(f"Answer question: {user_question.question}")

db_connection_repository = DatabaseConnectionRepository(self.storage)
database_connection = db_connection_repository.find_by_id(
question_request.db_connection_id
user_question.db_connection_id
)
if not database_connection:
return JSONResponse(
Expand Down Expand Up @@ -209,7 +210,7 @@ def run_and_catch_exceptions():
nonlocal result, exception
if not stop_event.is_set():
result = self.answer_question(
run_evaluator, generate_csv, question_request
run_evaluator, generate_csv, None, user_question
)

thread = threading.Thread(target=run_and_catch_exceptions)
Expand Down