Skip to content

Commit

Permalink
Merge pull request #5 from alokemajumder/alokemajumder-patch-1
Browse files Browse the repository at this point in the history
Update generate_pr_content.py
  • Loading branch information
alokemajumder authored Apr 22, 2024
2 parents b82721d + 63da36e commit 6edc2b3
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions .github/scripts/generate_pr_content.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import json
import requests
import subprocess

def call_api(url, headers, payload):
response = requests.post(url, headers=headers, json=payload)
Expand All @@ -14,31 +15,33 @@ def generate_summary(api_key, engine_url, prompt):
"Content-Type": "application/json"
}
payload = {
"model": "code-davinci-002",
"prompt": prompt,
"max_tokens": 150
}
return call_api(engine_url, headers, payload)

def get_git_diff():
try:
diff = subprocess.check_output(['git', 'diff', 'HEAD^', 'HEAD'], text=True)
except subprocess.CalledProcessError:
diff = "No previous commit to compare."
return diff

def main():
# Get code difference from the last commit
diff = os.popen('git diff HEAD^ HEAD').read()
diff = get_git_diff()
prompt = f"Summarize the following code changes in a detailed and formatted manner:\n{diff}"

# Generate summaries using both APIs
openai_summary = generate_summary(
os.getenv('OPENAI_API_KEY'),
"https://api.openai.com/v1/engines/davinci-codex/completions",
"https://api.openai.com/v1/completions",
prompt
)["choices"][0]["text"]

anthropic_summary = generate_summary(
os.getenv('ANTHROPIC_API_KEY'),
"https://api.anthropic.com/claude-3/text-completions",
prompt
)["completions"][0]["text"]
# Assuming anthropic_summary setup remains the same
# Include similar error handling and model updating for Anthropic API as needed

# Combine the results
formatted_content = f"## OpenAI Summary\n{openai_summary}\n\n## Anthropic Summary\n{anthropic_summary}"
formatted_content = f"## OpenAI Summary\n{openai_summary}\n\n## Further details to be added as required."
print(f"::set-output name=pr_content::{json.dumps(formatted_content)}")

if __name__ == "__main__":
Expand Down

0 comments on commit 6edc2b3

Please sign in to comment.