An open API service indexing awesome lists of open source software.

https://github.com/igorbenav/clientai-dungeon-master

Text-based role-playing game (RPG) where the game's content is dynamically generated by AI models
https://github.com/igorbenav/clientai-dungeon-master

chatgpt clientai llms ollama openai

Last synced: about 1 year ago
JSON representation

Text-based role-playing game (RPG) where the game's content is dynamically generated by AI models

Awesome Lists containing this project

README

          

# AI Dungeon Master


An AI-powered text-based RPG adventure guided by multiple AI models.

AI Dungeon Master is a text-based role-playing game (RPG) where the game's content is dynamically generated by AI models. This project utilizes the ClientAI package to interact seamlessly with multiple AI providers like OpenAI, Replicate, and Ollama. The game offers infinite replayability and unique experiences for each player by generating story elements, NPC dialogues, and dynamic environments on the fly.

## Features

- 🎮 **Dynamic Storytelling**: Experience unique adventures every time you play.
- 🤖 **Multiple AI Providers**: Leverage the strengths of different AI models.
- 🗣️ **Interactive NPCs**: Engage in conversations with AI-generated characters.
- 🌐 **Rich Environments**: Explore AI-generated settings and scenarios.
- 🔄 **Replayability**: Infinite possibilities for stories and outcomes.
- 💡 **Example Project**: Demonstrates how to use the ClientAI package in a practical application.

## Requirements

Before installing and running AI Dungeon Master, ensure you have the following:

- Python: Version 3.11 or newer.
- ClientAI: Installed with support for all providers.
- API Keys: Valid API keys for OpenAI and Replicate.
- Ollama: Installed for running local AI models.
- Additional Dependencies: See Installation for details.

## Installation

You can choose to install and run the project using either pip or Poetry.

### Option 1: Using pip

1. Clone the Repository

```bash
git clone https://github.com/yourusername/ai_dungeon_master.git
cd ai_dungeon_master
```

2. Set Up a Virtual Environment (Optional but Recommended)

```bash
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
```

3. Install Dependencies

Install required Python packages:

```bash
pip install clientai[all] requests python-decouple
```

### Option 2: Using Poetry

1. Install Poetry (if not already installed):

```bash
curl -sSL https://install.python-poetry.org | python3 -
```

2. Clone the Repository:

```bash
git clone https://github.com/igorbenav/ai_dungeon_master.git
cd ai_dungeon_master
```

3. Install Dependencies:

```bash
poetry install
```

This will create a virtual environment and install all required dependencies.

### Common Steps for Both Options

4. Install Ollama

For macOS or Linux:

```bash
curl -fsSL https://ollama.ai/install.sh | bash
```

For Windows:

Download the installer from the Ollama GitHub releases page and follow the installation instructions.

5. Pull the Llama 3 Model

After installing Ollama, download the Llama 3 model:

```bash
ollama pull llama3
```

Note: The download may take some time depending on your internet connection.

6. Set Up API Keys

Create a `.env` file in the project's root directory to store your API keys:

```plaintext
OPENAI_API_KEY=your_openai_api_key_here
REPLICATE_API_KEY=your_replicate_api_key_here
```

Replace `your_openai_api_key_here` and `your_replicate_api_key_here` with your actual API keys.

7. Ensure .env is Ignored by Git

Make sure your `.env` file is listed in your `.gitignore` to prevent accidental commits:

```plaintext
# .gitignore
.env
```

## Running the Game

### Option 1: Using pip

To start your AI-powered adventure, run the following command from the project's root directory:

```bash
python ai_dungeon_master/main.py
```

If you set up a virtual environment, ensure it's activated before running the command.

### Option 2: Using Poetry

To start your AI-powered adventure using Poetry, run the following command from the project's root directory:

```bash
poetry run python ai_dungeon_master/main.py
```

This command activates the Poetry virtual environment and runs the main script.

## Project Structure

```
ai_dungeon_master/
├── ai_dungeon_master/
│ ├── __init__.py
│ ├── main.py
│ ├── ai/
│ │ ├── __init__.py
│ │ ├── ai_providers.py
│ │ └── ollama_server.py
│ ├── game/
│ │ ├── __init__.py
│ │ ├── character.py
│ │ ├── dungeon_master.py
│ │ └── game_state.py
│ └── utils/
│ ├── __init__.py
│ └── text_utils.py
├── .env
├── .gitignore
├── README.md
└── pyproject.toml
```

## Usage

When you run the game, you'll be greeted by the AI Dungeon Master who will guide you through character creation and immerse you in a dynamically generated world.

- Character Creation: Provide your character's name; the AI will generate the rest.
- Gameplay: Type commands to interact with the environment, such as "look around," "talk to the innkeeper," or "explore the forest."
- Quitting: You can type "quit" at any time to exit the game.

## About ClientAI

This project is an example of how to use the ClientAI package to interact with multiple AI providers seamlessly.

ClientAI is a Python package that provides a unified interface for interacting with various AI models. It simplifies the process of switching between different AI providers and managing API interactions.

- Documentation: [https://igorbenav.github.io/clientai/](https://igorbenav.github.io/clientai/)
- Repository: [https://github.com/igorbenav/clientai](https://github.com/igorbenav/clientai)

## Tutorial

For a detailed walkthrough of how this project was built, including explanations of the code and design decisions, refer to the tutorial:

[Creating an AI Dungeon Master with ClientAI](https://igorbenav.github.io/clientai/examples/ai_dungeon_master/)

This tutorial covers:

- Setting up the project environment.
- Integrating multiple AI providers.
- Developing game logic and AI interactions.
- Managing conversation history and game state.
- Enhancements and potential improvements.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contact

Igor Magalhaes – [@igormagalhaesr](https://twitter.com/igormagalhaesr) – igormagalhaesr@gmail.com
[github.com/igorbenav](https://github.com/igorbenav/)