-
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.
Merge pull request #2 from shankarpandala/feature/dev
Add new files and dependencies
- Loading branch information
Showing
19 changed files
with
153 additions
and
140 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
def create_folder_structure_md(path, indent=0): | ||
markdown = "" | ||
path = Path(path) | ||
if path.is_file() and not path.name.startswith('.') and path.name != 'folderstructure.py': | ||
markdown += " " * indent + "- " + path.name + "\n" | ||
elif path.is_dir() and not path.name.startswith('.') and path.name != 'folderstructure.py': | ||
markdown += " " * indent + "- " + path.name + "/\n" | ||
for child in path.iterdir(): | ||
markdown += create_folder_structure_md(child, indent + 1) | ||
return markdown | ||
|
||
# Replace 'your_directory_path' with the path of the directory you want to convert to markdown | ||
print(create_folder_structure_md(os.getcwd())) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .cli_agent import generate_response |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
from langchain.prompts import ChatPromptTemplate | ||
from langchain.output_parsers import ResponseSchema, StructuredOutputParser | ||
import re | ||
|
||
from lazygitgpt.llms import chat_model | ||
from lazygitgpt.datasources.repos import read_repository_contents | ||
from lazygitgpt.git.operations import update_files | ||
|
||
output_schema = ResponseSchema(name='filename', description='contents', type='string') | ||
output_parser = StructuredOutputParser(response_schemas=[output_schema]) | ||
format_instructions = output_parser.get_format_instructions() | ||
template_string = """You are an expert programmer. | ||
You are reviewing a code repository. | ||
Read the code and make changes to the code as per the user requirements. | ||
user requirements: {user_requirements} | ||
code repository: {code_repository} | ||
Output the contents of the file that you changed as per the format instructions : {format_instructions} | ||
""" | ||
|
||
def generate_response(prompt, sources=read_repository_contents()): | ||
sources_str = json.dumps(sources, indent=4) | ||
prompt_template = ChatPromptTemplate.from_template(template_string) | ||
messages = prompt_template.format_messages(user_requirements = prompt, | ||
code_repository = sources_str, | ||
format_instructions=format_instructions) | ||
response = chat_model(messages) | ||
response_json = response.to_json() | ||
data = response_json['kwargs']['content'] | ||
return data |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .repos import read_repository_contents |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import glob | ||
import json | ||
|
||
def read_repository_contents(directory_path=os.getcwd(), file_pattern="*"): | ||
""" | ||
Reads all files in the specified directory matching the file pattern, | ||
and creates a JSON object with file names and their contents. | ||
Args: | ||
directory_path (str): Path to the directory containing the files. | ||
file_pattern (str): Pattern to match files. Defaults to '*' (all files). | ||
Returns: | ||
str: A JSON string containing the file names and their contents. | ||
""" | ||
data = {} | ||
for file_path in glob.glob(f"{directory_path}/{file_pattern}"): | ||
if os.path.isfile(file_path): | ||
try: | ||
with open(file_path, 'r', encoding='utf-8') as file: | ||
data[file_path] = file.read() | ||
except Exception as e: | ||
print(f"Error reading file: {file_path} - {e}") | ||
|
||
return json.dumps(data, indent=4) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .operations import update_files, clone_repository, checkout_branch, create_branch |
113 changes: 63 additions & 50 deletions
113
lazygitgpt/git_operations.py → lazygitgpt/git/operations.py
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,51 +1,64 @@ | ||
import os | ||
from git import Repo, GitCommandError | ||
|
||
def clone_repository(repo_url): | ||
""" | ||
Clones a git repository from the given URL to the current working directory. | ||
:param repo_url: URL of the repository to clone. | ||
""" | ||
try: | ||
# Get the name of the repository by parsing the URL | ||
repo_name = os.path.basename(repo_url) | ||
# If the URL ends with '.git', remove it | ||
if repo_name.endswith('.git'): | ||
repo_name = repo_name[:-4] | ||
# Use the current working directory as the destination | ||
destination = os.path.join(os.getcwd(), repo_name) | ||
Repo.clone_from(repo_url, destination) | ||
print(f"Repository cloned successfully to {destination}") | ||
except GitCommandError as e: | ||
print(f"Error cloning repository: {e}") | ||
|
||
def checkout_branch(branch_name): | ||
""" | ||
Checks out a specified branch in the current working directory. | ||
:param branch_name: Name of the branch to checkout. | ||
""" | ||
try: | ||
# Use the current working directory as the repository path | ||
repo_path = os.getcwd() | ||
repo = Repo(repo_path) | ||
repo.git.checkout(branch_name) | ||
print(f"Checked out to branch {branch_name}") | ||
except GitCommandError as e: | ||
print(f"Error checking out branch: {e}") | ||
|
||
def create_branch(branch_name): | ||
""" | ||
Creates a new branch in the current working directory. | ||
:param branch_name: Name of the branch to create. | ||
""" | ||
try: | ||
# Use the current working directory as the repository path | ||
repo_path = os.getcwd() | ||
repo = Repo(repo_path) | ||
repo.git.checkout('-b', branch_name) | ||
print(f"Created and checked out to new branch {branch_name}") | ||
except GitCommandError as e: | ||
import os | ||
from git import Repo, GitCommandError | ||
|
||
def update_files(response): | ||
try: | ||
for filename, contents in response.items(): | ||
file_path = os.path.join(os.getcwd(), filename) | ||
|
||
with open(file_path, 'w', encoding='utf-8') as file: | ||
file.write(contents) | ||
|
||
print(f"Updated file: {filename}") | ||
|
||
except Exception as e: | ||
print(f"Error updating files: {e}") | ||
|
||
def clone_repository(repo_url): | ||
""" | ||
Clones a git repository from the given URL to the current working directory. | ||
:param repo_url: URL of the repository to clone. | ||
""" | ||
try: | ||
# Get the name of the repository by parsing the URL | ||
repo_name = os.path.basename(repo_url) | ||
# If the URL ends with '.git', remove it | ||
if repo_name.endswith('.git'): | ||
repo_name = repo_name[:-4] | ||
# Use the current working directory as the destination | ||
destination = os.path.join(os.getcwd(), repo_name) | ||
Repo.clone_from(repo_url, destination) | ||
print(f"Repository cloned successfully to {destination}") | ||
except GitCommandError as e: | ||
print(f"Error cloning repository: {e}") | ||
|
||
def checkout_branch(branch_name): | ||
""" | ||
Checks out a specified branch in the current working directory. | ||
:param branch_name: Name of the branch to checkout. | ||
""" | ||
try: | ||
# Use the current working directory as the repository path | ||
repo_path = os.getcwd() | ||
repo = Repo(repo_path) | ||
repo.git.checkout(branch_name) | ||
print(f"Checked out to branch {branch_name}") | ||
except GitCommandError as e: | ||
print(f"Error checking out branch: {e}") | ||
|
||
def create_branch(branch_name): | ||
""" | ||
Creates a new branch in the current working directory. | ||
:param branch_name: Name of the branch to create. | ||
""" | ||
try: | ||
# Use the current working directory as the repository path | ||
repo_path = os.getcwd() | ||
repo = Repo(repo_path) | ||
repo.git.checkout('-b', branch_name) | ||
print(f"Created and checked out to new branch {branch_name}") | ||
except GitCommandError as e: | ||
print(f"Error creating new branch: {e}") |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
from .openai import chat_model |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from langchain.chat_models import ChatOpenAI | ||
|
||
chat_model = ChatOpenAI(model="gpt-4-1106-preview", temperature=0.0) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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,4 +1,8 @@ | ||
gitpython>=3.1.0 | ||
openai>=0.10.0 | ||
click | ||
langchain | ||
langchain | ||
duckduckgo-search | ||
llmx | ||
cohere | ||
tiktoken |