Skip to main content

A tool to convert GitHub repositories into LLM prompts

Project description

Repository2Prompt

CI Status PyPI version License: MIT

Repository2Prompt is a powerful tool that converts GitHub repositories or local directories into prompts for Large Language Models (LLMs). It extracts the structure and content of repositories, generating structured output for easy understanding and processing by LLMs.

Features

  • Support for both GitHub repositories and local directories
  • Generation of file tree structures
  • Extraction of specified file contents
  • Multiple output formats: Markdown, JSON, plain text, and split format
  • Customizable template system
  • Flexible configuration options

Installation

You can install Repository2Prompt using pip:

pip install repository2prompt

Alternatively, you can install from source:

git clone https://github.com/wctsai20002/repository2prompt.git
cd repository2prompt
pip install .

Usage

Command Line Interface

Repository2Prompt provides a simple command-line interface:

repository2prompt [OPTIONS] INPUT_PATH

Options:

  • -t, --template PATH: Path to a custom Jinja2 template file
  • -f, --format [markdown|json|text|split]: Output format (default: markdown)
  • -o, --output PATH: Output file path (default: repository_name.{format})
  • --help: Show help message

Example:

# Convert a GitHub repository to JSON format and save to a specific file
repository2prompt https://github.com/octocat/octocat.github.io -f json -o output.json

# Convert a local directory to markdown and save with default name
repository2prompt /path/to/local/repo -f markdown

# Use a custom template and save the output to a specific file
repository2prompt https://github.com/user/repo -t custom_template.j2 -o custom_output.md

If no output file is specified, the result will be saved in the current directory with the name repository_name_prompt.{extension}, where {extension} is the chosen output format.

Python API

You can also use Repository2Prompt in your Python code:

from repository2prompt import Repository2Prompt

converter = Repository2Prompt("https://github.com/octocat/octocat.github.io", output_format="json")
result = converter.process()
print(result)

Generates prompts in split format, and then sends each prompt to LLM sequentially.

import yaml
import json
from repository2prompt import Repository2Prompt, CONFIG

converter = Repository2Prompt("https://github.com/octocat/octocat.github.io", output_format="split")
result = converter.process()
prompts = json.loads(result)

for item in prompts:
    prompt = item['prompt']
    content = item['content']
    
    # Combine prompt and content
    full_message = f"{prompt}\n\n{content}"
    print(full_message)
    
    # Send to LLM and get response
    response = chat_with_llm(full_message)

Configuration

Repository2Prompt uses a YAML configuration file. The default configuration is located in default_config.yaml within the package. You can override the default settings by creating a .repository2prompt.yaml file in your home directory.

Key configuration options include:

  • supported_output_formats: List of supported output formats
  • max_file_size: Maximum file size to process (in bytes)
  • supported_file_extensions: List of supported file extensions
  • ignore_dirs and ignore_files: Lists of directories and files to ignore

Examples

Converting a GitHub Repository

from repository2prompt import Repository2Prompt

converter = Repository2Prompt("https://github.com/octocat/octocat.github.io")
result = converter.process()
print(result)

Processing a Local Directory

from repository2prompt import Repository2Prompt

converter = Repository2Prompt("/path/to/local/repo", output_format="json")
result = converter.process()
print(result)

Using a Custom Template

from repository2prompt import Repository2Prompt

converter = Repository2Prompt("https://github.com/octocat/octocat.github.io", 
                              template_path="path/to/custom_template.j2",
                              output_format="text")
result = converter.process()
print(result)

Configuration

Repository2Prompt uses a YAML configuration file for its settings. There are several ways to customize the configuration:

Default Configuration

The default configuration is located in repository2prompt/default_config.yaml within the package.

User-level Configuration

You can create a .repository2prompt.yaml file in your home directory to override the default settings. This file will be automatically loaded if it exists.

Project-specific Configuration

For project-specific settings, you can create a custom YAML file and load it in your code. For example:

import yaml
from repository2prompt import Repository2Prompt, CONFIG

# Load custom configuration
with open('path/to/your/custom_config.yaml', 'r') as f:
    custom_config = yaml.safe_load(f)

# Update the default configuration
CONFIG.update(custom_config)

# Use the updated configuration
converter = Repository2Prompt("https://github.com/user/repo")
result = converter.process()

Environment Variable

You can also specify a custom configuration file using the REPOSITORY2PROMPT_CONFIG environment variable:

export REPOSITORY2PROMPT_CONFIG=/path/to/your/custom_config.yaml

Configuration Options

Key configuration options include:

  • github_api_token: Github api token
  • supported_output_formats: List of supported output formats
  • max_file_size: Maximum file size to process (in bytes)
  • supported_file_extensions: List of supported file extensions
  • ignore_dirs and ignore_files: Lists of directories and files to ignore
  • split_format_prompts: Prompts of output

Example of a custom configuration file:

github_api_token: "xxx_xxxxxxxxxx"
max_file_size: 2097152  # 2MB
ignore_dirs:
  - node_modules
  - .git
  - build
supported_file_extensions:
  - .py
  - .js
  - .md

Remember that any setting not specified in your custom configuration will use the default value from the package's default configuration.

Contributing

We welcome contributions of all forms! If you'd like to contribute to Repository2Prompt, please follow these steps:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Before submitting a Pull Request, please ensure your code passes all tests and adheres to our coding style guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Project Link: https://github.com/wctsai20002/repository2prompt

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repository2prompt-1.0.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repository2prompt-1.0.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file repository2prompt-1.0.0.tar.gz.

File metadata

  • Download URL: repository2prompt-1.0.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for repository2prompt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 073f2a5f8a9b268f4351809307af2aa4add9da8b8cbb6727ea760e60d4f9ebe6
MD5 66925aaa0ed60853165ec5a498aa9b59
BLAKE2b-256 93eb54bcefc0015a3f0ce69cfd700506fdea761f8567709e44755a49b7e48695

See more details on using hashes here.

File details

Details for the file repository2prompt-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for repository2prompt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3892b1a6510afa4b98cc9ae62fdc0d905522712f1b568290b6f4ea52de835c
MD5 466eedaecd053ec2da499fcd3aacdbf0
BLAKE2b-256 e876b7edb6a7a8ed26bcae124165324619f1f20404e3e3f0b9d69315fd7ec7e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page