Skip to content

Commit

Permalink
[DH-5014] Fix duplicated questions (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcjc712 authored Nov 17, 2023
1 parent f5b237a commit b81e7e0
Showing 1 changed file with 11 additions and 10 deletions.
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

0 comments on commit b81e7e0

Please sign in to comment.