diff --git a/README.md b/README.md index 88898907..397ae325 100644 --- a/README.md +++ b/README.md @@ -403,6 +403,23 @@ curl -X 'POST' \ }' ``` +### Create new response based on a previously created question +After utilizing the `questions` endpoint, you have the option to generate a new response associated with a specific question_id. +You can modify the `sql_query` to produce an alternative `sql_query_result` and a distinct response. In the event that you do not +specify a `sql_query`, the system will reprocess the question to generate the `sql_query`, execute the `sql_query_result`, and subsequently +generate the response. + +``` +curl -X 'POST' \ + '/api/v1/responses?run_evaluator=true&sql_response_only=false&generate_csv=false' \ + -H 'accept: application/json' \ + -H 'Content-Type: application/json' \ + -d '{ + "question_id": "11fa1e419fe93d137536fe99", + "sql_query": "select * from sales order by created_at DESC limit 10" +}' +``` + ### Run scripts Within the `scripts` folder located inside the `dataherald` directory, you have the ability to upgrade your versions. For instance, if you are currently using version 0.0.3 and wish to switch to version 0.0.4, simply execute the following command: diff --git a/dataherald/api/fastapi.py b/dataherald/api/fastapi.py index bf99cb8d..c520c340 100644 --- a/dataherald/api/fastapi.py +++ b/dataherald/api/fastapi.py @@ -492,6 +492,9 @@ def create_response( question_repository = QuestionRepository(self.storage) response_repository = ResponseRepository(self.storage) user_question = question_repository.find_by_id(query_request.question_id) + if not user_question: + raise HTTPException(status_code=404, detail="Question not found") + db_connection_repository = DatabaseConnectionRepository(self.storage) database_connection = db_connection_repository.find_by_id( user_question.db_connection_id