AI Integration¶
MAID provides built-in support for AI-powered features through multiple LLM providers.
Overview¶
AI integration in MAID enables:
- NPC Dialogue - Natural conversations with AI-powered NPCs
- Content Generation - Generate room descriptions, items, quests
- Dynamic Storytelling - AI-driven narrative elements
Supported Providers¶
Anthropic (Claude)¶
The default and recommended provider:
OpenAI (GPT)¶
Ollama (Local LLMs)¶
For local, self-hosted models:
MAID_AI__DEFAULT_PROVIDER=ollama
MAID_AI__OLLAMA_HOST=http://localhost:11434
MAID_AI__OLLAMA_MODEL=llama2
NPC Dialogue System¶
NPCs can have AI-powered conversations:
from maid_stdlib.components.dialogue import DialogueComponent
npc.add_component(DialogueComponent(
personality="A wise old wizard who speaks in riddles",
knowledge=["ancient magic", "the prophecy", "dragon lore"],
mood="mysterious",
))
# Players can then talk to NPCs
# > talk wizard about the prophecy
Rate Limiting¶
Built-in rate limiting protects your API budget:
MAID_AI_DIALOGUE_GLOBAL_RATE_LIMIT_RPM=60
MAID_AI_DIALOGUE_PER_PLAYER_RATE_LIMIT_RPM=10
MAID_AI_DIALOGUE_DAILY_TOKEN_BUDGET=100000
Content Safety¶
The content filter ensures appropriate responses:
from maid_engine.ai.safety import ContentFilter
filter = ContentFilter(
block_explicit=True,
block_violence=False, # Allow for combat games
custom_blocked_terms=["real-world-politics"],
)