A sample of using an OpenAI Assistant to use the code interpreter to solve a maths problem. This is based on this Learn documentation, but is a really simple maths problem.
This repo used the Visual Studio Code REST client extension so that you can see the exact HTTP requests that go over the wire.
This is a really simple maths problem of getting the square root of a number. Traditionally LLMs are not good at these problems. Assistants solve this by using some compute in a sandboxed environment. This avoids issues of where an LLM could generate code that may be unsafe to run in a more conventional environment.
There are limits on the region's in which the assistants API is currently deployed. The example has been tested on Sweden Central.
The HTTP requests will need your Azure OpenAI resource name, key and the name of a model deployment. I suggest you use gpt-4o for this as this is the model that this has been tested against.
It is best to clone this repo and run inside Visual Studio code with the REST client.
Alteratively, if you can access GitHub CodeSpaces, that should work just as well.
The steps in this demo are marked in the requests.http file, but are described below in a little more detail.
- STEP 1 - this creates the assistant, gives it the instructions (AKA system prompt) and tells it to use the code interpreter. This returns an assistant_id which can be used later.
- STEP 2 - this creates a thread, which is used to manage an overall conversation thread with the assistant.
- STEP 3 - this creates a message which is where we send the ask to the assistant. in this case "what is the square root of 16"
- STEP 4 - this runs the thread. So now the assistant is attempting to ansswe the query.
- STEP 5 - lists the messages in the thread where we should see the LLM response in one of the messages. The response value is extracted to a variable response so you can see the text of the result of the query.
- STEP 6 - deletes the thread
- STEP 7 - deletes the assistant