Giter VIP home page Giter VIP logo

sakhi-api-service's Introduction

Activity Sakhi API :

A powerful service designed to enhance the educational experience for both parents and teachers. Our service revolves around a curated collection of documents focused on children's activities and curriculum frameworks. With simplicity at its core, "Activity Sakhi" empowers parents and teachers to effortlessly discover relevant content and find answers to audience-specific questions.

Key Features:

Rich Content Repository:

Explore a predefined set of documents tailored to children's activities and curriculum frameworks, ensuring a wealth of valuable information at your fingertips.

Audience-Centric:

Targeted specifically for parents and teachers, "Activity Sakhi" caters to their unique needs, providing insights and resources tailored to enhance the learning journey. Discover and Learn: Seamlessly discover engaging content and obtain answers to your specific questions, making the educational process more accessible and enjoyable.

Whether you're a parent looking for creative activities or a teacher seeking curriculum support, Activity Sakhi is your go-to solution. Unlock the potential of educational resources and make learning a delightful experience for children.

Getting Started:

Integrate "Activity Sakhi" effortlessly into your applications to revolutionize the way parents and teachers engage with educational content. Check out our documentation to get started and embark on a journey of enriched learning experiences.

Prerequisites

  • Python 3.7 or higher
  • Latest Docker
  1. To get the Marqo image, use the following command:
docker pull marqoai/marqo:latest
  1. To create the Marqo instance, run the following command:
docker run --name marqo --privileged \
  -p 8882:8882 \
  --add-host host.docker.internal:host-gateway \
  -d marqoai/marqo:latest

๐Ÿ”ง 1. Installation

To use the code, you need to follow these steps:

  1. Clone the repository from GitHub:

    git clone https://github.com/DJP-Digital-Jaaduii-Pitara/sakhi-api-service.git
    cd sakhi-api-service
    
  2. The code requires Python 3.7 or higher and some additional python packages. To install these packages, run the following command in your terminal:

    pip install -r requirements-dev.txt
  3. To injest data to marqo

    python3 index_documents.py --marqo_url=<MARQO_URL> --index_name=<MARQO_INDEX_NAME> --folder_path=<PATH_TO_INPUT_FILE_DIRECTORY> --fresh_index

    --fresh_index: This is a flag that creating a new index or overwriting an existing one. Fresh indexing typically starts from scratch without using existing data. PATH_TO_INPUT_FILE_DIRECTORY should have only PDF, audio, video and txt file only.

    e.g.

    python3 index_documents.py --marqo_url=http://0.0.0.0:8882 --index_name=sakhi_parent_activities --folder_path=parent_pdfs --fresh_index
    python3 index_documents.py --marqo_url=http://0.0.0.0:8882 --index_name=sakhi_teacher_activities --folder_path=teacher_pfs --fresh_index

    Create the index by using the above command. After creating the index add the index name in config.ini file.

       indices = {
          "parent":"<PARENT_INDEX_NAME>",
          "teacher": "<TEACHER_INDEX_NAME>"
       }
  4. You will need an OCI account to store the audio file for response.

  5. create another file .env which will hold the development credentials and add the following variables. Update the Azure OpenAI details, OCI details, Bhashini endpoint URL and API key.

    SERVICE_ENVIRONMENT=<name_of_the_environment>
    OPENAI_API_BASE=<your_azure_openai_api_base_url>
    OPENAI_API_VERSION=<your_azure_api_version>
    OPENAI_API_KEY=<your_azure_api_key>
    GPT_MODEL=<your_gpt_model>
    LOG_LEVEL=<log_level>  # INFO, DEBUG, ERROR
    BHASHINI_ENDPOINT_URL=<your_bhashini_api_endpoint>
    BHASHINI_API_KEY=<your_bhashini_api_key>
    OCI_ENDPOINT_URL=<oracle_bucket_name>
    OCI_REGION_NAME=<oracle_region_name>
    OCI_BUCKET_NAME=<oracle_bucket_name>
    OCI_SECRET_ACCESS_KEY=<oracle_secret_access_key>
    OCI_ACCESS_KEY_ID=<oracle_access_key_id>
    MARQO_URL=<your_marqo_db_url>
    TELEMETRY_ENDPOINT_URL=<telemetry_endpoint_url>
    TELEMETRY_LOG_ENABLED=<telemetry_enable_or_disable> # true or false

๐Ÿƒ๐Ÿป 2. Running

Once the above installation steps are completed, run the following command in home directory of the repository in terminal

uvicorn main:app

Open your browser at http://127.0.0.1:8000/docs to access the application.

