Skip to content

AI-powered debate system that orchestrates multi-model discussions with an automated judge, cost tracking, and a Gradio UI.

Notifications You must be signed in to change notification settings

knr83/ai-debate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Debate System

AI-powered debate system with multiple models, cost tracking, and web interface.

🚀 Features

  • Multi-Model Debates: Conduct debates between different AI models (GPT-4, GPT-5, etc.)
  • Intelligent Judging: Automated judgment system to evaluate debate quality
  • Cost Tracking: Real-time cost estimation and tracking for API usage
  • Configurable Rounds: Adjustable debate rounds (1-3) for different complexity levels
  • Token Management: Configurable token limits (100-4000) for response control
  • Modern Web Interface: Built with Gradio for an intuitive user experience
  • Environment Configuration: Secure API key management via .env files

🛠️ Technology Stack

  • Python 3.11+: Core programming language
  • OpenAI API: Integration with various GPT models
  • Gradio: Modern web interface framework
  • Python-dotenv: Environment variable management
  • Logging: Comprehensive application logging

📋 Prerequisites

  • Python 3.11 or higher
  • OpenAI API key
  • Virtual environment (recommended)

🚀 Installation

  1. Clone the repository

    git clone <repository-url>
    cd ai-debate
  2. Create and activate virtual environment

    python -m venv venv
    
    # On Windows
    .\venv\Scripts\Activate.ps1
    
    # On macOS/Linux
    source venv/bin/activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure environment variables Create a .env file in the project root:

    OPENAI_API_KEY=your_openai_api_key_here

🎯 Usage

  1. Start the application

    python main.py
  2. Access the web interface Open your browser and navigate to http://localhost:7860

  3. Configure debate settings

    • Enter your debate question
    • Select AI models for debaters and judge
    • Adjust token limits and debate rounds
    • Set cost limits if desired
  4. Launch the debate Click "Start Debate" to begin the AI-powered discussion

🔧 Configuration

Available Models

  • GPT-5 Models: gpt-5-mini, gpt-5-nano
  • GPT-4 Models: gpt-4o-mini, gpt-4o, gpt-4-turbo, gpt-4
  • GPT-3.5 Models: gpt-3.5-turbo, gpt-3.5-turbo-16k

Cost Structure

The system tracks costs based on OpenAI's pricing:

  • Input tokens: $0.0015 - $0.30 per 1M tokens
  • Output tokens: $0.002 - $2.00 per 1M tokens

Debate Settings

  • Rounds: 1-3 debate rounds
  • Token Limits: 100-4000 tokens per response
  • Cost Limits: Optional budget constraints

📁 Project Structure

ai-debate/
├── main.py              # Main application logic and orchestration
├── ui.py                # Gradio UI components and interface
├── config.py            # Configuration constants and settings
├── styles.css           # Custom CSS styling
├── requirements.txt     # Python dependencies
├── README.md           # Project documentation
├── .env                # Environment variables (create this)
└── venv/               # Virtual environment

🔍 Core Components

main.py

  • enhanced_debate_function: Main debate orchestration with logging
  • validate_inputs: Universal input validation
  • estimate_cost_for_question: Cost estimation before debate
  • CostTracker: Class-based cost management
  • LogManager: Centralized logging with performance tracking

ui.py

  • DebateUI: Main UI class with Gradio components
  • create_interface: Web interface setup and event handlers
  • setup_event_handlers: UI interaction management

config.py

  • Model configurations: Available AI models and pricing
  • UI settings: Interface configuration and defaults
  • Validation limits: Input constraints and presets

🚨 Error Handling

The system includes comprehensive error handling for:

  • Invalid API keys
  • Network connectivity issues
  • Input validation errors
  • Cost limit exceeded scenarios
  • Model availability issues

📊 Enhanced Logging

Enhanced logging system with centralized management:

  • Decorator-based logging: Automatic function entry/exit tracking
  • Performance metrics: Execution time monitoring for all operations
  • Cost tracking: Real-time API usage and cost calculation
  • Error handling: Centralized error logging with context
  • Operation stack: Nested operation tracking for complex workflows

🔒 Security

  • API keys are stored in environment variables
  • Input sanitization prevents injection attacks
  • Rate limiting considerations for API usage
  • Secure token handling

🧪 Testing

To test the system:

  1. Ensure all dependencies are installed
  2. Verify your OpenAI API key is valid
  3. Start with simple questions to test functionality
  4. Monitor the logs for any issues

🚀 Deployment

The application can be deployed using:

  • Local Development: Direct Python execution
  • Docker: Containerized deployment (Dockerfile not included)
  • Cloud Platforms: Deploy to Heroku, AWS, or similar platforms

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

For issues and questions:

  1. Check the logs for error messages
  2. Verify your API key and configuration
  3. Ensure all dependencies are properly installed
  4. Check OpenAI API status and quotas

🔮 Future Enhancements

  • Multi-language Support: Support for debates in different languages
  • Advanced Analytics: Detailed debate analysis and insights
  • Custom Model Integration: Support for other AI providers
  • Debate Templates: Pre-configured debate scenarios
  • Export Functionality: Save debates in various formats
  • Real-time Collaboration: Multi-user debate participation

Note: This system requires an active OpenAI API key and internet connectivity to function properly.

About

AI-powered debate system that orchestrates multi-model discussions with an automated judge, cost tracking, and a Gradio UI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published