6.9 KiB
6.9 KiB
NPC Dialogue System - Dubai Metaverse
Overview
This document describes the ChatGPT-powered dynamic dialogue system for NPCs in the Dubai Metaverse project (optional feature).
System Architecture
Overview
The dialogue system integrates ChatGPT API to generate dynamic, context-aware dialogue for NPCs, allowing for natural conversations with players.
Components
- BP_DialogueSystem: Main dialogue system blueprint
- API Integration: ChatGPT API client
- Dialogue Handler: Handles dialogue requests and responses
- NPC Integration: Integrates with NPC behavior system
ChatGPT API Integration
API Setup
- API Key: Obtain ChatGPT API key from OpenAI
- Secure Storage: Store API key securely (environment variable, not in repository)
- API Client: Create API client in blueprint or C++
- Configuration: Configure API endpoint and settings
API Configuration
- Model: GPT-3.5-turbo or GPT-4
- Temperature: 0.7-0.9 (creative but coherent)
- Max Tokens: 100-200 (concise responses)
- System Prompt: Define NPC personality and context
Dialogue System Blueprint
BP_DialogueSystem
Main dialogue system controller
Functions
RequestDialogue
- Purpose: Request dialogue from ChatGPT
- Input: Player message, NPC context
- Output: Generated dialogue response
- Implementation: API call to ChatGPT
ProcessResponse
- Purpose: Process API response
- Input: API response
- Output: Formatted dialogue
- Implementation: Parse and format response
GetNPCContext
- Purpose: Get NPC context for dialogue
- Input: NPC reference
- Output: NPC context (name, location, personality)
- Implementation: Gather NPC information
NPC Context
Context Information
NPC Identity
- Name: NPC name
- Role: NPC role (tourist, resident, business person)
- Personality: Personality traits
- Background: Background information
Location Context
- Current Location: Where NPC is located
- District: Dubai Marina
- Landmarks: Nearby landmarks
- Activities: Current activities
Conversation Context
- Previous Messages: Conversation history
- Topic: Current conversation topic
- Mood: NPC mood/emotional state
System Prompts
NPC Personality Prompts
Example: Tourist NPC
You are a tourist visiting Dubai Marina. You are friendly, curious, and excited about Dubai.
You speak in a casual, enthusiastic manner. Keep responses brief (1-2 sentences).
You know about Dubai Marina, Cayan Tower, and the luxury lifestyle in Dubai.
Example: Resident NPC
You are a resident of Dubai Marina. You are knowledgeable about the area, professional,
and helpful. You speak in a friendly but professional manner. Keep responses brief (1-2 sentences).
You know about local restaurants, shops, and the Marina lifestyle.
Example: Business Person NPC
You are a business person in Dubai. You are professional, busy, and focused.
You speak in a professional, concise manner. Keep responses brief (1-2 sentences).
You know about business in Dubai, the financial district, and professional services.
Dialogue Flow
Player Interaction
- Player Approaches NPC: Player interacts with NPC
- Dialogue UI: Dialogue UI appears
- Player Input: Player types or selects message
- Dialogue Request: System requests dialogue from ChatGPT
- NPC Response: NPC speaks generated dialogue
- Continuation: Conversation continues
Implementation
- Interaction System: Use interaction system to trigger dialogue
- UI Widget: Create dialogue UI widget
- API Call: Make API call to ChatGPT
- Response Processing: Process and display response
- Audio: Play NPC voice (optional, text-to-speech)
API Integration Script
npc_dialogue_api.py
Python script for API integration (optional)
Functions
- send_dialogue_request: Send request to ChatGPT API
- process_response: Process API response
- format_dialogue: Format dialogue for display
Usage
- Standalone: Run as standalone service
- Integration: Integrate with Unreal via HTTP requests
- Caching: Cache responses for performance
Performance Considerations
Optimization
- Caching: Cache common responses
- Rate Limiting: Limit API calls per NPC
- Response Time: Optimize for quick responses
- Fallback: Fallback to pre-written dialogue if API fails
Cost Management
- API Costs: Monitor API usage and costs
- Token Limits: Limit tokens per request
- Request Frequency: Limit request frequency
- Caching: Cache responses to reduce API calls
Security
API Key Security
- Never Commit: Never commit API keys to repository
- Environment Variables: Use environment variables
- Secure Storage: Store keys securely
- Access Control: Limit access to API keys
Input Validation
- Sanitize Input: Sanitize player input
- Length Limits: Limit input length
- Content Filtering: Filter inappropriate content
Testing
Dialogue Testing
- Quality: Test dialogue quality
- Context: Test context awareness
- Personality: Test NPC personality consistency
- Response Time: Test response time
Integration Testing
- NPC Integration: Test with NPC system
- UI Integration: Test with dialogue UI
- Performance: Test performance impact
- Error Handling: Test error handling
Fallback System
Pre-Written Dialogue
Fallback if API unavailable
- Greetings: Pre-written greetings
- Common Responses: Common response templates
- Topics: Pre-written dialogue for common topics
Implementation
- Dialogue Database: Store pre-written dialogue
- Topic Matching: Match player input to topics
- Response Selection: Select appropriate response
- Fallback Trigger: Trigger fallback if API fails
Troubleshooting
Common Issues
Issue: API not responding
- Solution: Check API key and connection
- Solution: Implement fallback system
- Solution: Check rate limits
Issue: Dialogue quality poor
- Solution: Refine system prompts
- Solution: Adjust temperature settings
- Solution: Improve context information
Issue: Response time too slow
- Solution: Implement caching
- Solution: Optimize API calls
- Solution: Use faster API model
Documentation
API Documentation
Document API integration:
- API setup
- Configuration
- Usage
- Error handling
Dialogue Documentation
Document dialogue system:
- NPC personalities
- Context information
- System prompts
- Usage examples
Version: 1.0 Last Updated: [Current Date]
Note: This is an optional feature. The project can function without ChatGPT integration using pre-written dialogue or no dialogue system.