Give complete solution with code for the below project stepwise in docker and docker…
- User
Give complete solution with code for the below project stepwise in docker and docker compose (Automate everything) As a user, I should be able to access APIs associated with any model (Please tell me how it is done in solution):
Project: AI Toolchain is a collection of tools for quickly building and deploying machine learning models for various use cases. Currently, the toolchain includes a text translation model, and more models may be added in the future. It abstracts the dirty details of how a model works similar to Huggingface and gives a clean API that you can orchestrate at aenter code here BFF level.
Features to be implemented Abstract the layer of deployment for AI Tools. Anyone should be easily add a new model to the stack without thinking about deployments. We should be able to deploy AI Tools in such a way where each model (every model can be packaged as a container) should be independently scalable. As a user, I should be able to access APIs associated with any model.
Product Set Up https://github.com/Samagra-Development/ai-tools#setup
Github Information: ReadME: AI Toolchain AI Toolchain is a collection of tools for quickly building and deploying machine learning models for various use cases. Currently, the toolchain includes a text translation model, and more models may be added in the future.
How to Run To deploy all models, simply execute the deploy.sh script located in the root folder. This script calls the deployment files of each model. Note that the toolchain may switch to using Docker in the future for deployment.
To create a new model class, use the template_batch_model.py file as a starting point. Your new model class should implement the method mentioned in the template file.
To create a new request class, use the template_model_request.py file as a starting point. This class is used to map the incoming request to the data needed by the model.
To add your new model and request to the API, modify the repository dictionary in api.py.
Repository The repository is structured as follows
Setup To set up the AI Toolchain environment, follow these steps:
python3 -m venv venv source venv/bin/activate pip install poetry poetry install quart --app api --debug run Poetry Fixes poetry lock --no-update Contributing Contributions to AI Toolchain are welcome! To contribute, please follow these guidelines:
Fork the repository and create a new branch for your feature or bug fix. Write tests for your changes. Submit a pull request describing your changes and why they are needed. Thank you for considering contributing to AI Toolchain!
- Assistant
To achieve the goal of deploying and automating the AI Toolchain project using Docker and Docker Compose, follow these steps:
- Write a Dockerfile for the AI Toolchain project
Create a
Dockerfilein the root of the AI Toolchain project with the following content:FROM python:3.8-slim WORKDIR /app COPY . . RUN pip install --upgrade pip RUN pip install poetry RUN poetry config virtualenvs.create false RUN poetry install --no-dev EXPOSE 8000 CMD ["quart", "--app", "api", "run", "--host", "0.0.0.0", "--port", "8000"]This Dockerfile sets the base image as Python 3.8, copies the contents of the project to the
/appdirectory, installs Poetry, installs dependencies, exposes port 8000 for the Quart web server, and runs thequartcommand to start the API.- Create a docker-compose.yml file
Create a
docker-compose.ymlfile in the root of the AI Toolchain project with the following content:
version: "3.8" services: ai_toolchain: build: . ports: - "8000:8000" environment: - PYTHONUNBUFFERED=1This docker-compose file defines a single service called 'ai_toolchain' that builds from the Dockerfile and maps the local port 8000 to the container's port 8000.
- Update deploy.sh
Now, you can modify the deploy.sh script to use Docker and Docker Compose to deploy all models. Replace the content of deploy.sh with the following commands:
#!/bin/sh set -e docker-compose build docker-compose up -dThis script builds the Docker image and runs it as a container in detached mode using Docker Compose.
- Deploy AI Toolchain
Finally, set up the environment, run deploy.sh, and access the APIs:
# Set up the environment python3 -m venv venv source venv/bin/activate pip install poetry poetry install # Deploy AI Toolchain chmod +x deploy.sh ./deploy.shNow, you can access the APIs associated with any model by sending requests to
http://localhost:8000/.- Adding new models
To add a new model:
- Create a new model class that implements the method mentioned in
template_batch_model.py. - Create a new request class that maps the incoming request to the data needed by the model, using
template_model_request.pyas a starting point. - Modify the
repositorydictionary inapi.pyto add your new model and request.
Make sure to rebuild and re-deploy containers after adding new models:
./deploy.shThis setup ensures that each model in the AI Toolchain is easily deployable and independently scalable using Docker and Docker Compose.