> ## Content Index
> Fetch the complete content index at: https://www.bramadams.dev/llms.txt
> Use this file to discover other available public pages before exploring further.

# June 06 2023
- URL: https://www.bramadams.dev/202306062304/
- Published: 2023-06-07T04:28:42.000Z
- Updated: 2023-06-13T02:39:37.000Z
- Description: City on fire (hot!)
- Author: Bram Adams
- Tags: instabram, family-guy, python, ai, audio-enabled

## Videos

Over 200 AQI in NYC (yikes)

## Thoughts

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!

## Code

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](https://gist.github.com/bramses/3bc23c6c601e7ad5b250c9f5054870d5?ref=bramadams.dev).

(full code below (...mostly))

### error\_wrap.py

```python
import openai
import os
import dotenv
import json
import sys
import inspect

# read these for more info:
# https://chat.openai.com/share/9341df1e-65c0-4fd8-87dc-80e0dc9fa5bc
# https://chat.openai.com/share/193482c6-e7b3-4022-b42b-cd2530efb839

dotenv.load_dotenv()

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

async def run_chat_prompt(prompt, model="gpt-4"):
    completion = openai.ChatCompletion.create(
        model=model,
        messages=[
            {"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
```

### main.py

```python
import error_wrap

async def main():
    try:
       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}
```

## Audio

I was on a podcast about GPT-4 and Go! Check it out [here](https://gotime.fm/279?ref=bramadams.dev).

## Freeform

[ Readwise quotes to code readwise quotes to code.pdf 948 KB download-circle ](https://www.bramadams.dev/content/files/2023/06/readwise-quotes-to-code.pdf "Download") 

**bramadams.dev is a reader-supported [published Zettelkasten](https://www.bramadams.dev/about/). [Both free and paid subscriptions are available](#/portal). If you want to support my work, the best way is by taking out a paid subscription.**