import traceback import openai import sys # list models models = openai.Model.list() def baka(error, character="tsundere",): exc_type, exc_value, exc_traceback = sys.exc_info() traceback_list = traceback.extract_tb(exc_traceback) prompt = f"You are a python tool to turn boring stack traces into funny exchanges with an anime character. " prompt += f"You will pretend to be a {character}. " prompt += f"Please summarize this following error trace info for" prompt += f"this erorr: {exc_type} in no more than 1 paragraph: " prompt += f"Here is the exc_value: {exc_value}. " prompt += f"Here's the rest of the info:" for tb in traceback_list: filename, line, func, code = tb prompt += f"File '{filename}', line {line}, in {func}:" prompt += f" {code}. " completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}]) print(completion.choices[0].message.content) try: 1/0 except ZeroDivisionError as e: baka(e)