You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AI Copilot - Flask App API Endpoints Documentation
This documentation provides an overview of the routes in a Flask application that interacts with OpenAI's GPT models and Azure's translation services. The application handles generating questions, reframing questions, checking answers, and translating content.
Response JSON: { "q_dict": { "additional_documents": "What are some examples of additional documents that may be required? (e.g. extract Khatauni, affidavit, original sale deed)" } }
POST /generate_draft
Generates a draft response based on the provided JSON schema.
Request: JSON
current_json: The current JSON object that needs to be processed.
Response: JSON
eng_draft_path: Path to the English draft text file.
hin_draft_path: Path to the translated Hindi draft text file.
AI Copilot - Flask App API Endpoints Documentation
This documentation provides an overview of the routes in a Flask application that interacts with OpenAI's GPT models and Azure's translation services. The application handles generating questions, reframing questions, checking answers, and translating content.
Table of Contents
POST /generate_draft
POST /reframe_q
POST /check_ans
POST /generate_q
Setup
To set up the application, ensure you have the necessary environment variables and dependencies.
Install the required packages:
Copy code
pip install flask openai python-dotenv requests
Set the necessary environment variables in a
.env
file:makefile
Copy code
AZURE_SUBSCRIPTION_KEY=your_azure_subscription_key
OPENAI_API_KEY=your_openai_key
Routes
POST /generate_q
Generates initial questions based on the provided schema path.
schema_path
: Path to the JSON schema file.q_dict
: Dictionary of generated questions.current_json
: Null or empty JSON object based on the schema.expected_dict_ans
: Dictionary of expected answers.Example:
Request JSON:
{ "schema_path": "schemaNexamples.json" }
Response JSON:
{ "current_json": { "additional_documents": [], "affidavit_submitted": null, "annulment_exists": null, "tehsil": null }, "expected_dict_ans": { "additional_documents": { "example": [ "extract Khatauni", "affidavit", "original sale deed" ], "items": { "type": "string" }, "type": "array" }, "affidavit_submitted": { "example": [ true, false ], "type": "boolean" }, "annulment_exists": { "example": [ true, false ], "type": "boolean" }, "tehsil": { "example": [ "Sadar Tehsil", "Sadar", "Tehsil Sadar" ], "type": "string" } }, "q_dict": { "additional_documents": "What are the additional documents submitted?", "affidavit_submitted": "Was an affidavit submitted?", "annulment_exists": "Does annulment of the case exist?", "annulment_order_date": "On what date was the annulment ordered?", } }
POST /check_ans
Checks and updates the current JSON object with the provided answers by user.
q_dict
: Dictionary of questions.expected_dict_ans
: Dictionary of expected answers.current_json
: The current JSON object.user_ans
: The user's answers in Hindi.q_dict_unans
: Dictionary of unanswered questions.current_json
: Updated current JSON object.expected_dict_ans
: Dictionary of expected answers for the unanswered questions.Example:
Request JSON:
{ "current_json": { "additional_documents": [], "affidavit_submitted": null, "annulment_exists": null, "tehsil": null }, "expected_dict_ans": { "additional_documents": { "example": [ "extract Khatauni", "affidavit", "original sale deed" ], "items": { "type": "string" }, "type": "array" }, "affidavit_submitted": { "example": [ true, false ], "type": "boolean" }, "annulment_exists": { "example": [ true, false ], "type": "boolean" }, "tehsil": { "example": [ "Sadar Tehsil", "Sadar", "Tehsil Sadar" ], "type": "string" } }, "q_dict": { "additional_documents": "What are the additional documents submitted?", "affidavit_submitted": "Was an affidavit submitted?", "annulment_exists": "Does annulment of the case exist?", "tehsil": "Which Tehsil does the land belong to?" }, "user_ans": { "tehsil": "सदर तहसील", "annulment_exists": true, "affidavit_submitted": true, "additional_documents": [], } }
Response JSON:
{ "current_json": { "additional_documents": [], "affidavit_submitted": true, "annulment_exists": true, "tehsil": "Sadar Tehsil" }, "expected_dict_ans": { "additional_documents": { "example": [ "extract Khatauni", "affidavit", "original sale deed" ], "items": { "type": "string" }, "type": "array" } } }, "q_dict_unans": { "additional_documents": "What are the additional documents submitted?", } }
POST /reframe_q
Reframes the unanswered questions based on the expected answers.
Q_dict_unans
: Dictionary of unanswered questions.expected_dict_ans
: Dictionary of expected answers for the unanswered questions.q_dict
: Dictionary of reframed questions.Example:
Request JSON:
{ "q_dict_unans": { "additional_documents": "What are the additional documents submitted?" }, "expected_dict_ans": { "additional_documents": { "example": [ "extract Khatauni", "affidavit", "original sale deed" ], "items": { "type": "string" }, "type": "array" } } }
Response JSON:
{ "q_dict": { "additional_documents": "What are some examples of additional documents that may be required? (e.g. extract Khatauni, affidavit, original sale deed)" } }
POST /generate_draft
Generates a draft response based on the provided JSON schema.
current_json
: The current JSON object that needs to be processed.eng_draft_path
: Path to the English draft text file.hin_draft_path
: Path to the translated Hindi draft text file.Example:
Request JSON:
{ "current_json": { "additional_documents": [ "extract khatauuni", "affidavit", "Original Sale Deed" ], "affidavit_submitted": true, "annulment_exists": true, "tehsil": "Sadar Tehsil" } }
Response JSON:
{ "eng_draft_path": "Draft.txt", "hin_draft_path": "DraftTranslated.txt" }
Helper Functions
load_json(file_path)
: Loads a JSON file from the specified file path.generate_questions(schema_path)
: Generates questions based on a JSON schema.fill_JSON_schema(user_ans_str, already_filled_str)
: Fills values in the current JSON schema based on user input.reframe_Q(Q_dict_earlier, expected_dict_ans)
: Reframes questions based on expected answers.convert_q(q_str)
: Converts questions from English to Hindi.convert_ans(hin_ans)
: Converts answers from Hindi to English.print_q(q_str)
: Prints questions.print_ans(ans_str)
: Prints answers.check_dict(d, q_dict, expected)
: Checks the dictionary for unanswered questions.create_null_json(input_json_path)
: Creates a null or empty JSON object based on the input schema.These helper functions are used internally by the routes to process and manage the JSON data.
The text was updated successfully, but these errors were encountered: