AI Dungeon Master for RPG-Text Game

Github Link: github.com/MetinUnlu/LLM_customGPT-textrpg

This Python code is an AI Dungeon Master for a text-based RPG game. It utilizes the Kivy library for the user interface and leverages Mistral or Llama2:7b model for generating interactive storylines and managing the game's narrative flow.

Purpose

This project serves as a practical exploration of Large Language Models (LLMs). It aims to establish a framework for using LLMs to generate dynamic and engaging text, specifically through the creation of a custom AI chatbot.

The core focus lies in:

  • Understanding LLM capabilities: This project investigates the potential of LLMs to produce creative and interactive text responses.
  • Developing custom LLM behavior: By defining templates and guidelines, the project explores how to influence LLM outputs without extensive fine-tuning.
  • Creating an LLM-powered application: Building a functional chatbot demonstrates the practical application of LLMs in real-world scenarios.

Features

  • Character Creation: Players can create their characters by allocating points to different attributes such as vitality, strength, agility, and intelligence.
  • Dynamic Storytelling: The AI Dungeon Master generates a dynamic storyline based on player input, creating an immersive gaming experience.
  • Combat System: The game includes a combat system where players engage in battles with enemies. The outcome of battles is determined by random dice rolls and player decisions.
  • User Interface: The game features a user-friendly interface built using Kivy, allowing players to interact with the game through buttons and text inputs.

Additional Notes

Refer to the Ollama documentation for more details on available models and functionalities: Ollama Documentation. Explore the Langchain documentation for advanced LLM usage patterns: Langchain Documentation.

Main Goal of Project

The code establishes a set of guidelines and templates that the Large Language Model (LLM) follows when generating responses for the game. This ensures a more immersive and controlled storytelling experience, essentially creating a custom chat GPT model behavior without extensive fine-tuning.

Breakdown

    • Template Strings: The code defines multiple template strings to structure the LLM's output:
    • template_header: Sets the overall objective and writing style for the LLM.
    • template_str: Provides information about the player character and additional storytelling guidelines.

Benefits:

  • Consistency: The templates ensure the LLM's responses follow a specific format, enhancing readability and maintaining the narrative flow.
  • Control: The guidelines within the templates steer the LLM's storytelling in a desired direction, preventing unwanted elements like premature combat or conclusive endings.
  • Player Agency: The templates emphasize prompting the player for decisions, fostering a sense of interactivity and control within the game.

This approach ensures consistent LLM output, avoids unwanted elements, and encourages player decision-making, leading to a more engaging gameplay experience.

Future Enhancements

This project lays the groundwork for further exploration in LLM-powered text-adventure games. Here are some exciting possibilities:

  • Dynamic Prompt Generation: Leverage player data like character attributes, location, and world details to craft personalized prompts for a more meaningful narrative.
  • AI-Driven Storytelling: Empower the LLM to actively participate in storytelling by generating descriptions, crafting dialogue, and introducing plot twists based on player choices.
  • Worldbuilding and Quests: Integrate map systems, complex narratives with branching storylines, and procedurally generated quests to create a truly immersive and dynamic game experience.

This project was done to gain experience in LLMs. However, the given concept in this project has not yet been implemented by anyone as of March 2024. Current AI-powered Text-RPG games basically only utilize AI models to create the game flow. However, using dynamic prompt generation by using object information of players, and in more detailed work, inventory, level, experience, stat, skill information combined with a map system and a given set of worlds with missions, a true text-RPG that is actually powered by AI can be achieved.