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

AI Copilot API Endpoints Documentation #21

Open
Grinzypino opened this issue Jul 9, 2024 · 0 comments
Open

AI Copilot API Endpoints Documentation #21

Grinzypino opened this issue Jul 9, 2024 · 0 comments

Comments

@Grinzypino
Copy link
Contributor

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

Setup

To set up the application, ensure you have the necessary environment variables and dependencies.

  1. Install the required packages:

    Copy code

    pip install flask openai python-dotenv requests

  2. 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.

  • Request: JSON
    • schema_path: Path to the JSON schema file.
  • Response: JSON
    • 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.

  • Request: JSON
    • 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.
  • Response: JSON
    • 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.

  • Request: JSON
    • Q_dict_unans: Dictionary of unanswered questions.
    • expected_dict_ans: Dictionary of expected answers for the unanswered questions.
  • Response: JSON
    • 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.

  • 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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant