The AI Politician chat system provides an interactive interface for conversing with AI versions of politicians. The system simulates the speaking style, policy positions, and personality of specific politicians (currently Joe Biden and Donald Trump).
- System Architecture
- How It Works
- Chat Modes
- Setup and Usage
- Politician Speaking Styles
- Technical Implementation
- Troubleshooting
- Example Prompts
- Advanced Features
The chat system is structured in multiple layers:
-
Entry Points:
aipolitician.py: Main launcher script for all modes- Various helper scripts in the
scripts/directory
-
Core Components:
- LangGraph System: A workflow-based system that processes user input through multiple stages
- RAG System: Retrieval-Augmented Generation for factual knowledge integration
- Response Models: Fine-tuned Mistral-7B models with politician-specific adapters
-
Processing Pipeline:
- Context Agent: Extracts topics and retrieves relevant knowledge
- Sentiment Agent: Analyzes query sentiment and determines if deflection is needed
- Response Agent: Generates the final politician response
When you chat with the AI Politician, the following process occurs:
graph TD
A[User Input] --> B[Context Agent]
B --> C[Sentiment Agent]
C --> D[Response Agent]
D --> E[Final Response]
B -.-> F[ChromaDB]
F -.-> B
-
Your input is received by the system
-
The Context Agent:
- Identifies topics and policy areas in your question using TinyLlama-1.1B-Chat
- Retrieves relevant facts from the ChromaDB database (if RAG is enabled)
- Formats context information for the response generation
-
The Sentiment Agent:
- Analyzes the sentiment of your question using RoBERTa-base-sentiment
- Detects potential "gotcha" questions or personal attacks
- Determines if the question should be deflected based on sentiment score
-
The Response Agent:
- Loads the appropriate politician model (Biden or Trump)
- Constructs a prompt with the context and sentiment analysis
- Generates a response using the fine-tuned Mistral-7B with politician-specific adapters
- Formats the response to match the politician's speaking style
The system offers three main chat modes:
Provides a standard conversational experience without technical details.
python aipolitician.py chat biden
# or
python aipolitician.py chat trumpShows the clean chat response plus debugging information such as sentiment analysis, knowledge retrieval status, and deflection status.
python aipolitician.py debug biden
# or
python aipolitician.py debug trumpDisplays detailed information about each step in the workflow process, showing how the system analyzes the query and generates a response.
python aipolitician.py trace biden
# or
python aipolitician.py trace trump- Python 3.9+ installed
- CUDA-capable GPU (optional but recommended)
- Appropriate Python packages installed
-
Clone the repository:
git clone [repository-url] cd aipolitician -
Install dependencies:
pip install -r requirements/requirements-chat.txt
To start a chat with Biden:
python aipolitician.py chat bidenTo start a chat with Trump:
python aipolitician.py chat trumpTo see sentiment analysis and other debug details:
python aipolitician.py debug bidenTo see the complete workflow execution:
python aipolitician.py trace bidenIf you encounter issues with the RAG system or don't want to use factual retrieval:
python aipolitician.py chat biden --no-ragBiden's responses are designed to mimic his authentic speaking style with:
- Verbal fillers like "Look, folks", "Here's the deal", "I'm not joking"
- Personal anecdotes about his family, Scranton, or his working-class upbringing
- Conversational, unstructured flow with natural pauses
- Occasional topic shifts that circle back to the main point
- References to the "soul of America" and "dignity"
Trump's responses feature his characteristic style including:
- Short, emphatic sentences
- Superlative language ("tremendous", "the best")
- Repetition for emphasis
- Direct, confrontational approach to criticism
- References to "Make America Great Again"
| Component | Model | Purpose | Technical Details |
|---|---|---|---|
| Response Generation | Mistral-7B-Instruct-v0.2 | Generate politician responses |
|
| Context Extraction | TinyLlama-1.1B-Chat-v1.0 | Identify topics & policy areas |
|
| Sentiment Analysis | RoBERTa-base-sentiment | Detect question sentiment |
|
| RAG Embeddings | all-MiniLM-L6-v2 | Create document vectors |
|
The Retrieval-Augmented Generation system provides factual knowledge to enhance responses:
ChromaDB (Persistent Client)
└── Collection: "politicians"
├── Documents (Political content)
├── Metadata (politician name, content type, source URL)
└── Embeddings (384-dimensional vectors)
- Database Engine: ChromaDB with SQLite backend
- Storage Location:
/opt/chroma_db(persistent storage) - Collection Structure:
- Document ID format:
{politician_id}_entry_{idx} - Metadata fields:
politician_name,content_type,source - Vector dimensions: 384 (from all-MiniLM-L6-v2)
- Document ID format:
-
Query Preprocessing:
- User question is captured
- Query text is sent to embedding model
-
Vector Embedding:
- SentenceTransformer converts query to 384-dimensional vector
- Embedding is formatted as a float array
-
Similarity Search:
- ChromaDB performs vector similarity search using cosine distance
- Query is filtered by politician name to ensure relevance
- Top 5 most similar documents are retrieved
-
Context Integration:
- Retrieved documents are formatted with source information
- Context is added to the prompt for the response model
- Response model generates answer influenced by retrieved facts
- Text documents are split into ~1000 character chunks during formatting
- Each chunk becomes a separate document in ChromaDB
- Chunking preserves paragraph boundaries where possible
- Chunks maintain sufficient context while optimizing for vector search
If you see "RAG database system not available":
- Ensure ChromaDB is installed:
pip install -r requirements/requirements-chat.txt - Check that the DB directory exists:
/opt/chroma_db - Try running with
--no-ragflag to bypass the knowledge database
If models fail to load:
- Check for proper CUDA installation
- The system will use a fallback response generator
- Try running on a machine with more GPU memory
Try these example queries to see the system in action:
- "What's your vision for America's future?"
- "How would you handle the situation at the southern border?"
- "Tell me about your infrastructure plan"
- "What do you think about your political opponent?"
- "How are you addressing climate change?"
- "Can you tell me about your family?"
- "What are your thoughts on the economy?"
You can customize model paths with environment variables:
BIDEN_ADAPTER_PATH: Path to Biden's model adapter (default: "nnat03/biden-mistral-adapter")TRUMP_ADAPTER_PATH: Path to Trump's model adapter (default: "nnat03/trump-mistral-adapter")