The command uvicorn main:app refers to:

  • main: the file main.py (the Python "module").
  • app: the object created inside of main.py with the line app = FastAPI().
  • --reload: make the server restart after code changes. Only do this for development.
    uvicorn main:app --reload

Alt text

๐Ÿ“ƒ 3. API Specification and Documentation

POST /v1/query

API Function

API is used to generate activity/story based on user query and translation of text/audio from one language to another language in text/audio format. To achieve the same, Bhashini has been integrated. OCI object storage has been used to store translated audio files when audio is chosen as target output format.

curl -X 'POST' \
  'http://127.0.0.1:8000/v1/query' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "input": {
    "language": "en",
    "text": "string",
    "audio": "string",
    "audienceType": "teacher"
  },
  "output": {
    "format": "text"
  }
}'

Request

Request Input Value
input.language en,bn,gu,hi,kn,ml,mr,or,pa,ta,te
input.text User entered question (any of the above language)
input.audio Public file URL Or Base64 encoded audio
input.audienceType parent, teacher (default value is parent, if not passing)
output.format text or audio

Required inputs are text, audio and language.

Either of the text(string) or audio(string) should be present. If both the values are given, text is taken for consideration. Another requirement is that the language should be same as the one given in text and audio (i.e, if you pass English as language, then your text/audio should contain queries in English language). The audio should either contain a publicly downloadable url of mp3 file or base64 encoded text of the mp3. If output format is given as text than response will return text format only. If output format is given as audio than response will return text and audio both.

{
   "input": {
      "text": "How to Teach Kids to Play Games", 
      "language": "en"
   },
   "output": {
      "format": "text"
   }
}

Successful Response

{
   "output": {
      "text": "string",
      "audio": "string",
      "language": "en",
      "format": "text|audio"
   }
}

What happens during the API call?

Once the API is hit with proper request parameters, it is then checked for the presence of query text.

If query text is present, the translation of query text based on input language is done. Then the translated query text is given to langchain model which does the same work. Then the paraphrased answer is again translated back to input_language. If the output_format is voice, the translated paraphrased answer is then converted to a mp3 file and uploaded to an OCI folder and made public.

If the query text is absent and audio url is present, then the audio url is downloaded and converted into text based on the input language. Once speech to text conversion in input language is finished, the same process mentioned above happens. One difference is that by default, the paraphrased answer is converted to voice irrespective of the output_format since the input format is voice.

๐Ÿš€ 4. Deployment

This repository comes with a Dockerfile. You can use this dockerfile to deploy your version of this application to Cloud Run. Make the necessary changes to your dockerfile with respect to your new changes. (Note: The given Dockerfile will deploy the base code without any error, provided you added the required environment variables (mentioned in the .env file) to either the Dockerfile or the cloud run revision)

5. Configuration (config.ini)

Variable Description Default Value
database.indices index or collection name to be referred to from vector database based on input audienceType
database.top_docs_to_fetch Number of filtered documents retrieved from vector database to be passed to Gen AI as contexts 5
database.docs_min_score Minimum score of the documents based on which filtration happens on retrieved documents 0.4
request.supported_lang_codes Supported languages by the service en,bn,gu,hi,kn,ml,mr,or,pa,ta,te
request.support_response_format Supported response formats text,audio
llm.gpt_model Gen AI GPT Model value
llm.enable_bot_intent Flag to enable or disable verification of user's query to check if it is referring to bot false
llm.intent_prompt System prompt to Gen AI to verify if the user's query is referring to the bot
llm.bot_prompt System prompt to Gen AI to generate responses for user's query related to bot
llm.activity_prompt System prompt to Gen AI to generate responses based on user's query and input contexts
telemetry.telemetry_log_enabled Flag to enable or disable telemetry events logging to Sunbird Telemetry service true
telemetry.environment service environment from where telemetry is generated from, in telemetry service dev
telemetry.service_id service identifier to be passed to Sunbird telemetry service
telemetry.service_ver service version to be passed to Sunbird telemetry service
telemetry.actor_id service actor id to be passed to Sunbird telemetry service
telemetry.channel channel value to be passed to Sunbird telemetry service
telemetry.pdata_id pdata_id value to be passed to Sunbird telemetry service
telemetry.events_threshold telemetry events batch size upon which events will be passed to Sunbird telemetry service 5

Feature request and contribution

  • We are currently in the alpha stage and hence need all the inputs, feedbacks and contributions we can.
  • Kindly visit our project board to see what is it that we are prioritizing.

sakhi-api-service's People

Contributors

vaibhavbhuva avatar sajeshkayyath avatar amiableanil avatar jayaprakash8887 avatar gandham-santhosh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.