Skip to content

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. ๐ŸŽฏ

License

Notifications You must be signed in to change notification settings

ArchitJ6/What-Beats-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ What Beats AI โ€“ GenAI Game ๐Ÿค–

๐Ÿš€ Introduction

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! ๐ŸŒ

๐Ÿ“ Features โœจ

  • 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.

๐Ÿ”ง Tech Stack โš™๏ธ

  • 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 ๐Ÿ”„

๐Ÿ“‚ Project Structure

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

๐Ÿƒโ€โ™‚๏ธ Getting Started ๐Ÿ

1. Clone the Repository ๐Ÿ’ป

Clone the repository to your local machine:

git clone https://github.com/ArchitJ6/What-Beats-AI.git
cd What-Beats-AI

2. Create Environment Files ๐Ÿ“„

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.

3. Build and Run the Application Using Docker ๐Ÿ‹

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 ๐Ÿ–ฅ๏ธ

4. Access the Application ๐ŸŒ

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! ๐ŸŽฎ

โšก API Endpoints ๐Ÿ”Œ

1. POST /guess ๐ŸŽฏ

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
}

2. GET /history ๐Ÿ“œ

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
}

3. POST /reset ๐Ÿ”„

Resets the game for the current session.

Request:

POST /reset?session_id=unique-session-id

Response:

{
    "message": "Game reset."
}

4. WebSocket /ws/active_users ๐ŸŒ

This WebSocket endpoint provides real-time updates on the number of active users.

5. GET /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
    }
}

๐Ÿ’ก Game Logic ๐Ÿง 

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 โณ.

๐Ÿง‘โ€๐Ÿ’ป Developing and Testing ๐Ÿ› ๏ธ

To test the application locally, follow these steps:

  1. Install Dependencies:

    pip install -r requirements.txt
  2. Run the Application: After setting up Docker and environment files, start the app using:

    docker-compose up
  3. Test API Endpoints ๐Ÿงช: Use tools like Postman or Insomnia to test the API endpoints.

  4. Run End-to-End Tests ๐Ÿ…: End-to-end tests are located in the tests/e2e_duplicate_test.py file. Run them using:

    pytest

๐Ÿ“ฆ Docker & Services ๐Ÿ‹

  • 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 ๐ŸŒ.

๐Ÿ’ฌ Contributing ๐ŸŒŸ

We welcome contributions! ๐Ÿ’ฅ To contribute to this project, please follow these steps:

  1. Fork the repository ๐Ÿด.
  2. Create a new branch (git checkout -b feature-name) ๐ŸŒฑ.
  3. Make your changes ๐Ÿ–‹๏ธ.
  4. Commit your changes (git commit -am 'Add feature') ๐Ÿ’ฌ.
  5. Push to the branch (git push origin feature-name) ๐Ÿš€.
  6. Create a pull request ๐Ÿ”€.

๐Ÿ›  Technologies Used ๐Ÿ’ป

  • Backend: FastAPI ๐Ÿš€, SQLAlchemy ๐Ÿ—„๏ธ, Redis ๐Ÿง‘โ€๐Ÿ’ป
  • Frontend: React โš›๏ธ, Vite โšก
  • Database: PostgreSQL ๐Ÿ—„๏ธ
  • Cache: Redis ๐Ÿง‘โ€๐Ÿ’ป
  • Real-Time Communication: WebSockets ๐ŸŒ
  • Profanity Filtering: profanity_check ๐Ÿงน

๐Ÿ“œ License โš–๏ธ

This project is licensed under the MIT License - see the LICENSE file for details.

About

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. ๐ŸŽฏ

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published