File size: 1,098 Bytes
ab7440d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai

# Set up the OpenAI API credentials
openai.api_key = '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'

# Define a function that takes a user's input code as a prompt and uses the OpenAI API to generate a corrected version of the code
def correct_code(prompt):
    # Set up the OpenAI API parameters
    model_engine = "text-davinci-002"
    temperature = 0.7
    max_tokens = 100

    # Generate the corrected code using the OpenAI API
    response = openai.Completion.create(
        engine=model_engine,
        prompt=prompt,
        temperature=temperature,
        max_tokens=max_tokens
    )

    # Extract the corrected code from the API response
    corrected_code = response.choices[0].text.strip()

    return corrected_code

def main():
    while True:
        # Prompt the user for input code
        prompt = input("Enter code to correct: ")

        # Generate a corrected version of the code using the OpenAI API
        corrected_code = correct_code(prompt)

        # Print the corrected code
        print(corrected_code)

if __name__ == '__main__':
    main()