CoolFace
Apppublic

XaviGuardia/oa2-agent

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
App README

πŸ€– OA2 Agent - Intelligent Codebase Analysis Tool

<!-- Force HF rebuild: 2025-01-16-19:00 -->

Privacy-first LLM integration with local inference, conversation history, and vector search.

πŸš€ Live Demo

🌐 Try it now: [OA2 Agent on Hugging Face Spaces](https://huggingface.co/spaces/XaviGuardia/oa2-agent)

Upload your codebase ZIP files and start chatting with AI about your code - all inference happens locally for complete privacy!

🎯 Features

  • β€”πŸ”’ Privacy-First: Local LLM inference (no external API calls)
  • β€”πŸ“€ Upload ZIP files of your codebase for analysis
  • β€”πŸ” Semantic search using Qdrant vector database server
  • β€”πŸ’¬ Interactive chat with conversation memory and context
  • β€”πŸ“‹ Context-aware responses using retrieved code snippets
  • β€”βš‘ GPU Acceleration in HF Spaces for fast inference
  • β€”πŸŽ― Token management for efficient LLM interactions

πŸ”’ Local LLM Support

Privacy-First Design

  • β€”βœ… All inference happens locally - your code never leaves your environment
  • β€”βœ… No API keys required - no external service dependencies
  • β€”βœ… GPU acceleration when available (HF Spaces auto-detects)
  • β€”βœ… Dual environment support - works in both local dev and HF Spaces

Supported Providers

  • β€”Ollama (recommended for local development)
  • β€”Hugging Face Transformers (for both local and HF Spaces)

Quick Configuration

yaml
# Local development with Ollama (default)
llm:
  provider: ollama
  model: llama3

# Local development with Hugging Face
llm:
  provider: huggingface
  model: microsoft/DialoGPT-medium
  device: auto  # auto-detects GPU/CPU

πŸ“– See [LOCAL_LLM_GUIDE.md](LOCAL_LLM_GUIDE.md) for complete setup instructions and configuration options.

πŸ’‘ How to Use

  1. 1.Upload a codebase ZIP file in the sidebar
  2. 2.Give it a collection name for organization
  3. 3.Start a chat session to explore your code
  4. 4.Ask questions about your codebase - all processed locally!

πŸ’­ Example Questions

  • β€”"How does authentication work in this codebase?"
  • β€”"Show me the main classes and their relationships"
  • β€”"What are the database connection patterns?"
  • β€”"Explain the API endpoints and their functionality"

πŸ› οΈ Architecture

This deployment runs in a single Docker container with:

  • β€”OA2 Agent: Core analysis engine with local LLM inference
  • β€”Qdrant Server: Vector database for semantic search
  • β€”Streamlit UI: Interactive web interface
  • β€”ChatSession: Persistent conversation management
  • β€”Local LLM: Privacy-first inference (Ollama/HuggingFace)

Powered by: OA2 Agent + Local LLMs + Qdrant Server + Streamlit

![CI Status](https://github.com/xaviguardia/oa2/actions) ![Coverage](https://github.com/xaviguardia/oa2) ![Python 3.12+](https://www.python.org/downloads/) ![HF Spaces](https://huggingface.co/spaces/XaviGuardia/oa2-agent)

OA2 Agent transforms how you explore and understand codebases using AI-powered semantic search and interactive analysis with complete privacy through local LLM inference.

πŸš€ Core Features

  • β€”πŸ“¦ ZIP Import: Import entire codebases from ZIP files into Qdrant vector database
  • β€”πŸ” Semantic Search: Natural language search across your codebase using embeddings
  • β€”πŸ€– Interactive Chat: Local LLM-powered conversations about your code with context-aware responses
  • β€”πŸ”’ Privacy-First: All LLM inference happens locally - your code never leaves your environment
  • β€”βš‘ Fast Setup: One-command Docker deployment with persistent storage

πŸ“‹ Quick Start

1. Prerequisites

bash
# Python 3.12+ and Docker required
python --version  # Should be 3.12+
docker --version

# For local LLM support (optional)
# Install Ollama for easy model management
brew install ollama  # macOS
# OR curl -fsSL https://ollama.ai/install.sh | sh  # Linux

2. Installation

bash
git clone https://github.com/xaviguardia/oa2.git
cd oa2
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt  # Includes transformers and torch for local LLM
pip install -e .

3. Start Services

bash
# Start Qdrant vector database
docker-compose -f tests/docker-compose.yml up -d

# For Ollama users: Pull a model
ollama pull llama3

# Verify Qdrant is running
curl http://localhost:6333/health

4. Usage Examples

Import Codebase
bash
# Import a ZIP file into Qdrant
oa2 import-zip /path/to/your-project.zip --collection my-project
Search Code
bash
# Natural language search
oa2 search "authentication functions" --collection my-project

# Get JSON output for programmatic use
oa2 search "database connections" --collection my-project --format json
Interactive Analysis (Local LLM)
bash
# Start interactive chat session with local LLM
oa2 chat --collection my-project
# Now ask questions like:
# "How does authentication work in this codebase?"
# "Show me all database-related functions"
# "What security patterns are used?"
# All processed locally for complete privacy!

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   CLI Layer     β”‚    β”‚  Service Layer  β”‚    β”‚  Vector Store   β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ import-zip    │───▢│ β€’ IndexerService│───▢│  Qdrant Server  β”‚
β”‚ β€’ search        β”‚    β”‚ β€’ Retriever     β”‚    β”‚                 β”‚
β”‚ β€’ chat          β”‚    β”‚ β€’ AgentService  β”‚    β”‚ Collections:    β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚ - codebase-docs β”‚
β”‚                 β”‚    β”‚ Config & LLM    β”‚    β”‚ - file-chunks   β”‚
β”‚                 β”‚    β”‚ (Local/Private) β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ”§ Development and Testing

⚠️ MANDATORY: Local Testing Before Deployment

NEVER deploy without running the full local test suite first.

bash
# Run complete validation pipeline
./scripts/local_test.sh

This script validates:

  • β€”βœ… Code linting and formatting
  • β€”βœ… Unit tests with 89% coverage requirement
  • β€”βœ… Streamlit app integration tests
  • β€”βœ… Docker build validation
  • β€”βœ… Container startup and health checks
  • β€”βœ… Local LLM functionality

Development Workflow

  1. 1.Make changes to code
  2. 2.Run local tests: ./scripts/local_test.sh
  3. 3.Fix any failures before committing
  4. 4.Commit and push (triggers CI)
  5. 5.Deploy only after CI passes

Manual Testing

bash
# Test locally with Docker (includes local LLM)
docker build -t oa2-local .
docker run -p 7860:7860 oa2-local
# Open http://localhost:7860

# Test with development server
cd src && streamlit run ../app.py

# Test local LLM functionality
python -c "
from oa2_agent.config import get_config
from oa2_agent.services.llm_service import get_llm_service
service = get_llm_service(get_config().llm)
print('LLM Available:', service.is_available())
"

Debugging Failed Deployments

bash
# Check container logs
docker logs <container-name>

# Test specific components
python -m pytest tests/integration/test_streamlit_integration.py -v

# Validate configuration
python -c "from oa2_agent.config import get_config; print(get_config())"

# Test LLM service
python -c "
from oa2_agent.services.llm_service import get_llm_service
from oa2_agent.config import get_config
service = get_llm_service(get_config().llm)
print(f'Provider: {get_config().llm.provider}')
print(f'Available: {service.is_available()}')
"

πŸ“ Project Structure