Skip to content

Commit

Permalink
get files in current dir
Browse files Browse the repository at this point in the history
  • Loading branch information
erexer committed Jan 20, 2025
1 parent c399183 commit 79c18b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ jobs:
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
REPO_URL: ${{ github.repository }}
run: python format_file.py
22 changes: 19 additions & 3 deletions format_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@
from langchain_core.prompts import ChatPromptTemplate


file_contents = {}

def get_file_contents(path='.'):
for filename in sorted((f for f in os.listdir(path) if not f.startswith(".")), key=str.lower):
full_path = os.path.join(path, filename)
if os.path.isdir(full_path):
get_file_contents(full_path)
else:
_, file_extension = os.path.splitext(filename)
print(file_extension)
if (".ipynb" or ".py") in file_extension:
with open(full_path) as f:
file_contents.update({filename: f.read()})


get_file_contents()
print(f"Found the following files: {file_contents.keys()}")

try:
# This code will raise a NameError because 'my_variable' is not defined
os.environ["AZURE_OPENAI_API_KEY"]
except Error as e:
# This block will execute if an Error occurs
print(f"No AZURE_OPENAI_API_KEY environment variable was found: {e}")

llm = AzureChatOpenAI(
Expand All @@ -34,7 +50,7 @@
ai_msg = chain.invoke(
{
"language": "Python",
"input": f"Go through all the scripts in the repository at {os.environ["REPO_URL"]} and provide detailed feedback and suggestions on how to make the scripts easier to read, cleaner, and more reproducible.",
"input": f"Go through all the scripts in the following dictionary of scripts and provide detailed feedback and suggestions on how to make the scripts easier to read, cleaner, and more reproducible: {file_contents}",
}
)

Expand Down

0 comments on commit 79c18b6

Please sign in to comment.