An AI-powered text suggestion tool that works anywhere you type.
nagging/
├── apps/
│ ├── extension/ # Chrome Extension (TypeScript)
│ └── backend/ # Python Backend (FastAPI)
- Python 3.11+
- Poetry (package manager)
- Redis (optional, for caching)
- HuggingFace API key
- Navigate to the backend directory:
cd apps/backend
- Create and activate virtual environment:
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies with Poetry:
pip install poetry
poetry install --no-root
- Configure environment variables:
cp .env.example .env
# Edit .env and add your HuggingFace API key
The backend uses the following environment variables:
# HuggingFace API Configuration
HF_API_KEY=your_api_key_here
HF_MODEL_URL=https://api-inference.huggingface.co/models/microsoft/phi-2
# Frontend Configuration
FRONTEND_MAX_TOKENS=20 # Maximum tokens to generate
FRONTEND_TEMPERATURE=0.6 # Temperature for text generation
FRONTEND_DEBOUNCE_MS=1000 # Debounce time for suggestions
# AI Request Parameters
AI_DO_SAMPLE=true # Whether to use sampling
AI_TOP_P=0.9 # Top-p sampling parameter
AI_STOP_TOKENS=\n,.,!,? # Tokens to stop generation
AI_RETURN_FULL_TEXT=false # Whether to return full text
AI_REQUEST_TIMEOUT=30.0 # API request timeout in seconds
Start the FastAPI server:
# Make sure you're in the src directory
cd src
# Run with Poetry
poetry run python main.py
# Or if already in Poetry shell
python main.py
-
/api/suggest
- Get text suggestions- POST request with JSON body:
{ "text": "Your text here", "max_tokens": 20, "temperature": 0.6 }
- POST request with JSON body:
-
/api/suggest/stream
- Stream text suggestions- Same request format as
/api/suggest
- Returns Server-Sent Events (SSE)
- Same request format as
The backend uses FastAPI with async support and integrates with HuggingFace's Inference API. Key components:
ai/service.py
- Core AI service for text suggestionsapi/models.py
- Pydantic models for request/responsemain.py
- FastAPI application and routes
All development tools are configured in pyproject.toml
:
- Code Formatting: black, isort
- Linting: ruff
- Type Checking: mypy
- Testing: pytest, pytest-asyncio
Run tools through Poetry:
# Format code
poetry run black .
poetry run isort .
# Type checking
poetry run mypy .
# Run tests
poetry run pytest
Coming soon...
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
TBD