Skip to content
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

Update generate_pr_content.py #5

Merged
merged 1 commit into from
Apr 22, 2024
Merged
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
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
Loading