-
Notifications
You must be signed in to change notification settings - Fork 0
/
chatgpt_automation.py
53 lines (45 loc) · 1.61 KB
/
chatgpt_automation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# .github/scripts/chatgpt_automation.py
import os
import openai
from github import Github
# Load environment variables
openai.api_key = os.getenv('OPENAI_API_KEY')
github_token = os.getenv('GITHUB_TOKEN')
# Initialize GitHub client
g = Github(github_token)
# Define repository
repo = g.get_repo('temichelle/studyplanner')
# Function to handle issue creation
def handle_issues():
open_issues = repo.get_issues(state='open')
for issue in open_issues:
if 'task' in issue.labels:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Analyze this issue: {issue.title} and provide next steps.",
max_tokens=100
)
comment_body = response['choices'][0]['text'].strip()
issue.create_comment(comment_body)
# Function to manage project cards
def manage_project_cards():
projects = repo.get_projects()
for project in projects:
columns = project.get_columns()
for column in columns:
cards = column.get_cards()
for card in cards:
if 'Backlog' in column.name:
response = openai.Completion.create(
engine="text-davinci-003",
prompt=f"Suggest improvements for this task: {card.note}",
max_tokens=100
)
card_note = response['choices'][0]['text'].strip()
card.create_comment(card_note)
# Main function to run automation
def main():
handle_issues()
manage_project_cards()
if __name__ == "__main__":
main()