You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Porting over the SDK sample that uses code interpreter tool to create an image, download the image and display it using streaming and additional instructions.
@@ -144,125 +144,203 @@ for image_content in messages.image_contents:
144
144
145
145
:::zone pivot="csharp"
146
146
147
-
## Create a project client
147
+
#How to use the code interpreter tool
148
148
149
-
To use code interpreter, first you need to create a project client, which will contain a connection string to your AI project, and will be used to authenticate API calls.
149
+
In this example we will demonstrate the Agent streaming support, code interpreter creating an image and downloading and viewing the image.
1. First, we set up configuration using `appsettings.json`, create a `PersistentAgentsClient`, and then create a `PersistentAgent` with the Code Interpreter tool.
Files can be uploaded and then referenced by agents or messages. First, use the generalized upload API with a `purpose` of `Agents` to make a file ID available. Once uploaded, the file ID can then be provided to create a vector store for it. The vector store ID can then be provided to an agent upon creation.
// Create a vector store with the file and wait for it to be processed.
169
-
// If you do not specify a vector store, create_message will create a vector store with a default expiration policy of seven days after they were last active
instructions: "You politely help with math questions. Use the code interpreter tool when asked to visualize numbers.",
189
+
tools: [newCodeInterpreterToolDefinition()]
190
+
);
188
191
```
189
192
190
-
## Create a Thread, Message, and Get the Agent Response
193
+
2. Next, we create a `PersistentAgentThread`and add a user message to it.
191
194
192
-
Next create a thread with `CreateThreadAsync()` and a thread with `CreateMessageAsync()`. After the thread is created, you can add messages to it with `CreateMessageAsync()` that will cause the code interpreter tool to trigger. Create a run, and then continue polling it until it reaches a terminal status. Assuming the run was successful, parse the agent's response by listing the messages.
"Hi, Agent! Draw a graph for a line with a slope of 4 and y-intercept of 9.");
215
+
```
216
+
217
+
3. Then, we create a `ThreadRun` for the thread and agent, providing any additional instructions. We poll the run's status until it is no longer queued, in progress, or requires action.
4. Once the run is finished, we retrieve all messages from the thread. We then iterate through the messages to display text content and handle any image files by saving them locally and opening them.
221
256
222
-
//Assuming the run successfully completed, listing messages from the thread that was run will now reflect new information added by the agent:
Files generated by code interpreter can be found in the Agent message responses. You can download image files generated by code interpreter by iterating through the response's messages and checking for an `ImageFileId`. If that field exists, use the following code:
0 commit comments