What Beats AI is an interactive word-challenge game that leverages Generative AI (GenAI) to judge whether a player's guess can beat a given seed word. ๐ฏ The game allows players to make guesses and get real-time feedback through a dynamic, AI-driven experience. ๐ง ๐ฅ Players score points by making valid and winning guesses, and can compete with others in a fun, fast-paced environment! ๐
- AI-Powered Judgement ๐ค: Uses a language model to assess if a guess beats a seed word.
- Real-Time Multiplayer โฑ๏ธ: Players can join, interact, and compete in real time through WebSockets.
- Profanity Filtering ๐ซ: Automatically checks and filters inappropriate content.
- Game History & Scores ๐: Tracks guess history and scores for every session.
- Global Guess Count ๐: Monitors how many times each guess has been made globally.
- Session Management โณ: Handles unique sessions, timeouts, and expirations.
- Database-Driven ๐: Uses PostgreSQL for storing guess statistics and game data.
- Cache Integration โก: Redis ensures quick response times by caching game verdicts.
- Dockerized ๐ณ: The whole app is containerized for easy deployment and scalability.
- Backend: FastAPI ๐
- Frontend: React + Vite โ๏ธ
- Database: PostgreSQL ๐๏ธ (with SQLAlchemy ORM)
- Cache: Redis ๐งโ๐ป
- Profanity Filter:
profanity_check
๐งน - WebSockets: Real-time communication ๐
- Docker: Containerization ๐ณ
- Docker Compose: Multi-service orchestration ๐
What Beats AI โ GenAI Game/
โโโ backend/
โ โโโ api/
โ โ โโโ routes.py # API endpoints for handling game logic
โ โโโ core/
โ โ โโโ ai_client.py # Communicates with the LLM (AI client)
โ โ โโโ cache.py # Redis helpers for caching verdicts
โ โ โโโ game_logic.py # Game logic, session management, and validation
โ โ โโโ moderation.py # Profanity check and policy enforcement
โ โโโ db/
โ โ โโโ models.py # Database models for global guess count
โ โ โโโ session.py # SQLAlchemy session management
โ โโโ main.py # FastAPI app entry point
โโโ frontend/
โ โโโ React Vite code # Frontend code (React with Vite)
โโโ tests/
โ โโโ e2e_duplicate_test.py # End-to-end testing
โโโ Dockerfile # Docker configuration for backend
โโโ docker-compose.yml # Multi-service Docker Compose file
โโโ requirements.txt # Python dependencies
โโโ README.md # Project documentation
Clone the repository to your local machine:
git clone https://github.com/ArchitJ6/What-Beats-AI.git
cd What-Beats-AI
Create .env
files in the root and frontend directories. These files should be based on the .env.example
provided:
cp .env.example .env
cp frontend/.env.example frontend/.env
Make sure to update the environment variables with the correct configuration, such as database URLs, Redis configuration, and other necessary settings.
To build and run the application with Docker, execute the following command:
docker-compose up --build
This command will:
- Build all necessary Docker images ๐
- Set up the backend, frontend, Redis, and PostgreSQL services ๐ง
- Run the application on your local machine ๐ฅ๏ธ
Once the services are up, you can access the game by visiting the following URL in your browser:
http://localhost:5173 (Frontend)
http://localhost:8000 (Backend)
The frontend will automatically interact with the backend via API calls and WebSockets, allowing you to play the game! ๐ฎ
This endpoint allows the user to submit a guess to beat the seed word. It returns the result of the game (whether the guess is valid and if it beats the seed).
Request Body:
{
"seed": "apple",
"guess": "banana",
"session_id": "unique-session-id",
"persona": "serious"
}
Response:
{
"status": "success",
"message": "โ
Nice! 'banana' beats 'apple'. 'banana' has been guessed 15 times before.",
"seed_word": "banana",
"score": 10,
"history": ["rock", "banana"],
"global_count": 15
}
This endpoint retrieves the guess history and score of a session.
Request:
GET /history?session_id=unique-session-id
Response:
{
"history": ["rock", "banana"],
"score": 10
}
Resets the game for the current session.
Request:
POST /reset?session_id=unique-session-id
Response:
{
"message": "Game reset."
}
This WebSocket endpoint provides real-time updates on the number of active users.
This endpoint retrieves the current count of active users and sessions.
Response:
{
"active_users": 10,
"sessions": 12,
"ip_connections": {
"192.168.1.1": 3,
"192.168.1.2": 2
}
}
The game operates by accepting user guesses and comparing them against a pre-generated seed word. The judgment is made using an AI language model, and the results are cached for faster responses. Sessions are managed with a timeout feature, ensuring that players are disconnected after periods of inactivity โณ.
To test the application locally, follow these steps:
-
Install Dependencies:
pip install -r requirements.txt
-
Run the Application: After setting up Docker and environment files, start the app using:
docker-compose up
-
Test API Endpoints ๐งช: Use tools like Postman or Insomnia to test the API endpoints.
-
Run End-to-End Tests ๐ : End-to-end tests are located in the
tests/e2e_duplicate_test.py
file. Run them using:pytest
- Backend: FastAPI ๐ for API management and game logic.
- Frontend: React โ๏ธ with Vite for a fast, responsive UI.
- Database: PostgreSQL ๐๏ธ to store global guess counts and session data.
- Redis: Fast, in-memory caching for quick access to previous verdicts โก.
- WebSockets: Real-time communication for active player updates ๐.
We welcome contributions! ๐ฅ To contribute to this project, please follow these steps:
- Fork the repository ๐ด.
- Create a new branch (
git checkout -b feature-name
) ๐ฑ. - Make your changes ๐๏ธ.
- Commit your changes (
git commit -am 'Add feature'
) ๐ฌ. - Push to the branch (
git push origin feature-name
) ๐. - Create a pull request ๐.
- Backend: FastAPI ๐, SQLAlchemy ๐๏ธ, Redis ๐งโ๐ป
- Frontend: React โ๏ธ, Vite โก
- Database: PostgreSQL ๐๏ธ
- Cache: Redis ๐งโ๐ป
- Real-Time Communication: WebSockets ๐
- Profanity Filtering:
profanity_check
๐งน
This project is licensed under the MIT License - see the LICENSE file for details.