Skip to content

adding hello world script #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions .github/workflows/autofeedback.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PR Comment with GPT-4
name: Senior Engineer GPT

on:
pull_request:
Expand All @@ -18,18 +18,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install openai
pip install PyGithub

- name: Get PR changes
id: pr_changes
run: |
CHANGED_FILES=$(jq -r '.pull_request.head.sha' "$GITHUB_EVENT_PATH")
echo "::set-output name=changed_files::$CHANGED_FILES"
pip install -r requirements.txt

- name: Run Python script
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
python src/generate_comment.py ${{ github.event.pull_request.number }} ${{ steps.pr_changes.outputs.changed_files }}
python src/generate_comment.py ${{ github.event.pull_request.number }} ${{ github.event.pull_request.head.sha }}
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
openai
PyGithub
50 changes: 28 additions & 22 deletions src/generate_comment.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import os
import sys
import requests
import boto3
from util import get_logger, get_api_key, get_git_creds, get_changed_files
import logging
from openai import OpenAI
from github import Github

logger = get_logger()
logger = logging.getLogger()
formatter = logging.Formatter("%(message)s")
stream_handler = logging.StreamHandler(sys.stdout)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
logger.setLevel(logging.INFO)

client = OpenAI(api_key=get_api_key())
git_token, repo, pr_number = get_git_creds()
GIT_TOKEN = os.environ.get('GIT_TOKEN')
GIT_REPO = os.environ.get('GITHUB_REPOSITORY')
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY")
if OPENAI_API_KEY is None:
raise ValueError("You need to specify OPENAI_API_KEY environment variable!")

client = OpenAI(api_key=OPENAI_API_KEY)

def get_pr_files(pr_number):
g = Github(os.getenv('GITHUB_TOKEN'))
g = Github(os.getenv('GIT_TOKEN'))
repo = g.get_repo(os.getenv('GITHUB_REPOSITORY'))
pr = repo.get_pull(pr_number)
files = pr.get_files()
changes = [f.filename for f in files]
return changes


def download_from_s3(s3_bucket: str, s3_path: str, local_path: str):
s3 = boto3.client('s3')
try:
s3.download_file(s3_bucket, s3_path, local_path)
except Exception as e:
raise Exception(f"Failed to download from S3: {e}")


def get_feedback(filename: str, system_prompt: str, user_prompt: str) -> str:
comment = ''
response = client.chat.completions.create(
Expand Down Expand Up @@ -69,16 +69,22 @@ def main(files_to_process: list):
You are a senior software engineer looking to give feedback on every PR you see in this repo

"""

for filename in files_to_process:
file_path = os.path.join('src', filename)
if file_path in files_to_process:
prompt = f"Make sure this file {file_path} follows all the right naming and python conventions. Make any call outs you see!"
comment = get_feedback(filename, system_prompt, prompt)
if git_token and repo and pr_number:
post_github_comment(git_token, repo, pr_number, comment, filename)
logger.info("processing:" +filename)
try:
with open(filename, 'r') as file:
content = file.read()
print(content)
prompt = f"Make sure this file {filename} with this content: {content} follows all the right naming and python conventions. Make any call outs you see!"
comment = get_feedback(filename, system_prompt, prompt)
if GIT_TOKEN and GIT_REPO and pr_number:
post_github_comment(GIT_TOKEN, GIT_REPO, pr_number, comment, filename)
except Exception as e:
print(e)


if __name__ == "__main__":
pr_number = int(sys.argv[1])
changes = get_pr_files(pr_number)
files_to_process = get_changed_files()
main(files_to_process)
main(changes)
4 changes: 4 additions & 0 deletions src/python_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

hello = 'world'

print(hello)
85 changes: 0 additions & 85 deletions src/util.py

This file was deleted.

Loading