From 2c76917cc7d2488e9c6886f32a5729bdbf1b2069 Mon Sep 17 00:00:00 2001 From: viskey98 Date: Tue, 14 May 2024 09:54:01 +0530 Subject: [PATCH] Updated the project by updating the utilities. THe llm used here is gpt-3.5-turbo-0125 --- utility.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/utility.py b/utility.py index 0a6e1449..cf1db471 100644 --- a/utility.py +++ b/utility.py @@ -31,7 +31,44 @@ def format_data_for_openai(diffs, readme_content, commit_messages): return prompt def call_openai(prompt): - pass + client = ChatOpenAI(api_key=os.environ['OPENAI_API_KEY'], model="gpt-3.5-turbo-0125") + + try: + messages = [ + { + "role": "system", + "content": "You are an AI trained to help with updating README files based on code changes and commit messages." + }, + { + "role": "user", + "content": prompt + } + ] + response = client.invoke(input=messages) + # We use the StrOutputParser to parse the response as this class can adapt to providers like OpenAI, Llama and others. + parser = StrOutputParser() + content = parser.parse(input=response) + return content + except Exception as e: + print(f"Error calling OpenAI: {e}") def update_readme_and_create_pr(repo, updated_readme, readme_sha): - pass \ No newline at end of file + commit_messages = "AI COMMIT: Proposed README update based on code changes" + commit_sha = os.getenv('COMMIT_SHA') + main_brainch = repo.get_branch("main") + new_branch_name = f'update-readme-{commit_sha[:7]}' + new_branch = repo.create_git_ref(ref=f"refs/heads/{new_branch_name}", sha=main_brainch.commit.sha) + + repo.update_file( + path="README.md", + message=commit_messages, + content=updated_readme, + sha=readme_sha, + branch=new_branch_name + ) + + pr_title = "AI PR: Update README based on recent changes" + pr_body = "This is an AI PR. Please review the README." + pull_request = repo.create_pull(title=pr_title, body=pr_body, head=new_branch_name, base="main") + + return pull_request \ No newline at end of file