-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
60 lines (47 loc) · 1.89 KB
/
main.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
54
55
56
57
58
59
60
import requests
import openai
github_token = 'YOUR_GITHUB_TOKEN'
github_api_url = 'GITHUB_API_URL'
openai.api_key = 'YOUR_OPENAI_SECRETKEY'
def make_sample_request():
url = f'{github_api_url}/user'
headers = {'Authorization': f'token {github_token}'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
user_data = response.json()
print(f"Authenticated as {user_data['login']}")
else:
print(f"Error: {response.status_code}, {response.text}")
def get_repository_info(owner, repo):
url = f'{github_api_url}/repos/{owner}/{repo}'
headers = {'Authorization': f'token {github_token}'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
repo_info = response.json()
print(f"Repository Name: {repo_info['name']}")
print(f"Description: {repo_info['description']}")
else:
print(f"Error: {response.status_code}, {response.text}")
def analyze_code_with_chatgpt(code_snippet):
prompt = f"Analyzing the following code:\n\n{code_snippet}\n\nSuggestions:"
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt},
]
)
suggestions = response['choices'][0]['message']['content'].strip()
with open("code_analysis_results.txt", "w") as file:
file.write(f"Suggestions for Code Improvement:\n{suggestions}")
print(f"Suggestions for Code Improvement:\n{suggestions}")
if __name__ == "__main__":
make_sample_request()
get_repository_info('VishnuH28', 'collegeManagement')
code_snippet = """
def calculate_square(n):
return n * n
result = calculate_square(5)
print(result)
"""
analyze_code_with_chatgpt(code_snippet)