This project utilizes Flask, a Python microframework, to create a web application for managing assistants, chats, and documents for a project by Creath Digital. Here's a brief overview of the project structure and functionalities:
The project is organized into three main sections: routes, models, and database interaction.
All routes (except for the /chats/enviarMensagemLLM
route) require a LOGIN TOKEN to be passed in the header.
That's 'cause they should be run by a logged client on our frontend.
The token can be obtained by logging in with the /auth/login
route.
// header:
{
"Authorization": "Bearer <token>"
}
- POST /assistants/add: Add a new assistant.
// request: { "name": "Assistant Name", "owner_id": "Owner id" }
- GET /assistants/list: List all assistants.
// response: [ { "_id": "id", "name": "Assistant Name", "owner_id": "owner id", "api_key": "api key", "createdAt": "2021-09-01T00:00:00" } ]
- GET /assistants/get/<id>: Get details of a specific assistant.
// response: { "_id": "id", "name": "Assistant Name", "owner_id": "owner id", "api_key": "api key", "createdAt": "2021-09-01T00:00:00" }
- PUT /assistants/update/<id>: Update details of a specific assistant.
// request: { "_id": "id", "name": "Assistant Name", "owner_id": "owner id", "api_key": "api key", "createdAt": "2021-09-01T00:00:00" }
- DELETE /assistants/delete/<id>: Delete a specific assistant.
- POST /chats/enviarMensagemLLM: Send a message to LLM.
// header: { "X-API-Key": "api key" }
// request: { "id": "+5513988593464", "message_service": "Whatsapp", "username": "nome", "active": true, "message": "mensagem do usuario" }
- GET /chats/get/<id>: Get details of a specific chat.
// response: { "_id": "id", "channel": { "id": "+551300000000", "message_service": "Whatsapp" }, "tokens": { "in": 1, "out": 1 }, "username": "nome", "assistant_id": "id", "active": true, "message": "mensagem do Usuario", "response": "resposta LLM", "createdAt": "05-09-2024T19:57:00" }
- GET /chats/list: List all chats.
// response: [ { "_id": "id", "channel": { "id": "+551300000000", "message_service": "Whatsapp" }, "tokens": { "in": 1, "out": 1 }, "username": "nome", "assistant_id": "id", "active": true, "message": "mensagem do Usuario", "response": "resposta LLM", "createdAt": "05-09-2024T19:57:00" } ]
- GET /chats/listarAtivos: List all active chats.
// response: [ { "_id": "id", "channel": { "id": "+551300000000", "message_service": "Whatsapp" }, "tokens": { "in": 1, "out": 1 }, "username": "nome", "assistant_id": "id", "active": True, "message": "mensagem do Usuario", "response": "resposta LLM", "createdAt": "05-09-2024T19:57:00" } ]
- GET /chats/listarInativos: List all inactive chats.
// response: [ { "_id": "id", "channel": { "id": "+551300000000", "message_service": "Whatsapp" }, "tokens": { "in": 1, "out": 1 }, "username": "nome", "assistant_id": "id", "active": False, "message": "mensagem do Usuario", "response": "resposta LLM", "createdAt": "05-09-2024T19:57:00" } ]
- PUT /chats/desativar/<id>: Deactivate a specific chat.
- PUT /chats/ativar/<id>: Activate a specific chat.
- POST /documents/add: Upload a new document.
// request form-data: { "file": "file attached" "type": "rag or prompt", "assistant_id": "id", }
- GET /documents/list: List all documents.
// response: [ { "_id": "id", "filepath": "file path", "filename": "file name", "type": "rag or prompt", "assistant_id": "id", "createdAt": "2021-09-01T00:00:00" } ]
- GET /documents/get/<id>: Get details of a specific document.
// response: { "_id": "id", "filepath": "file path", "filename": "file name", "type": "rag or prompt", "assistant_id": "id", "createdAt": "2021-09-01T00:00:00" }
- PUT /documents/path/get/<id>: Get the file path of a specific document.
- GET /documents/download/<id>: Download a specific document.
- DELETE /documents/delete/<id>: Delete a specific document.
Orquestradora-LabDeIA
└── documents
├── <assistant id>
│ ├── knowledge
│ │ └── rag.md
│ └── prompt.txt
│
└── <assistant id>
├── knowledge
│ └── rag.md
└── prompt.txt
- POST /auth/login: Login to the application.
// request: { "email": "user email", "password": "password" } // response: { "token": "access token", "user": { "email": "user email", "id": "id", "name": "name" } }
- POST /auth/register: Register a new user.
// request: { "name": "name" "email": "user email", "password": "password", }
- Assistant Model:
- Attributes: name, company, createdAt
- Chat Model:
- Attributes: channel (id and message_service), username, assistant_id, active, message, response, createdAt
- Document Model:
- Attributes: filepath, filename, type (rag or prompt), assistant_id, createdAt
The project utilizes MongoDB as the database. Each model corresponds to a collection in the MongoDB database.
We have two packages on the code that are responsible for the database interaction: repositories
and services
.
- Repositories: The repositories package contains the classes that interact with the database.
- Services: The services package contains the classes that handle the business logic of the application.
- DocumentType Enum: The type of document is defined by an enum called DocumentType, which has two values: "rag" or "prompt".
- File Storage: Document files are saved within the project folder, and only the file path is stored in the database.
To set up the project locally, follow these steps:
- Clone the repository.
- Run
cp .env.example .env
to create a new.env
file and set it up according to the required. - Install the required dependencies using pip:
pip install -r requirements.txt
. - Ensure that you have the core application running on your local machine.
- Run the Flask application on waitress running:
waitress-serve --port=8080 --call main:create_app
.
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request with your changes.
This project is licensed under the MIT License.