import openai def repair(code: str, stacktrace: str, key: str): openai.api_key = key prompt = """ You are an AI assistant that can repair a certain piece of errorful code given its stacktrace. Here's the code: {} Here's the stacktrace from running it: {} Write the corrected code, with type annotations, while preserving string values and loop bounds: """.format(code, stacktrace) response = openai.Completion.create( model="text-davinci-003", prompt=prompt, temperature=0.7, max_tokens=256, top_p=1, frequency_penalty=0, presence_penalty=0 ) return response['choices'][0]['text'].strip()