CodeX / app.py
typesdigital's picture
Update app.py
28b6db7
raw
history blame
1.11 kB
import openai
import secrets
print(secrets.OPENAI_API_KEY)
# Set up the OpenAI API credentials
openai.api_key = secrets.OPENAI_API_KEY
# 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()