-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8db624
commit d8c6bfa
Showing
2 changed files
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
import argparse | ||
import os | ||
from .repository2prompt import Repository2Prompt | ||
from .config import CONFIG | ||
|
||
def get_file_extension(format): | ||
extension_map = { | ||
'markdown': 'md', | ||
'json': 'json', | ||
'text': 'txt', | ||
'split': 'json' | ||
} | ||
return extension_map.get(format, format) | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description="Convert GitHub repositories or local directories into LLM prompts.") | ||
parser.add_argument("input_path", help="GitHub repository URL or path to local directory") | ||
parser.add_argument("-t", "--template", help="Path to custom Jinja2 template file") | ||
parser.add_argument("-f", "--format", choices=CONFIG['supported_output_formats'], | ||
default=CONFIG['default_output_format'], | ||
help=f"Output format (default: {CONFIG['default_output_format']})") | ||
parser.add_argument("-o", "--output", help="Output file path (default: repository_name.{extension})") | ||
args = parser.parse_args() | ||
|
||
converter = Repository2Prompt(args.input_path, args.template, args.format) | ||
result = converter.process() | ||
|
||
if result: | ||
print(result) | ||
|
||
# Determine output file name | ||
if args.output: | ||
output_file = args.output | ||
else: | ||
print("Failed to generate prompt due to errors.") | ||
repo_name = os.path.basename(args.input_path.rstrip('/')) | ||
extension = get_file_extension(args.format) | ||
output_file = f"{repo_name}_prompt.{extension}" | ||
|
||
# Write result to file | ||
with open(output_file, 'w', encoding='utf-8') as f: | ||
f.write(result) | ||
|
||
print(f"Output written to: {output_file}") | ||
|
||
if __name__ == "__main__": | ||
main() |