MVP of an idea using multiple LLM models to simulate and play D&D (Local LLM via ollama support + together.ai API support).
This project is a proof of concept (MVP) that demonstrates how to use multiple language models (LLMs) to simulate and play a Dungeons & Dragons (D&D) game. The script involves a Dungeon Master (DM) and several player characters, some controlled by LLMs and one controlled by a human player.
- Generate Party: Generates a party of LLM-controlled characters.
- Human Player Input: Prompts the human player to enter their character details.
- Adventure Setup: The DM starts the adventure and introduces all characters.
- Turn-Based Gameplay: Each character takes turns describing their actions, followed by the DM summarizing the events and introducing new challenges.
- Local LLM Support: Option to use local LLMs via the Ollama API for LLM-controlled characters and the DM.
- Python 3
requests
library (install viapip install requests
)
-
Clone the repository:
git clone https://github.com/tegridydev/dnd-llm-game.git cd dnd-llm-game
-
Install the required Python packages:
pip install requests
-
Set your Together API key in the script or as an environment variable:
export TOGETHER_API_KEY='your_api_key'
-
(Optional) Set up the Ollama API for local LLM support. Ensure the Ollama API is running and accessible at the specified endpoint (default:
http://localhost:11434/api/generate
).
-
Run the script:
python dnd.py
-
Follow the on-screen prompts to generate a party and start a new adventure.
To use the local LLM via the Ollama API, set the USE_OLLAMA
flag to True
in the dnd.py
script:
USE_OLLAMA = True # Set this to False to use Together API
Ensure the Ollama API is running locally and accessible. The default endpoint is http://localhost:11434/api/generate
.
- Generate Party: The script generates a party of LLM-controlled characters.
- Human Player Input: The human player is prompted to enter their character's name, backstory, and items.
- Adventure Setup: The DM introduces the adventure setting and all characters.
- Turn-Based Gameplay: Each character takes turns to describe their actions, and the DM summarizes the events and introduces new challenges.
This project is open source and can be expanded in numerous ways:
- Character Development: Add more detailed character creation options, including classes, races, and abilities.
- Inventory Management: Implement inventory management for both LLM-controlled and human-controlled characters.
- Battle System: Create a more complex battle system with dice rolls, hit points, and special abilities.
- Story Progression: Develop a more sophisticated story progression system with branching narratives based on player choices.
- Multiplayer: Allow multiple human players to join the game and interact with LLM-controlled characters.
- Graphics and UI: Enhance the game with graphical elements and a user-friendly interface.
- Integration with D&D Rulesets: Integrate the game with official D&D rulesets and modules.
- Save and Load: Implement save and load functionality to allow players to continue their adventures at a later time.
Contributions are welcome! Please fork the repository and build some cool stuff.
This project is licensed under the MIT License. See the LICENSE file for details.
- This project uses the Together API and the Ollama API for LLM interactions.
- Inspired by the creative world of Dungeons & Dragons.