Skip to content

Repository files navigation

title Personal Website Backend
emoji 🌐
colorFrom blue
colorTo indigo
sdk docker
pinned false

RAG LLM Agent Backend

This is the backend service for my personal website, implementing a Retrieval-Augmented Generation (RAG) agent that processes queries about my professional background and experience.

Features

  • RAG system for retrieving relevant information from a knowledge base
  • Integration with GitHub and LinkedIn for external data
  • Groq LLM integration for generating responses
  • FastAPI server for handling requests

API Usage

Send a POST request to /query with a JSON body containing your query:

curl -X POST "https://huggingface.co/spaces/ereinha3/personal-website/query" \
     -H "Content-Type: application/json" \
     -d '{"text": "Your query here"}'

The response will include:

  • The original query
  • LLM-generated response
  • Relevant context from the knowledge base
  • A list of relevant documents

Environment Variables

The following environment variables need to be set in your Hugging Face Space:

  • GITHUB_TOKEN: Your GitHub personal access token
  • GITHUB_USERNAME: Your GitHub username
  • LINKEDIN_EMAIL: Your LinkedIn email
  • LINKEDIN_PASSWORD: Your LinkedIn password
  • GROQ_API_KEY: Your Groq API key

Local Development

  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables in a .env file

  2. Run the server:

python main.py

The server will start on http://localhost:8000

Local Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file with your API keys:
# GitHub credentials
GITHUB_TOKEN=your_github_personal_access_token
GITHUB_USERNAME=your_github_username

# LinkedIn credentials
LINKEDIN_EMAIL=your_linkedin_email
LINKEDIN_PASSWORD=your_linkedin_password

# Groq API credentials
GROQ_API_KEY=your_groq_api_key
  1. Create a knowledge directory and add your documents:
knowledge/
├── resume/
│   ├── resume.pdf
│   └── resume.md
├── projects/
│   ├── project1/
│   │   ├── README.md
│   │   └── code/
│   └── project2/
│       ├── README.md
│       └── code/
└── other/
    └── additional_info.md
  1. Run the server:
python main.py

The server will start on http://localhost:8000.

Deployment to Hugging Face Spaces

  1. Create a new Space on Hugging Face:

    • Go to https://huggingface.co/spaces
    • Click "Create new Space"
    • Choose a name for your space
    • Select "Docker" as the SDK
    • Choose "Public" or "Private" visibility
  2. Add your environment variables:

    • Go to your Space settings
    • Navigate to the "Repository Secrets" section
    • Add the following secrets:
      • GITHUB_TOKEN
      • GITHUB_USERNAME
      • LINKEDIN_EMAIL
      • LINKEDIN_PASSWORD
      • GROQ_API_KEY
  3. Push your code to the Space:

    • The Space will automatically build and deploy your application
    • You can monitor the build process in the "Factory" tab
  4. Access your deployed application:

    • Once deployed, your application will be available at https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME

Troubleshooting Deployment Issues

If you encounter issues when pushing to Hugging Face Spaces, try these solutions:

  1. Check Git Configuration:

    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
  2. Verify Remote URL:

    git remote -v

    Make sure the URL is correct: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME

  3. Try Using Hugging Face CLI:

    pip install huggingface_hub
    huggingface-cli login
    git push space main
  4. Check File Size Limits:

    • Hugging Face has file size limits
    • If your knowledge base is large, consider hosting it elsewhere
  5. Check Docker Build Logs:

    • Go to your Space's "Factory" tab
    • Look for any error messages in the build logs
  6. Simplify Your Dockerfile:

    • If the build is failing, try a simpler Dockerfile first
    • Once that works, gradually add back the complexity
  7. Use Hugging Face's Web Interface:

    • Instead of pushing via Git, try uploading files directly through the web interface
    • This can help identify if the issue is with Git or with the files themselves

Notes

  • The agent uses the sentence-transformers/all-MiniLM-L6-v2 model for embeddings
  • Documents are chunked into 1000-character segments with 200-character overlap
  • The agent returns the top 3 most relevant documents for each query
  • External data (GitHub and LinkedIn) is updated every 24 hours
  • The Groq Mixtral model is used for generating responses

About

Backend RAG architecture for my personal website using OpenAI API for LLM compute.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages