Skip to content


June 06 2023

City on fire (hot!)


Over 200 AQI in NYC (yikes)


I've been using my shortcuts to keep track of a food journal, always cool to overload an automation cornerstone (capture workflow) into a brand new highly useful adaptation

I've been writing a lot, my draft folder is bulging with 3+ essays waiting to be published, wow!


Use GPT-4 to automatically diagnose errors whenever they are thrown, this is already proving hella useful (so much so I might convert it into a library so it can be used across projects), check it out here.

(full code below (...mostly))

import openai
import os
import dotenv
import json
import sys
import inspect

# read these for more info:


openai.api_key = os.getenv("OPENAI_API_KEY")

async def run_chat_prompt(prompt, model="gpt-4"):
    completion = openai.ChatCompletion.create(
            {"role": "user", "content": prompt}

    return (completion.choices[0].message.content)

def wrap_error(e: Exception, description: str = None):
    exc_type, exc_value, exc_traceback = sys.exc_info()
    filename = exc_traceback.tb_frame.f_code.co_filename
    line_number = exc_traceback.tb_lineno
    func_name = exc_traceback.tb_frame.f_code.co_name
    module = inspect.getmodule(exc_traceback.tb_frame)
    function_obj = getattr(module, func_name)

    # Get and print the source code of the function
    func_code = inspect.getsource(function_obj)

    error_message = f"This error message occurred because of '{str(e)}' at line {line_number} in file {filename}, function {func_name}. The exception type is {exc_type}. The function is: \n\n```python\n{func_code}\n```\n\n How do I fix this?"
    if description:
        error_message += f'Other details: {description}'

    return error_message

import error_wrap

async def main():
       raise Exception("test")
    except Exception as e:
        potential_fix = await error_wrap.run_chat_prompt(error_wrap.wrap_error(e))
        # an optional description can be added with something along the lines of: error_wrap.wrap_error(e, "here's some specific info passed in by me, a human")
        return {"error": str(e), "potential_fix": potential_fix}


I was on a podcast about GPT-4 and Go! Check it out here.

Freeform is a reader-supported published Zettelkasten. Both free and paid subscriptions are available. If you want to support my work, the best way is by taking out a paid subscription.