[{"element_type":"markdown","content":"\u003ch3\u003eOverview\u003c/h3\u003e\n\n\u003cp\u003eGPT Code Interpreter allows you to run your own code on a GPT server. It's great for trying out simple functions. Did you know that you can upload your own interpreter and have GPT run it? It takes some work, but you can have GPT write code and tests, then run them on an actual CircuitPython interpreter. Not all the features are there, and you don't have access to any real hardware. This is highly experimental at this point. Difficulty level: \u003cstrong\u003eAdvanced\u003c/strong\u003e.\u003c/p\u003e\n\n\u003ch3\u003eEquipment\u003c/h3\u003e\n\n\u003cul\u003e\n\u003cli\u003eCircuitPython interpreter binary \u003ccode class=\"inline\"\u003eports/unix\u003c/code\u003e x86-64. Follow the instructions for \u003ca href=\"https://learn.adafruit.com/building-circuitpython\"\u003eBuilding CircuitPython\u003c/a\u003e. You need to build with the same GLIBC as Code Interpreter which is currently 2.31. I was able to build it using Debian 11 (bullseye).\u003c/li\u003e\n\u003cli\u003eThe interpreter is named 'micropython' but it is CircuitPython.\u003c/li\u003e\n\u003cli\u003eChatGPT+ account: Code Interpreter is a plus feature.\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch3\u003eInstructions\u003c/h3\u003e\n\n\u003cp\u003eFollow these instructions to start a chat with access to your CircuitPython interpreter. \u003ccode class=\"inline\"\u003ecommands\u003c/code\u003e should be entered directly into the chat.\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003eStart a new ChatGPT 4 session.\u003c/li\u003e\n\u003cli\u003eAttach your CircuitPython interpreter 'micropython'. Click the 'paperclip' to upload it.\u003c/li\u003e\n\u003cli\u003eUse this command: \u003ccode class=\"inline\"\u003ePlease make /mnt/data/micropython executable.\u003c/code\u003e\n\u003c/li\u003e\n\u003cli\u003eUse this code to check that the interpreter is working:\u003c/li\u003e\n\u003c/ul\u003e\n\u003ccode class=\"python\"\u003e\u003cpre\u003eimport sys\nprint(\"Version:\", sys.version)\nprint(\"Platform:\", sys.platform)\n\u003c/pre\u003e\u003c/code\u003e\n\u003cul\u003e\n\u003cli\u003eFlex some Python skills: \u003ccode class=\"inline\"\u003eUse introspection to list the features in the \u0026lt;os\u0026gt; module\u003c/code\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch3\u003eHow it Works\u003c/h3\u003e\n\n\u003cp\u003eThe code interpreter is like a Jupyter Notebook that GPT controls. When you ask it to run some code it writes the script and executes it as a notebook 'cell'. It adds an icon that allows you to view the script and the output.\u003c/p\u003e\n\n\u003cp\u003eFor the CircuitPython interpreter it will embed the CircuitPython code in the cell as a string, then use the shell to execute the CircuitPython interpreter with the embedded script and capture the output. It can then interpret the output or return it to you directly.\u003c/p\u003e\n\n\u003cp\u003eIt's pretty code-inceptiony and may take a while to figure out. Be sure to click on the icons to view the code and output for each 'cell'.\u003c/p\u003e\n\n\u003ch3\u003eObservations\u003c/h3\u003e\n\n\u003cp\u003eI'm still in awe that it even works. You will have to use some prompting to make sure it is running the interpreter and not just calculating the responses in some other way. It can use introspection to figure out which features are available and which are not present.\u003c/p\u003e\n\n\u003cp\u003eThis is still very experimental at this point!\u003c/p\u003e\n\n\u003ch3\u003eConclusions\u003c/h3\u003e\n\n\u003cp\u003eBuilding a CircuitPython interpreter that can run within GPT is an interesting and at times mind-bending exercise.\u003c/p\u003e\n\n\u003cp\u003eCode Interpreter could be a useful tool for testing different builds or even different versions of the CircuitPython core. \u003c/p\u003e\n\n\u003ch3\u003eFuture Work\u003c/h3\u003e\n\n\u003cul\u003e\n\u003cli\u003eFigure out how to add library packages to Code Interpreter.\u003c/li\u003e\n\u003cli\u003eImplement some hardware-in-software modules (fake temperature and humidity sensor, fake I2C and SPI peripherals, fake \u003ccode class=\"inline\"\u003eboard\u003c/code\u003e with a few pins etc.)\u003c/li\u003e\n\u003cli\u003eMake the interaction traceable so we know if the interpreter is used or not.\u003c/li\u003e\n\u003cli\u003eWrap it in a GPT application.\u003c/li\u003e\n\u003cli\u003eFigure out how to call it via the GPT API.\u003c/li\u003e\n\u003c/ul\u003e\n","metadata":{"markdown":"### Overview\n\nGPT Code Interpreter allows you to run your own code on a GPT server. It's great for trying out simple functions. Did you know that you can upload your own interpreter and have GPT run it? It takes some work, but you can have GPT write code and tests, then run them on an actual CircuitPython interpreter. Not all the features are there, and you don't have access to any real hardware. This is highly experimental at this point. Difficulty level: **Advanced**.\n\n### Equipment\n\n- CircuitPython interpreter binary `ports/unix` x86-64. Follow the instructions for [Building CircuitPython](https://learn.adafruit.com/building-circuitpython). You need to build with the same GLIBC as Code Interpreter which is currently 2.31. I was able to build it using Debian 11 (bullseye).\n- The interpreter is named 'micropython' but it is CircuitPython.\n- ChatGPT+ account: Code Interpreter is a plus feature.\n\n### Instructions\n\nFollow these instructions to start a chat with access to your CircuitPython interpreter. `commands` should be entered directly into the chat.\n\n- Start a new ChatGPT 4 session.\n- Attach your CircuitPython interpreter 'micropython'. Click the 'paperclip' to upload it.\n- Use this command: `Please make /mnt/data/micropython executable.`\n- Use this code to check that the interpreter is working:\n\n```python\nimport sys\nprint(\"Version:\", sys.version)\nprint(\"Platform:\", sys.platform)\n```\n\n- Flex some Python skills: `Use introspection to list the features in the \u0026lt;os\u0026gt; module`\n\n### How it Works\n\nThe code interpreter is like a Jupyter Notebook that GPT controls. When you ask it to run some code it writes the script and executes it as a notebook 'cell'. It adds an icon that allows you to view the script and the output.\n\nFor the CircuitPython interpreter it will embed the CircuitPython code in the cell as a string, then use the shell to execute the CircuitPython interpreter with the embedded script and capture the output. It can then interpret the output or return it to you directly.\n\nIt's pretty code-inceptiony and may take a while to figure out. Be sure to click on the icons to view the code and output for each 'cell'.\n\n### Observations\n\nI'm still in awe that it even works. You will have to use some prompting to make sure it is running the interpreter and not just calculating the responses in some other way. It can use introspection to figure out which features are available and which are not present.\n\nThis is still very experimental at this point!\n\n### Conclusions\n\nBuilding a CircuitPython interpreter that can run within GPT is an interesting and at times mind-bending exercise.\n\nCode Interpreter could be a useful tool for testing different builds or even different versions of the CircuitPython core. \n\n### Future Work\n\n- Figure out how to add library packages to Code Interpreter.\n- Implement some hardware-in-software modules (fake temperature and humidity sensor, fake I2C and SPI peripherals, fake `board` with a few pins etc.)\n- Make the interaction traceable so we know if the interpreter is used or not.\n- Wrap it in a GPT application.\n- Figure out how to call it via the GPT API.\n"}},{"element_type":"text","content":"\n  \n  \n        \u003cp\u003eHug Reports\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eDan Halbert for writing the guide to building CircuitPython\u003c/li\u003e\n\u003cli\u003eSimon Willison for his experiments with GPT Code Interpreter:\n\u003cul\u003e\n\u003cli\u003e\u003ca\u003eExpanding ChatGPT Code Interpreter with Python packages, Deno and Lua\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://simonwillison.net/2023/Nov/15/gpts/\"\u003eExploring GPTs: ChatGPT in a trench coat?\u003c/a\u003e\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ul\u003e\n      \n\n","metadata":{}}]