This project, AI-NPC, is a Minecraft mod designed to create and interact with AI-powered NPCs (Non-Player Characters) using advanced language models. It combines Minecraft's gameplay with AI to enable NPCs that can move, mine, and chat with players. Here's an overview of how the project works and what it is about:
What is AI-NPC?
AI-NPC is a mod that introduces AI-driven NPCs into Minecraft. These NPCs are powered by large language models (LLMs), such as OpenAI's GPT models or local models using Ollama. By integrating AI, the NPCs can perform tasks like:
- Movement: Navigate the Minecraft world.
- Mining: Interact with the game environment by mining blocks.
- Chatting: Communicate with players through natural language.
The project consists of two main components:
- AI-NPC Launcher: A mod that runs on the Minecraft Fabric server and manages the AI-NPC client and its configuration.
- AI-NPC Client: The client-side mod that handles the NPC's logic, AI interactions, and integrates with LLMs.
How Does AI-NPC Work?
1. AI Integration
The mod uses Large Language Models (LLMs) to power the NPCs' intelligence. Two LLM options are supported:
- OpenAI (Cloud-based):
- Uses OpenAI's GPT models (e.g., GPT-4 or GPT-3.5).
- Requires an API key to interact with OpenAI's API.
- Ollama (Local LLM):
- Runs AI models locally on the user's machine.
- Reduces reliance on external APIs and offers offline functionality.
The AI is responsible for generating responses, understanding contextual prompts, and deciding the NPC's actions.
2. Minecraft Mod Architecture
Server-Side (Launcher)
- The AI-NPC Launcher is a Fabric mod that runs on the Minecraft server.
- It handles:
- Configuration of the AI models.
- Commands for managing NPCs (e.g., spawning, removing, and configuring NPCs).
- Communication between the Minecraft server and the AI-NPC client.
Client-Side (AI-NPC Client)
- The AI-NPC Client is where the NPC logic is implemented. It:
- Loads the AI model configuration (e.g., OpenAI or Ollama settings).
- Initializes the NPC and connects it to the server.
- Uses LLMs to:
- Generate natural language responses.
- Process player interactions.
- Perform tasks like mining or movement based on input.
3. Key Features
NPC Configuration
NPCs are spawned and configured using Minecraft commands:
Player Interaction
Players can chat directly with NPCs by typing in the chat. The NPC uses its AI to generate responses based on the context.
LLM Integration
- The NPC interacts with the LLMs through dedicated clients:
- OpenAiClient: Uses OpenAI's API to generate responses and embeddings.
- OllamaClient: Connects to a locally running Ollama server to perform similar tasks.
Tasks and Actions
The NPC is capable of interpreting commands and performing in-game actions like:
- Chatting: Responding to players in natural language.
- Mining: Breaking blocks in the game world.
- Movement: Navigating to specific locations.
4. How the Code Works
Initialization
- The server-side mod initializes upon the Minecraft server starting (
AiNPCLauncher.java).
- The client-side mod waits for the Minecraft client to load and then initializes the NPC (
AiNPCClient.java).
LLM Clients
- The AI-NPC client interacts with LLMs through implementations of the
ILLMClient interface:
- OpenAiClient:
- Sends prompts to OpenAI's API.
- Receives text responses or embeddings for tasks.
- OllamaClient:
- Sends prompts to a locally running Ollama server.
- Handles responses locally without relying on external APIs.
- Both clients handle system prompts (e.g., instructions for task structure) and user prompts (e.g., player input).
Commands
- The mod registers commands using the
CommandManager class, which allows server operators to spawn, remove, and configure NPCs.
Configuration
- Configuration settings are stored in properties files managed by
ModConfig.java.
- Default settings include:
- OpenAI model (
gpt-4o-mini).
- Ollama model (
gemma2).
- Server port (
25565 for Minecraft).
Requirements
To use this mod, the following are required:
- Minecraft Version: 1.20.4.
- Dependencies:
- FabricAPI: For running Fabric mods.
- Java 17: Required by the mod.
- LLM Setup:
- OpenAI: Requires an API key and credits for usage.
- Ollama: Requires downloading and running the Ollama server locally.
Summary
AI-NPC is a cutting-edge Minecraft mod that integrates AI-powered NPCs into the game. It leverages advanced LLMs to enable NPCs that can interact with players, mine, and navigate the game world. The mod is flexible, supporting both cloud-based (OpenAI) and local (Ollama) LLMs, making it suitable for a wide range of use cases.
This project is still under active development, with planned features such as combat skills, crafting, and enhanced AI interactions. It's a promising tool for Minecraft players and developers looking to explore the intersection of AI and gaming.