MUD Dungeon Creation with GPT Assistance - wwestlake/Labyrinth GitHub Wiki

MUD Dungeon Creation with GPT Assistance

Project Overview

In this project, we are building a tool for owners and admins to easily create and manage various aspects of the MUD (rooms, items, quests, etc.) using an AI assistant (GPT). Owners can write and save themes that can be used to generate content, and GPT will assist in filling out forms based on the user's input and the chosen theme.

The backend is built using .NET 8 Web API with Firebase for authentication and MongoDB for data storage. We will design several endpoints to handle interaction between the frontend and the GPT-powered backend.

System Architecture

1. Admin and Owner Tools

The React-based UI will allow the user to create:

  • Rooms
  • Items
  • Quests
  • Themes

Each tool has access to GPT through an API to help fill out and complete forms, with the option to retry specific fields or generate entirely new suggestions based on a saved theme.

2. High-Level Architecture Breakdown

The architecture is split into three main layers:

  1. React UI:

    • The user interacts with forms (room, item, quest creation) to input data.
    • It communicates with the backend to request GPT assistance, save themes, and submit forms.
    • GPT responses will be in a structured format (JSON) to allow easy population of form fields.
  2. .NET 8 Web API Backend:

    • Handles communication with OpenAI GPT, forwarding user inputs and themes.
    • Manages the saving, loading, and application of themes to different requests.
    • Handles authentication and data storage with MongoDB.
  3. GPT Assistant Logic:

    • Dynamically builds prompts based on the type of entity (room, item, quest) and the user’s partially filled data.
    • Uses the selected theme to guide GPT’s output to match the dungeon world.

3. Component-Level Breakdown for React App

The UI will consist of the following React components:

  • ThemeManager: A component for creating and managing themes.

    • Features:
      • Create and save a theme description (e.g., a dark, eerie world).
      • Load a saved theme and apply it to form generation requests.
  • EntityForm: A form-based component for creating rooms, items, and quests.

    • Features:
      • Dynamically adjust the form based on the selected entity type (room, item, quest).
      • Fill out part of the form manually, then ask GPT to complete it.
      • Regenerate individual fields with GPT assistance if the result is unsatisfactory.
  • GPTResponseViewer: A section to show GPT suggestions and allow the user to accept or reject the results.


4. API & Backend Design

We will design the following API endpoints in the .NET 8 Web API backend. These endpoints will handle session management, GPT interaction, and theme management.

API Endpoints

  1. POST /theme/create

    • Request:
    {
      "name": "Dark Dungeon",
      "description": "This theme is for a dark, eerie world filled with shadows and ancient curses."
    }
    
    • Response:
    {
      "themeId": "uuid",
      "message": "Theme created successfully"
    }
    
  2. GET /theme/:themeId

    • Request: { themeId }
    • Response:
    {
      "name": "Dark Dungeon",
      "description": "This theme is for a dark, eerie world..."
    }
    
  3. POST /gpt/fillForm

    • Request:
    {
      "themeId": "uuid",
      "entityType": "room",
      "partialData": { "description": "A dimly lit cave" }
    }
    
    • Response:
    {
      "filledData": {
        "name": "Forgotten Cavern",
        "description": "A cave with eerie sounds echoing through the corridors...",
        "items": ["Skeleton Key", "Ancient Scroll"]
      }
    }
    
  4. POST /gpt/retryField

    • Request:
    {
      "themeId": "uuid",
      "entityType": "item",
      "field": "description",
      "currentData": "A rusty sword"
    }
    
    • Response:
    {
      "newDescription": "An ancient sword with glowing runes carved into the blade"
    }
    
  5. POST /entity/save (for rooms, items, or quests)

    • Request:
    {
      "entityType": "item",
      "data": {
        "name": "Sword of Dawn",
        "description": "A sword with a shimmering blade that glows in darkness..."
      }
    }
    
    • Response:
    {
      "entityId": "uuid",
      "message": "Item saved successfully"
    }
    

5. Prompt Creation & GPT Interaction

When a user submits partially filled data, the backend constructs a dynamic prompt for GPT based on the theme and entity type.

Example Prompt for Room Generation:

Theme: Dark Dungeon
User Input: { "description": "A dimly lit cave with echoes of dripping water." }
GPT Task: Based on the theme and user input, generate a complete room description.

This prompt helps GPT to align the generated content with the current dungeon theme.


6. Frontend-Backend Communication

In React, Axios can be used for API communication. Here’s how the GPT request and form submission would work.

Service Call to Fill Form with GPT

import axios from 'axios';

export const fillFormWithGPT = async (themeId, entityType, partialData) => {
  const response = await axios.post('/gpt/fillForm', {
    themeId,
    entityType,
    partialData
  });
  return response.data;
};

The response from this API will contain the filled form data, which can be used to update the UI.


7. Backend Implementation in .NET 8 Web API

Below is a general structure for the .NET 8 Web API:

Firebase Authentication Setup

  1. Install Firebase SDK for .NET and integrate Firebase authentication.
  2. Apply [Authorize] attributes to secure endpoints.

MongoDB Integration

Use MongoDB for storing themes, rooms, items, and quests.

API Endpoint for Filling Forms with GPT

[HttpPost("gpt/fillForm")]
public async Task<IActionResult> FillFormWithGPT([FromBody] GPTFormRequest request)
{
    var theme = await _themeService.GetThemeById(request.ThemeId);
    var prompt = _promptBuilder.BuildPrompt(request.EntityType, request.PartialData, theme);

    var gptResponse = await _gptService.GenerateContent(prompt);

    return Ok(new { filledData = gptResponse });
}

MongoDB Model for CodeStore

public class CodeStore
{
    [BsonId]
    public ObjectId Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string UserId { get; set; }
    public DateTime Created { get; set; }
    public DateTime LastModified { get; set; }
    public List<CodeFile> CodeFiles { get; set; } = new List<CodeFile>();
    public SupportedLanguages Language { get; set; }
}

This example demonstrates how we can store rooms, items, and quests in MongoDB.


8. Flow Overview

  1. Create Theme: Owners can create a theme using the ThemeManager component. The theme is saved in MongoDB via the backend.
  2. Partially Fill Form: The user partially fills out a form (room, item, quest).
  3. Call GPT: A request is sent to GPT through the /gpt/fillForm endpoint.
  4. Display GPT Results: The returned data is used to populate the form.
  5. Save the Entity: The user can save the generated content to MongoDB through the /entity/save endpoint.

9. Technical Stack

  • Frontend: React (with Axios for API calls).
  • Backend: .NET 8 Web API with Firebase for authentication.
  • Database: MongoDB for storing themes, rooms, items, and quests.
  • AI Integration: OpenAI GPT API for generating content.

This architecture provides flexibility for admins and owners to interact with GPT dynamically while managing the game’s content creation tools.

⚠️ **GitHub.com Fallback** ⚠️