- Get a list of books
- Get a specific book
- Order for a book
- AI service is employed to attain summary or other prompts peculiar to a specific book available in the library.
- Docker for containerization
- RabbitMQ for communication between consumer and producer to asynchronously process order
- SocketIO to transfer communication and give status real-time
- Asynchronous order processing via RabbitMQ
- Real-time updates (planned/implemented) via SocketIO
- Nested item using indentation
Install the following:
- Python 3.12.6
- Pip (Python package installer)
- RabbitMQ Server, used Homebrew
- Docker & Docker Compose
Provide step-by-step instructions.
-
Clone the repository:
git clone https://github.com/Nobelwrite/ai-library.git cd NewLIB -
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On macOS/Linux # .\ .venv\Scripts\activate # On Windows
-
Install dependencies:
pip install -r requirements.txt
(Note: You'll need to create a
requirements.txtfile) -
Configure Environment Variables: Including:
RABBITMQ_URL,FLASK_SECRET_KEY..envfile (optional but recommended).# Example .env file content RABBITMQ_URL FLASK_SECRET_KEY=your_super_secret_key_here -
Start RabbitMQ: Used brew services command using
brew services start rabbitmq
Instructions on how to run the different parts.
-
Run the Consumer:
python consumer.py
-
Run the Flask/SocketIO Server:
python app.py
Describe the available API endpoints.
-
POST /orders: Place a new order.- Request Body:
{ "items": [ { "book_id": 1, "quantity": 1 }, { "book_id": 3, "quantity": 2 } ], "user_identifier": "optional_user_id" } - Success Response (201 Created): Order details.
- Error Responses (400, 500): Error details.
- Request Body:
-
GET /books: Get list of available books.
Describe real-time events clients can listen for.
connect: Emitted when a client connects.disconnect: Emitted when a client disconnects.order_received: Emitted by server when an order is initially accepted.- Data:
{'order_id': '...', 'status': 'Pending'}
- Data:
order_error: Emitted on queueing failure.- Data:
{'order_id': '...', 'error': 'Queueing Failed'}
- Data:
order_status_update(Emitted by Consumer - Implementation Note): Ideally emitted when order status changes during processing.- Data:
{'order_id': '...', 'status': 'Processed' | 'Failed'}
- Data: