From 47e3d207ca6f2a5cd5c16b59b6afd431fb125897 Mon Sep 17 00:00:00 2001 From: viskey98 Date: Thu, 9 May 2024 22:45:06 +0530 Subject: [PATCH] wip --- .github/workflows/update_readme.yaml | 15 +++++++++++++++ .gitignore | 2 ++ requirements.txt | 1 + utility.py | 17 ++++++++++++++++- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .gitignore diff --git a/.github/workflows/update_readme.yaml b/.github/workflows/update_readme.yaml index 916bf590..81b84a66 100644 --- a/.github/workflows/update_readme.yaml +++ b/.github/workflows/update_readme.yaml @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..64d14230 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Virtual Environment +venv/ \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8905d1c8..9d99ed78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,3 +25,4 @@ typing_extensions==4.11.0 urllib3==2.2.1 wheel==0.41.2 wrapt==1.16.0 +langchain_openai \ No newline at end of file diff --git a/utility.py b/utility.py index dab38cdc..0a6e1449 100644 --- a/utility.py +++ b/utility.py @@ -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