Skip to content

Commit

Permalink
Merge pull request #1 from viswak-cn/update
Browse files Browse the repository at this point in the history
Updated the project by updating the utilities. THe llm used here is gpt-3.5-turbo-0125
  • Loading branch information
viswak-cn authored May 14, 2024
2 parents 47e3d20 + 2c76917 commit 0a6215e
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit 0a6215e

Please sign in to comment.