Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
viswak-cn committed May 9, 2024
1 parent 4192ceb commit 47e3d20
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .github/workflows/update_readme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,23 @@ jobs:
pip install -r requirements.txt
# Extract PR Number and Commit SHA from the GitHub event context
- name: Get PR info
id: pr_info
run: |
pr_num=$(jq -r .pull_request.number "$GITHUB_EVENT_PATH")
commit_sha=$(jq -r .pull_request.head.sha "$GITHUB_EVENT_PATH")
echo "pull_request_number=$pr_num" >> $GITHUB_ENV
echo "commit_sha=$commit_sha" >> $GITHUB_ENV
# Run the Python script
- name: Generate Updated README
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
REPO_PATH: ${{ github.repository }}
PR_NUMBER: ${{ env.pull_request_number }}
COMMIT_SHA: ${{ env.commit_sha }}
run: python main.py

# Additional step to enable debugging, helps in troublshooting
- name: Enable Debug Logging
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Virtual Environment
venv/
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ typing_extensions==4.11.0
urllib3==2.2.1
wheel==0.41.2
wrapt==1.16.0
langchain_openai
17 changes: 16 additions & 1 deletion utility.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import os
import base64
from openai import OpenAI
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers.string import StrOutputParser

def format_data_for_openai(diffs, readme_content, commit_messages):
prompt = None

# Combine the changes into a string with clear delineation.
changes = '\n'.join([f"File: {diff['filename']}\nDiff: \n{diff['patch']}" for diff in diffs])

# Combine all commit messages
commit_messages = '\n'.join(commit_messages) + '\n\n'

# Decode the README content
readme_content = base64.b64decode(readme_content.content).decode('utf-8')

# Construct the prompt with clear instructions for the LLM.
prompt = (
"Please review the following code changes and commit messages from a GitHub pull request:\n"
"Code changes from Pull Request:\n"
f"{changes}\n"
"Commit messages:\n"
f"{commit_messages}"
"Here is the current README file content:\n"
f"{readme_content}\n"
"Consider the code changes and commit messages, determine if the README needs to be updated. If so, edit the README, ensuring to maintain its existing style and clarity.\n"
"Updated README:\n"
)

return prompt

Expand Down

0 comments on commit 47e3d20

Please sign in to comment.