|
# π Smart Auto-Complete - Setup Guide |
|
|
|
This guide will help you set up and run the Smart Auto-Complete application. |
|
|
|
## π Prerequisites |
|
|
|
- **Python 3.8+** (recommended: Python 3.9 or higher) |
|
- **pip** (Python package installer) |
|
- **API Keys** from one or both providers: |
|
- [OpenAI API Key](https://platform.openai.com/api-keys) |
|
- [Anthropic API Key](https://console.anthropic.com/) |
|
|
|
## π Quick Installation |
|
|
|
### Option 1: Automated Installation (Recommended) |
|
|
|
```bash |
|
# Run the installation script |
|
python install.py |
|
``` |
|
|
|
This will: |
|
- Check Python version compatibility |
|
- Install all required dependencies |
|
- Set up environment configuration |
|
- Run setup tests to verify everything works |
|
|
|
### Option 2: Manual Installation |
|
|
|
```bash |
|
# 1. Install dependencies |
|
pip install -r requirements.txt |
|
|
|
# 2. Set up environment |
|
cp .env.example .env |
|
|
|
# 3. Edit .env file with your API keys |
|
# Add your API keys to the .env file |
|
|
|
# 4. Test the setup |
|
python test_setup.py |
|
``` |
|
|
|
## βοΈ Configuration |
|
|
|
### Environment Variables |
|
|
|
Edit the `.env` file with your configuration: |
|
|
|
```env |
|
# Required: Add at least one API key |
|
OPENAI_API_KEY=your_openai_key_here |
|
ANTHROPIC_API_KEY=your_anthropic_key_here |
|
|
|
# Optional: Customize settings |
|
DEFAULT_PROVIDER=openai |
|
MAX_SUGGESTIONS=5 |
|
DEBOUNCE_DELAY=300 |
|
CACHE_TTL=3600 |
|
``` |
|
|
|
### API Keys Setup |
|
|
|
#### OpenAI API Key |
|
1. Go to [OpenAI Platform](https://platform.openai.com/api-keys) |
|
2. Create a new API key |
|
3. Copy the key (starts with `sk-`) |
|
4. Add to `.env` file: `OPENAI_API_KEY=sk-your-key-here` |
|
|
|
#### Anthropic API Key |
|
1. Go to [Anthropic Console](https://console.anthropic.com/) |
|
2. Create a new API key |
|
3. Copy the key (starts with `sk-ant-`) |
|
4. Add to `.env` file: `ANTHROPIC_API_KEY=sk-ant-your-key-here` |
|
|
|
## πββοΈ Running the Application |
|
|
|
```bash |
|
# Start the application |
|
python app.py |
|
``` |
|
|
|
The application will be available at: **http://localhost:7860** |
|
|
|
## π§ͺ Testing |
|
|
|
### Run Setup Tests |
|
```bash |
|
python test_setup.py |
|
``` |
|
|
|
### Run Unit Tests |
|
```bash |
|
# Install test dependencies (if not already installed) |
|
pip install pytest pytest-cov |
|
|
|
# Run all tests |
|
python -m pytest tests/ |
|
|
|
# Run with coverage |
|
python -m pytest tests/ --cov=src/ |
|
``` |
|
|
|
## π Project Structure |
|
|
|
``` |
|
Smart-Auto-Complete/ |
|
βββ app.py # Main Gradio application |
|
βββ src/ |
|
β βββ __init__.py |
|
β βββ autocomplete.py # Core autocomplete logic |
|
β βββ api_client.py # API integration layer |
|
β βββ cache.py # Caching system |
|
β βββ utils.py # Utility functions |
|
βββ config/ |
|
β βββ __init__.py |
|
β βββ settings.py # Configuration management |
|
βββ tests/ |
|
β βββ __init__.py |
|
β βββ test_autocomplete.py |
|
β βββ test_api_client.py |
|
β βββ test_cache.py |
|
βββ requirements.txt # Python dependencies |
|
βββ .env.example # Environment template |
|
βββ install.py # Installation script |
|
βββ test_setup.py # Setup verification |
|
βββ README.md # Main documentation |
|
``` |
|
|
|
## π§ Troubleshooting |
|
|
|
### Common Issues |
|
|
|
#### Import Errors |
|
```bash |
|
# Make sure you're in the correct directory |
|
cd Smart-Auto-Complete |
|
|
|
# Install dependencies |
|
pip install -r requirements.txt |
|
``` |
|
|
|
#### API Key Issues |
|
- Verify your API keys are correct and active |
|
- Check that keys are properly set in `.env` file |
|
- Ensure you have sufficient API credits |
|
|
|
#### Port Already in Use |
|
```bash |
|
# If port 7860 is busy, specify a different port |
|
python app.py --server-port 7861 |
|
``` |
|
|
|
#### Permission Errors |
|
```bash |
|
# On macOS/Linux, you might need: |
|
python3 app.py |
|
|
|
# Or use virtual environment: |
|
python -m venv venv |
|
source venv/bin/activate # On Windows: venv\Scripts\activate |
|
pip install -r requirements.txt |
|
python app.py |
|
``` |
|
|
|
### Debug Mode |
|
|
|
Enable debug mode for detailed logging: |
|
|
|
```bash |
|
# Set in .env file |
|
DEBUG_MODE=true |
|
LOG_LEVEL=DEBUG |
|
``` |
|
|
|
## π― Usage Examples |
|
|
|
### Email Writing |
|
``` |
|
Input: "Dear Mr. Johnson," |
|
Context: Email |
|
β Suggests professional email continuations |
|
``` |
|
|
|
### Code Documentation |
|
``` |
|
Input: "// This function calculates" |
|
Context: Code |
|
β Suggests technical documentation |
|
``` |
|
|
|
### Creative Writing |
|
``` |
|
Input: "Once upon a time, in a kingdom far away" |
|
Context: Creative |
|
β Suggests story continuations |
|
``` |
|
|
|
## π Security Notes |
|
|
|
- API keys are stored locally in `.env` file |
|
- Never commit `.env` file to version control |
|
- Input text is sanitized before processing |
|
- No user data is stored permanently |
|
|
|
## π Support |
|
|
|
If you encounter issues: |
|
|
|
1. Check this setup guide |
|
2. Run `python test_setup.py` to diagnose problems |
|
3. Check the console output for error messages |
|
4. Verify your API keys and internet connection |
|
|
|
## π Success! |
|
|
|
If everything is working correctly, you should see: |
|
- β
All setup tests passing |
|
- π Application running at http://localhost:7860 |
|
- π‘ Real-time suggestions as you type |
|
|
|
Enjoy using Smart Auto-Complete! π |
|
|