Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Recommender System

A system that learns coding patterns from a Git repository and provides intelligent code recommendations.

Features

  • Clone and analyze Git repositories
  • Extract code patterns and style
  • Generate context-aware code suggestions
  • Support for multiple programming languages
  • Vector-based semantic search
  • Command-line interface for easy use

Installation

From Source

  1. Clone this repository
  2. Install the package in development mode:
    pip install -e .

From PyPI (Coming Soon)

pip install code-recommender

Usage

Command Line Interface

The easiest way to use the code recommender is through the command line.

Index a Repository

To analyze a Git repository and create a search index:

code-recommender index https://github.com/username/repo.git

Options:

  • --local-path: Specify a local directory to clone to (default: temp directory)
  • --update: Update the repository if it already exists
  • --no-cleanup: Keep the cloned repository after indexing
  • --verbose: Show detailed output

Search for Code Suggestions

Search for code suggestions based on a query:

code-recommender search "function to sort a list" --repo-url https://github.com/username/repo.git

Options:

  • --repo-url: URL of the Git repository to search in
  • --local-path: Path to a local repository
  • -n, --num-results: Number of results to return (default: 5)
  • --language: Filter results by programming language
  • -i, --interactive: Start an interactive search session
  • --verbose: Show detailed output

Generate Code

Generate code based on a natural language description:

code-recommender generate "a function to calculate factorial in Python" --repo-url https://github.com/username/repo.git

Options:

  • --max-length: Maximum length of generated code (default: 200)
  • --temperature: Controls randomness (0.0-1.0, lower is more deterministic, default: 0.7)
  • --top-p: Nucleus sampling parameter (0.0-1.0, default: 0.95)
  • --num-sequences: Number of code samples to generate (default: 1)
  • --no-context: Disable using the indexed codebase for context
  • --repo-url: URL of the Git repository to use for context
  • --local-path: Path to a local repository to use for context
  • --verbose: Show detailed output

Interactive Mode

For a continuous search experience with multiple queries in one session:

# Start interactive mode
code-recommender search --interactive --persist-dir ./flask_demo

# Then type queries interactively:
# Search query: route decorator
# Search query: error handler
# Search query: exit

Features:

  • 🔍 Continuous searching without restarting
  • ⚡ Fast queries (database loaded once)
  • 💡 Built-in help with help command
  • 🎯 Filter by language: --language python
  • 📊 Limit results: -n 3

See INTERACTIVE_MODE_GUIDE.md for detailed usage and examples.

Python API

You can also use the code recommender as a Python library:

from code_recommender import CodeRecommender

# Initialize with a Git repository URL
recommender = CodeRecommender()

# Index a repository
recommender.index_repository("https://github.com/username/repo.git")

# Get code suggestions
suggestions = recommender.get_suggestions("function to sort a list", n_results=5)

# Print the suggestions
for i, suggestion in enumerate(suggestions, 1):
    print(f"Suggestion {i}:")
    print(f"File: {suggestion['metadata']['file_path']}")
    print(f"Function: {suggestion['metadata']['function_name']}")
    print(suggestion['code'])
    print("-" * 80)

Code Generation

The code generation feature uses the bigcode/starcoder model by default, which is a state-of-the-art code generation model. The first time you use the generation feature, the model will be downloaded (about 30GB).

Context-Aware Generation

When you provide a repository URL or local path, the code generator will:

  1. Index the repository
  2. Find relevant code snippets based on your prompt
  3. Use those snippets as context for better code generation

This helps the model generate code that matches the style and patterns of the existing codebase.

Example: Generate with Context

# Generate code using a specific repository for context
code-recommender generate \
    "a function to parse JSON configuration" \
    --repo-url https://github.com/username/config-parser.git \
    --max-length 300

See tests/README.md for detailed information about each test.

Configuration

Environment Variables

Create a .env file in your project root to configure the application:

# Copy the example file
cp .env.example .env

# Edit with your values
nano .env

Example .env file:

# Required for Claude-based generation
ANTHROPIC_API_KEY=your_api_key_here

# Optional settings
CHROMA_DB_PATH=./chroma_db
EMBEDDING_MODEL=jinaai/jina-code-embeddings-0.5b
GENERATION_MODEL=claude-sonnet-4-20250514
TOKENIZERS_PARALLELISM=false
LOG_LEVEL=INFO

See ENV_SETUP.md for detailed configuration instructions.

About

A system that learns coding patterns from a Git repository and provides intelligent code recommendations.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages