|
| 1 | +# π‘οΈ SafeInfer LLM Chatbot |
| 2 | + |
| 3 | +A secure and intelligent chatbot application powered by the SafeInfer LLM API. This Streamlit-based web application provides a user-friendly interface for interacting with large language models while ensuring safety and security through SafeInfer's content filtering and classification capabilities. |
| 4 | + |
| 5 | +## β¨ Features |
| 6 | + |
| 7 | +- **π Secure Conversations**: Powered by SafeInfer API with built-in content safety filtering |
| 8 | +- **π€ Multiple Model Support**: Choose between GPT-4o and GPT-4o-mini models |
| 9 | +- **π¬ Interactive Chat Interface**: Clean, modern UI with real-time conversation flow |
| 10 | +- **π Response Analysis**: View detailed classification and safety analysis of AI responses |
| 11 | +- **π Regeneration**: Regenerate the last AI response with a single click |
| 12 | +- **π₯ Chat Export**: Export your conversation history in JSON format |
| 13 | +- **π API Health Monitoring**: Test API connectivity and status |
| 14 | +- **βοΈ Configurable Settings**: Customize API keys, models, and preferences |
| 15 | +- **π± Responsive Design**: Works seamlessly on desktop and mobile devices |
| 16 | + |
| 17 | +## β‘ Quick Run |
| 18 | + |
| 19 | +To run the application immediately: |
| 20 | + |
| 21 | +```bash |
| 22 | +cd safeinfer_chatbot_app |
| 23 | +pip install -r requirements.txt |
| 24 | +streamlit run safe_infer_chatbot.py |
| 25 | +``` |
| 26 | + |
| 27 | +Then open your browser to `http://localhost:8501` |
| 28 | + |
| 29 | +## π Quick Start |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +- Python 3.8 or higher |
| 34 | +- SafeInfer API service running (default: `http://localhost`) |
| 35 | +- API key (optional, depending on your SafeInfer setup) |
| 36 | + |
| 37 | +### Installation |
| 38 | + |
| 39 | +1. **Clone the repository** (if not already done): |
| 40 | + ```bash |
| 41 | + git clone <repository-url> |
| 42 | + cd daxa-samples/safeinfer_chatbot_app |
| 43 | + ``` |
| 44 | + |
| 45 | +2. **Install dependencies**: |
| 46 | + ```bash |
| 47 | + pip install -r requirements.txt |
| 48 | + ``` |
| 49 | + |
| 50 | +3. **Set up environment variables** (optional): |
| 51 | + ```bash |
| 52 | + export PEBBLO_API_KEY="pebblo-api-key" |
| 53 | + export PROXIMA_HOST="http://your-proxima-host" |
| 54 | + export PROXIMA_USER_USERNAME="your-proxima-username" |
| 55 | + export PROXIMA_USER_PASSWORD="your-proxima-password" |
| 56 | + ``` |
| 57 | + |
| 58 | +4. **Run the application**: |
| 59 | + ```bash |
| 60 | + streamlit run safe_infer_chatbot.py |
| 61 | + ``` |
| 62 | + |
| 63 | +5. **Open your browser** and navigate to `http://localhost:8501` |
| 64 | + |
| 65 | +## π οΈ Configuration |
| 66 | + |
| 67 | +### Environment Variables |
| 68 | + |
| 69 | +- `PROXIMA_HOST`: Base URL for the SafeInfer API (default: `http://localhost`) |
| 70 | + |
| 71 | +### API Configuration |
| 72 | + |
| 73 | +The application automatically configures the following endpoints: |
| 74 | +- **Responses**: `{PROXIMA_HOST}/safe_infer/llm/v1/responses` |
| 75 | +- **Health Check**: `{PROXIMA_HOST}/safe_infer/healthz` |
| 76 | + |
| 77 | +### Available Models |
| 78 | + |
| 79 | +- `gpt-4o-mini`: Faster, more cost-effective model |
| 80 | +- `gpt-4o`: Full GPT-4o model with enhanced capabilities |
| 81 | + |
| 82 | +## π Usage Guide |
| 83 | + |
| 84 | +### Starting a Conversation |
| 85 | + |
| 86 | +1. **Select a Model**: Choose your preferred model from the sidebar |
| 87 | +2. **Enter API Key** (if required): Add your API key in the configuration section |
| 88 | +3. **Test Connection**: Use the "Test API Connection" button to verify connectivity |
| 89 | +4. **Start Chatting**: Type your message and click "Send" or press Enter |
| 90 | + |
| 91 | +### Chat Features |
| 92 | + |
| 93 | +- **Send Messages**: Type in the text area and click "π Send" |
| 94 | +- **Regenerate Responses**: Click "π Regenerate Last Response" to get a new AI response |
| 95 | +- **Clear History**: Use "Clear Chat History" to start fresh |
| 96 | +- **Export Chat**: Download your conversation as a JSON file |
| 97 | + |
| 98 | +### Response Analysis |
| 99 | + |
| 100 | +When the AI responds, you can expand the "π Response Analysis" section to view: |
| 101 | +- Content classification |
| 102 | +- Safety scores |
| 103 | +- Risk assessments |
| 104 | +- Detailed metadata |
| 105 | + |
| 106 | +## π§ Advanced Configuration |
| 107 | + |
| 108 | +### Customizing the Application |
| 109 | + |
| 110 | +Edit `config.py` to modify: |
| 111 | +- Default models and settings |
| 112 | +- UI styling and colors |
| 113 | +- Error messages and timeouts |
| 114 | +- Export formats and file naming |
| 115 | + |
| 116 | +### API Integration |
| 117 | + |
| 118 | +The application sends requests with the following structure: |
| 119 | +```json |
| 120 | +{ |
| 121 | + "model": "gpt-4o-mini", |
| 122 | + "input": "Your message here", |
| 123 | + "app": "safe_infer_chatbot" |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +## π Project Structure |
| 128 | + |
| 129 | +``` |
| 130 | +safeinfer_chatbot_app/ |
| 131 | +βββ safe_infer_chatbot.py # Main application file |
| 132 | +βββ config.py # Configuration settings |
| 133 | +βββ requirements.txt # Python dependencies |
| 134 | +βββ __init__.py # Package initialization |
| 135 | +βββ README.md # This file |
| 136 | +``` |
| 137 | + |
| 138 | +## π Troubleshooting |
| 139 | + |
| 140 | +### Common Issues |
| 141 | + |
| 142 | +1. **Connection Error**: |
| 143 | + - Ensure SafeInfer API is running |
| 144 | + - Check `PROXIMA_HOST` environment variable |
| 145 | + - Verify network connectivity |
| 146 | + |
| 147 | +2. **API Key Issues**: |
| 148 | + - Confirm API key is correct |
| 149 | + - Check if API key is required for your setup |
| 150 | + |
| 151 | +3. **Model Not Available**: |
| 152 | + - Verify the model name is supported |
| 153 | + - Check API service configuration |
| 154 | + |
| 155 | +4. **Timeout Errors**: |
| 156 | + - Increase timeout in config.py |
| 157 | + - Check API service performance |
| 158 | + |
| 159 | +### Debug Mode |
| 160 | + |
| 161 | +To enable debug logging, add this to your environment: |
| 162 | +```bash |
| 163 | +export STREAMLIT_LOG_LEVEL=debug |
| 164 | +``` |
| 165 | + |
| 166 | +## π€ Contributing |
| 167 | + |
| 168 | +1. Fork the repository |
| 169 | +2. Create a feature branch |
| 170 | +3. Make your changes |
| 171 | +4. Test thoroughly |
| 172 | +5. Submit a pull request |
| 173 | + |
| 174 | +## π License |
| 175 | + |
| 176 | +This project is part of the daxa-samples repository. Please refer to the main repository for license information. |
| 177 | + |
| 178 | +## π Support |
| 179 | + |
| 180 | +For issues related to: |
| 181 | +- **SafeInfer API**: Contact your SafeInfer service provider |
| 182 | +- **Application Bugs**: Open an issue in the repository |
| 183 | +- **Configuration**: Check the config.py file and documentation |
| 184 | + |
| 185 | +## π Related Resources |
| 186 | + |
| 187 | +- [SafeInfer Documentation](https://docs.safeinfer.com) |
| 188 | +- [Streamlit Documentation](https://docs.streamlit.io) |
| 189 | +- [OpenAI API Documentation](https://platform.openai.com/docs) |
| 190 | + |
| 191 | +--- |
| 192 | + |
| 193 | +**π‘οΈ Powered by SafeInfer LLM API | Secure β’ Intelligent β’ Reliable** |
0 commit comments