Skip to content

Commit 1798e12

Browse files
[azopenaiassistants] Updated changelog, added in examples for more complex scenarios. (Azure#23106)
* Updated changelog, added in examples for more complex scenarios. * Noticed I was using context.Background() sometimes in examples, but it should always be context.TODO()
1 parent d765680 commit 1798e12

7 files changed

+301
-25
lines changed

sdk/ai/azopenaiassistants/CHANGELOG.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Release History
22

3-
## 0.2.0 (TBD)
3+
## 0.2.0 (2024-06-25)
44

55
### Features Added
66

7-
- Now supports the Assistants V2 API, with support for vector stores.
8-
9-
### Bugs Fixed
7+
- Now supports the Assistants V2 API, with support for vector stores as well as streaming.
108

119
### Breaking Changes
1210

sdk/ai/azopenaiassistants/client_custom_streaming_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func submitToolOutputsWithStreaming(t *testing.T, client *azopenaiassistants.Cli
190190
resp, err := client.SubmitToolOutputsToRunStream(context.Background(), *lastResp.ThreadID, *lastResp.ID, azopenaiassistants.SubmitToolOutputsToRunBody{
191191
ToolOutputs: []azopenaiassistants.ToolOutput{
192192
{
193-
Output: to.Ptr("0C"),
193+
Output: to.Ptr("26C"),
194194
ToolCallID: funcToolCall.ID,
195195
},
196196
},

sdk/ai/azopenaiassistants/example_assistants_code_interpreter_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func Example_assistantsUsingCodeInterpreter() {
4242
assistantName := fmt.Sprintf("your-assistant-name-%d", time.Now().UnixNano())
4343

4444
// First, let's create an assistant.
45-
createAssistantResp, err := client.CreateAssistant(context.Background(), azopenaiassistants.CreateAssistantBody{
45+
createAssistantResp, err := client.CreateAssistant(context.TODO(), azopenaiassistants.CreateAssistantBody{
4646
Name: &assistantName,
4747
DeploymentName: to.Ptr("gpt-4-1106-preview"),
4848
Instructions: to.Ptr("You are an AI assistant that can write code to help answer math questions."),
@@ -122,7 +122,7 @@ func Example_assistantsUsingCodeInterpreter() {
122122
})
123123

124124
for listMessagesPager.More() {
125-
page, err := listMessagesPager.NextPage(context.Background())
125+
page, err := listMessagesPager.NextPage(context.TODO())
126126

127127
if err != nil {
128128
// TODO: Update the following line with your application specific error handling logic
@@ -143,7 +143,7 @@ func Example_assistantsUsingCodeInterpreter() {
143143

144144
func pollCodeInterpreterEnd(ctx context.Context, client *azopenaiassistants.Client, threadID string, runID string) (azopenaiassistants.GetRunResponse, error) {
145145
for {
146-
lastGetRunResp, err := client.GetRun(context.Background(), threadID, runID, nil)
146+
lastGetRunResp, err := client.GetRun(context.TODO(), threadID, runID, nil)
147147

148148
if err != nil {
149149
return azopenaiassistants.GetRunResponse{}, err

sdk/ai/azopenaiassistants/example_assistants_conversation_loop_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func Example_assistantsWithConversationLoop() {
4848
}
4949

5050
// First, let's create an assistant.
51-
createAssistantResp, err := client.CreateAssistant(context.Background(), azopenaiassistants.CreateAssistantBody{
51+
createAssistantResp, err := client.CreateAssistant(context.TODO(), azopenaiassistants.CreateAssistantBody{
5252
Name: &assistantName,
5353
DeploymentName: to.Ptr("gpt-4-1106-preview"),
5454
Instructions: to.Ptr("You are a personal math tutor. Write and run code to answer math questions."),
@@ -79,7 +79,7 @@ func Example_assistantsWithConversationLoop() {
7979

8080
// Now we'll create a thread. The thread is where you will add messages, which can later
8181
// be evaluated using a Run. A thread can be re-used by multiple Runs.
82-
createThreadResp, err := client.CreateThread(context.Background(), azopenaiassistants.CreateThreadBody{}, nil)
82+
createThreadResp, err := client.CreateThread(context.TODO(), azopenaiassistants.CreateThreadBody{}, nil)
8383

8484
if err != nil {
8585
// TODO: Update the following line with your application specific error handling logic
@@ -172,7 +172,7 @@ func assistantLoop(ctx context.Context, client *azopenaiassistants.Client,
172172
for _, yourResponse := range yourResponses {
173173
// Add some messages to the thread. We will use Run the thread later to evaluate these and to get
174174
// responses from the assistant.
175-
createMessageResp, err := client.CreateMessage(context.Background(), threadID, yourResponse, nil)
175+
createMessageResp, err := client.CreateMessage(context.TODO(), threadID, yourResponse, nil)
176176

177177
if err != nil {
178178
return err
@@ -183,7 +183,7 @@ func assistantLoop(ctx context.Context, client *azopenaiassistants.Client,
183183
lastMessageID = createMessageResp.ID
184184
}
185185

186-
createRunResp, err := client.CreateRun(context.Background(), threadID, azopenaiassistants.CreateRunBody{
186+
createRunResp, err := client.CreateRun(context.TODO(), threadID, azopenaiassistants.CreateRunBody{
187187
AssistantID: &assistantID,
188188
}, nil)
189189

@@ -239,7 +239,7 @@ func printAssistantMessages(ctx context.Context, client *azopenaiassistants.Clie
239239

240240
func pollUntilRunEnds(ctx context.Context, client *azopenaiassistants.Client, threadID string, runID string) (azopenaiassistants.GetRunResponse, error) {
241241
for {
242-
lastGetRunResp, err := client.GetRun(context.Background(), threadID, runID, nil)
242+
lastGetRunResp, err := client.GetRun(context.TODO(), threadID, runID, nil)
243243

244244
if err != nil {
245245
return azopenaiassistants.GetRunResponse{}, err

sdk/ai/azopenaiassistants/example_assistants_functiontool_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Example_assistantsUsingFunctionTool() {
6767
}
6868

6969
// First, let's create an assistant.
70-
createAssistantResp, err := client.CreateAssistant(context.Background(), azopenaiassistants.CreateAssistantBody{
70+
createAssistantResp, err := client.CreateAssistant(context.TODO(), azopenaiassistants.CreateAssistantBody{
7171
Name: &assistantName,
7272
DeploymentName: to.Ptr("gpt-4-1106-preview"),
7373
Instructions: to.Ptr("You are a personal math tutor. Write and run code to answer math questions."),
@@ -90,7 +90,7 @@ func Example_assistantsUsingFunctionTool() {
9090
var lastMessageID, runID, threadID string
9191
{
9292
fmt.Fprintf(os.Stderr, "Creating our thread\n")
93-
createThreadResp, err := client.CreateThread(context.Background(), azopenaiassistants.CreateThreadBody{}, nil)
93+
createThreadResp, err := client.CreateThread(context.TODO(), azopenaiassistants.CreateThreadBody{}, nil)
9494

9595
if err != nil {
9696
// TODO: Update the following line with your application specific error handling logic
@@ -99,7 +99,7 @@ func Example_assistantsUsingFunctionTool() {
9999

100100
threadID = *createThreadResp.ID
101101

102-
msgResponse, err := client.CreateMessage(context.Background(), threadID, azopenaiassistants.CreateMessageBody{
102+
msgResponse, err := client.CreateMessage(context.TODO(), threadID, azopenaiassistants.CreateMessageBody{
103103
Content: &question,
104104
Role: to.Ptr(azopenaiassistants.MessageRoleUser),
105105
}, nil)
@@ -114,7 +114,7 @@ func Example_assistantsUsingFunctionTool() {
114114
// run the thread
115115
fmt.Fprintf(os.Stderr, "Creating our run for thread %s\n", *createThreadResp.ID)
116116

117-
createRunResp, err := client.CreateRun(context.Background(), *createThreadResp.ID, azopenaiassistants.CreateRunBody{
117+
createRunResp, err := client.CreateRun(context.TODO(), *createThreadResp.ID, azopenaiassistants.CreateRunBody{
118118
AssistantID: createAssistantResp.ID,
119119
Instructions: to.Ptr("Use functions to answer questions, when possible."),
120120
}, nil)
@@ -130,7 +130,7 @@ func Example_assistantsUsingFunctionTool() {
130130
fmt.Fprintf(os.Stderr, "Waiting for the Run status to indicate it needs tool outputs\n")
131131
// NOTE: see https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/ai/azopenaiassistants#example-package-AssistantsConversationLoop
132132
// for the pollUntilRunEnds function.
133-
lastResp, err := pollUntilRunEnds(context.Background(), client, threadID, runID)
133+
lastResp, err := pollUntilRunEnds(context.TODO(), client, threadID, runID)
134134
if err != nil {
135135
// TODO: Update the following line with your application specific error handling logic
136136
log.Fatalf("ERROR: %s", err)
@@ -171,7 +171,7 @@ func Example_assistantsUsingFunctionTool() {
171171
fmt.Fprintf(os.Stderr, "Call our own function to get the weather for %s, in %s\n", weatherFuncArgs.Location, weatherFuncArgs.Unit)
172172
{
173173
// submit our outputs from evaluating the tool
174-
_, err := client.SubmitToolOutputsToRun(context.Background(), threadID, runID, azopenaiassistants.SubmitToolOutputsToRunBody{
174+
_, err := client.SubmitToolOutputsToRun(context.TODO(), threadID, runID, azopenaiassistants.SubmitToolOutputsToRunBody{
175175
ToolOutputs: []azopenaiassistants.ToolOutput{
176176
{
177177
Output: to.Ptr("0C"),
@@ -189,7 +189,7 @@ func Example_assistantsUsingFunctionTool() {
189189
// the run will restart now, we just need to wait until it finishes
190190
// NOTE: see https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/ai/azopenaiassistants#example-package-AssistantsConversationLoop
191191
// for the pollUntilRunEnds function.
192-
lastResp, err = pollUntilRunEnds(context.Background(), client, threadID, runID)
192+
lastResp, err = pollUntilRunEnds(context.TODO(), client, threadID, runID)
193193

194194
if err != nil || *lastResp.Status != azopenaiassistants.RunStatusCompleted {
195195
// TODO: Update the following line with your application specific error handling logic
@@ -200,7 +200,7 @@ func Example_assistantsUsingFunctionTool() {
200200

201201
// NOTE: see https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/ai/azopenaiassistants#example-package-AssistantsConversationLoop
202202
// for the getLatestMessages function.
203-
latestMessages, err := getLatestMessages(context.Background(), client, threadID, &lastMessageID)
203+
latestMessages, err := getLatestMessages(context.TODO(), client, threadID, &lastMessageID)
204204
if err != nil {
205205
// TODO: Update the following line with your application specific error handling logic
206206
log.Fatalf("ERROR: %s", err)
@@ -211,7 +211,7 @@ func Example_assistantsUsingFunctionTool() {
211211
// [ASSISTANT] <id>: Text response: The current weather in Boston, MA, measured in Celsius, is 0°C.
212212
// NOTE: see https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/ai/azopenaiassistants#example-package-AssistantsConversationLoop
213213
// for the printAssistantMessages function.
214-
err = printAssistantMessages(context.Background(), client, latestMessages)
214+
err = printAssistantMessages(context.TODO(), client, latestMessages)
215215

216216
if err != nil {
217217
// TODO: Update the following line with your application specific error handling logic

sdk/ai/azopenaiassistants/example_assistants_streaming_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func Example_assistantsStreaming() {
4444
assistantName := fmt.Sprintf("your-assistant-name-%d", time.Now().UnixNano())
4545

4646
// First, let's create an assistant.
47-
createAssistantResp, err := client.CreateAssistant(context.Background(), azopenaiassistants.CreateAssistantBody{
47+
createAssistantResp, err := client.CreateAssistant(context.TODO(), azopenaiassistants.CreateAssistantBody{
4848
Name: &assistantName,
4949
DeploymentName: to.Ptr("gpt-4-1106-preview"),
5050
Instructions: to.Ptr("You are an AI assistant that can write code to help answer math questions."),
@@ -73,7 +73,7 @@ func Example_assistantsStreaming() {
7373
}
7474
}()
7575

76-
resp, err := client.CreateThreadAndRunStream(context.Background(), azopenaiassistants.CreateAndRunThreadBody{
76+
resp, err := client.CreateThreadAndRunStream(context.TODO(), azopenaiassistants.CreateAndRunThreadBody{
7777
AssistantID: assistantID,
7878
DeploymentName: &assistantsModel,
7979
Instructions: to.Ptr("You're a helpful assistant that provides answers on questions about beetles."),
@@ -109,7 +109,7 @@ func Example_assistantsStreaming() {
109109
}
110110

111111
// NOTE: for this example we're handling a small subset of the events that are
112-
// streaming in. See [AssistantStreamEvent] for the full list of available events.
112+
// streaming in. See [azopenaiassistants.AssistantStreamEvent] for the full list of available events.
113113
switch event.Reason {
114114
// Assistant events
115115
case azopenaiassistants.AssistantStreamEventThreadCreated:

0 commit comments

Comments
 (0)