Running Personal MAIC Deployment

Preparation

Please make sure you have Docker for your specific OS platform and Python3[?] installed.

Clone Repo

Clone the repo using Git and navigate to the root directory of the project:

git clone git@github.com:THU-MAIC/MAIC-Core.git maic
cd maic

Install pip dependencies

Pip install Requirements with Python >= 3.11:

pip install -r requirements.txt

Initialize MongoDB

Download the MongoDB dump file from this link and unzip the dump file in the current directory. Example of in linux bash (use other commands for other platforms):

# downlod dump file
wget -O dump.zip https://cloud.tsinghua.edu.cn/f/33d4e25fc62041e1b943/?dl=1
# unzip dump file
unzip dump.zip

Then, run the following commands to initialize the MongoDB database in docker:

# install mongo
docker pull mongo:4.4.4
# create mongo from ${your_dump_path}/dump:/mongo_dump
docker run -d --name algo-new-mongo -v ${your_dump_path}/mongo_dump:/dump -p 27017:27017 mongo:4.4.4
# initialize database
docker exec -it -u root algo-new-mongo sh -c "cd /dump && mongorestore ./"

Initialize RabbitMQ

# install rabbitmq-server
docker pull rabbitmq:management
# start rabbitmq
docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.9.15-management

Build the PPTX2PDF Converter Image

docker build -t preclass-converter --network=host service/preclass

InClass Deployment

Deploy InClass Worker

Run the following code in two separate terminals in the root directory of algo-backend:

# deploy zhipuai workers
python -m service.llm.zhipuai --zhipu_api_key <replace with your zhipuai apikey>
# deploy classroom_session workers
python -m service.inclass.main

Running In-Class

We provide 2 forms of triggering the in-class interaction in this code release:

  1. Commandline Interface. If you are still in the process of debugging or you are only intending to use maic for your personal needs, the commandline interface could be viewed as an official synchronized imeplementation (However, this implemention still demands the deployment of the zhipuai worker).

  2. Async Job Calls. If you are planning to deploy MAIC for the usecase where you are serving multiple users, and they share the same pool of parallel process workers, use this to create an async in-class job and retrieve the results once you are done.

Commandline Interface

Simply run:

python -m service.inclass.commandline

Creating Async Jobs

Run the following code in a new python console to initialize the course course “TAGI” by Zhiyuan Liu(modification needed):

python
# Run an inclass example
>>> from service.inclass.main import INCLASS_SERVICE
# Start the inclass service with specified session id, which can be replaced with your own session id created by PreClass service in the MongoDB database
>>> INCLASS_SERVICE.trigger("674ff0c87baecad6fd515719")
# Continue the inclass service with user input
>>> INCLASS_SERVICE.trigger("674ff0c87baecad6fd515719", user_input="Hello!")

PreClass Deployment

PreClass is a service indenpendent from InClass, which helps to create your own class agenda by uploading your slides. We have provided an created inclass agenda from course “TAGI” by Zhiyuan Liu(modification needed).

Deploy PreClass Worker

Run the following code in the root directory of algo-backend (Each service should go into a seperate process):

# deploy openai workers in a separate terminal, additionaly use --openai_baseurl if you are using a non-official openai service entrypoint
python -m service.llm.openai --openai_api_key <replace with your openai apikey>

# deploy main workers in a separate terminal
python -m service.preclass.main

# deploy processors
python -m service.preclass.processors.pptx2pdf
python -m service.preclass.processors.pdf2png
python -m service.preclass.processors.ppt2text
python -m service.preclass.processors.gen_description
python -m service.preclass.processors.gen_structure
python -m service.preclass.processors.gen_readscript
python -m service.preclass.processors.gen_showfile
python -m service.preclass.processors.gen_askquestion

Creating Async Pre-Class Job

Make sure you have a slide file named “your_slide.pptx” in the root directory of maic. Run the following code in the python console:

# Run a preclass example
>>> from service.preclass.main import PRECLASS_MAIN
# Trigger a preclass job
>>> PRECLASS_MAIN.trigger("Calling Preclass from Commandline", "your_slide.pptx")