-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexerc.py
More file actions
31 lines (26 loc) · 880 Bytes
/
exerc.py
File metadata and controls
31 lines (26 loc) · 880 Bytes
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
import os
import openai
import secret
# CODIO SOLUTION BEGIN
openai.api_key=secret.api_key
def chatgpt_code_review(file_path):
# Check if file exists
if not os.path.isfile(file_path):
return "File not found."
# Open the file and read the code
with open(file_path, 'r') as file:
code = file.read()
# Send the code for review
try:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a code review assistant that provides feedback and suggests improvements for Python code."},
{"role": "user", "content": code},
],
)
# Return the assistant's reply
return response['choices'][0]['message']['content']
except Exception as e:
return str(e)
# CODIO SOLUTION END