Skip to content

Commit 625474b

Browse files
authored
Generate a new code and fix samples (Azure#49222)
* Regenerate code * Fix
1 parent 819a9d4 commit 625474b

33 files changed

+1382
-214
lines changed

sdk/ai/Azure.AI.Projects/README.md

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -606,56 +606,43 @@ We parse streaming updates in two cycles. One iterates over the streaming run ou
606606
```C# Snippet:FunctionsWithStreamingUpdateCycle
607607
List<ToolOutput> toolOutputs = [];
608608
ThreadRun streamRun = null;
609-
await foreach (StreamingUpdate streamingUpdate in client.CreateRunStreamingAsync(thread.Id, agent.Id))
609+
AsyncCollectionResult<StreamingUpdate> stream = client.CreateRunStreamingAsync(thread.Id, agent.Id);
610+
do
610611
{
611-
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
612-
{
613-
Console.WriteLine("--- Run started! ---");
614-
}
615-
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
612+
toolOutputs.Clear();
613+
await foreach (StreamingUpdate streamingUpdate in stream)
616614
{
617-
streamRun = submitToolOutputsUpdate.Value;
618-
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
619-
while (streamRun.Status == RunStatus.RequiresAction) {
615+
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
616+
{
617+
Console.WriteLine("--- Run started! ---");
618+
}
619+
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
620+
{
621+
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
620622
toolOutputs.Add(
621623
GetResolvedToolOutput(
622624
newActionUpdate.FunctionName,
623625
newActionUpdate.ToolCallId,
624626
newActionUpdate.FunctionArguments
625627
));
626-
await foreach (StreamingUpdate actionUpdate in client.SubmitToolOutputsToStreamAsync(streamRun, toolOutputs))
627-
{
628-
if (actionUpdate is MessageContentUpdate contentUpdate)
629-
{
630-
Console.Write(contentUpdate.Text);
631-
}
632-
else if (actionUpdate is RequiredActionUpdate newAction)
633-
{
634-
newActionUpdate = newAction;
635-
toolOutputs.Add(
636-
GetResolvedToolOutput(
637-
newActionUpdate.FunctionName,
638-
newActionUpdate.ToolCallId,
639-
newActionUpdate.FunctionArguments
640-
)
641-
);
642-
}
643-
else if (actionUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
644-
{
645-
Console.WriteLine();
646-
Console.WriteLine("--- Run completed! ---");
647-
}
648-
}
649-
streamRun = client.GetRun(thread.Id, streamRun.Id);
650-
toolOutputs.Clear();
628+
streamRun = submitToolOutputsUpdate.Value;
629+
}
630+
else if (streamingUpdate is MessageContentUpdate contentUpdate)
631+
{
632+
Console.Write(contentUpdate.Text);
633+
}
634+
else if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
635+
{
636+
Console.WriteLine();
637+
Console.WriteLine("--- Run completed! ---");
651638
}
652-
break;
653639
}
654-
else if (streamingUpdate is MessageContentUpdate contentUpdate)
640+
if (toolOutputs.Count > 0)
655641
{
656-
Console.Write(contentUpdate.Text);
642+
stream = client.SubmitToolOutputsToStreamAsync(streamRun, toolOutputs);
657643
}
658644
}
645+
while (toolOutputs.Count > 0);
659646
```
660647

661648
#### Azure function call
@@ -900,7 +887,7 @@ Any operation that fails will throw a [RequestFailedException][RequestFailedExce
900887
try
901888
{
902889
client.CreateMessage(
903-
"1234",
890+
"thread1234",
904891
MessageRole.User,
905892
"I need to solve the equation `3x + 11 = 14`. Can you help me?");
906893
}

sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.net8.0.cs

Lines changed: 61 additions & 1 deletion
Large diffs are not rendered by default.

sdk/ai/Azure.AI.Projects/api/Azure.AI.Projects.netstandard2.0.cs

Lines changed: 61 additions & 1 deletion
Large diffs are not rendered by default.

sdk/ai/Azure.AI.Projects/samples/Sample12_FunctionsWithStreaming.md

Lines changed: 48 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -145,119 +145,92 @@ ThreadMessage message = await client.CreateMessageAsync(
145145
"What's the weather like in my favorite city?");
146146
```
147147

148-
6. Create a stream and wait for the stream update of the `RequiredActionUpdate` type. This update will mark the point, when we need to submit tool outputs to the stream. We will submit outputs in the inner cycle. Please note that `RequiredActionUpdate` keeps only one required action, while our run may require multiple function calls, this case is handled in the inner cycle, so that we can add tool output to the existing array of outputs. After all required actions were submitted we clean up the array of required actions.
148+
6. Create a stream and wait for the stream update of the `RequiredActionUpdate` type. This update will mark the point, when we need to submit tool outputs to the stream. `RequiredActionUpdate` keeps only one required action, while our run may require multiple function calls, when the last required action has been read, the stream terminates and we start a new stream by submitting tool call results. In the begin of each cycle up the array of required actions.
149149

150150
Synchronous sample:
151151
```C# Snippet:FunctionsWithStreamingSyncUpdateCycle
152152
List<ToolOutput> toolOutputs = [];
153153
ThreadRun streamRun = null;
154-
foreach (StreamingUpdate streamingUpdate in client.CreateRunStreaming(thread.Id, agent.Id))
154+
CollectionResult<StreamingUpdate> stream = client.CreateRunStreaming(thread.Id, agent.Id);
155+
do
155156
{
156-
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
157+
toolOutputs.Clear();
158+
foreach (StreamingUpdate streamingUpdate in stream)
157159
{
158-
Console.WriteLine("--- Run started! ---");
159-
}
160-
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
161-
{
162-
streamRun = submitToolOutputsUpdate.Value;
163-
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
164-
while (streamRun.Status == RunStatus.RequiresAction)
160+
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
161+
{
162+
Console.WriteLine("--- Run started! ---");
163+
}
164+
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
165165
{
166+
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
166167
toolOutputs.Add(
167168
GetResolvedToolOutput(
168169
newActionUpdate.FunctionName,
169170
newActionUpdate.ToolCallId,
170171
newActionUpdate.FunctionArguments
171172
));
172-
foreach (StreamingUpdate actionUpdate in client.SubmitToolOutputsToStream(streamRun, toolOutputs))
173-
{
174-
if (actionUpdate is MessageContentUpdate contentUpdate)
175-
{
176-
Console.Write(contentUpdate.Text);
177-
}
178-
else if (actionUpdate is RequiredActionUpdate newAction)
179-
{
180-
newActionUpdate = newAction;
181-
toolOutputs.Add(
182-
GetResolvedToolOutput(
183-
newActionUpdate.FunctionName,
184-
newActionUpdate.ToolCallId,
185-
newActionUpdate.FunctionArguments
186-
)
187-
);
188-
}
189-
else if (actionUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
190-
{
191-
Console.WriteLine();
192-
Console.WriteLine("--- Run completed! ---");
193-
}
194-
}
195-
streamRun = client.GetRun(thread.Id, streamRun.Id);
196-
toolOutputs.Clear();
173+
streamRun = submitToolOutputsUpdate.Value;
174+
}
175+
else if (streamingUpdate is MessageContentUpdate contentUpdate)
176+
{
177+
Console.Write(contentUpdate.Text);
178+
}
179+
else if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
180+
{
181+
Console.WriteLine();
182+
Console.WriteLine("--- Run completed! ---");
197183
}
198-
break;
199184
}
200-
else if (streamingUpdate is MessageContentUpdate contentUpdate)
185+
if (toolOutputs.Count > 0)
201186
{
202-
Console.Write(contentUpdate.Text);
187+
stream = client.SubmitToolOutputsToStream(streamRun, toolOutputs);
203188
}
204189
}
190+
while (toolOutputs.Count > 0);
205191
```
206192

207193
Asynchronous sample:
208194
```C# Snippet:FunctionsWithStreamingUpdateCycle
209195
List<ToolOutput> toolOutputs = [];
210196
ThreadRun streamRun = null;
211-
await foreach (StreamingUpdate streamingUpdate in client.CreateRunStreamingAsync(thread.Id, agent.Id))
197+
AsyncCollectionResult<StreamingUpdate> stream = client.CreateRunStreamingAsync(thread.Id, agent.Id);
198+
do
212199
{
213-
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
200+
toolOutputs.Clear();
201+
await foreach (StreamingUpdate streamingUpdate in stream)
214202
{
215-
Console.WriteLine("--- Run started! ---");
216-
}
217-
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
218-
{
219-
streamRun = submitToolOutputsUpdate.Value;
220-
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
221-
while (streamRun.Status == RunStatus.RequiresAction) {
203+
if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCreated)
204+
{
205+
Console.WriteLine("--- Run started! ---");
206+
}
207+
else if (streamingUpdate is RequiredActionUpdate submitToolOutputsUpdate)
208+
{
209+
RequiredActionUpdate newActionUpdate = submitToolOutputsUpdate;
222210
toolOutputs.Add(
223211
GetResolvedToolOutput(
224212
newActionUpdate.FunctionName,
225213
newActionUpdate.ToolCallId,
226214
newActionUpdate.FunctionArguments
227215
));
228-
await foreach (StreamingUpdate actionUpdate in client.SubmitToolOutputsToStreamAsync(streamRun, toolOutputs))
229-
{
230-
if (actionUpdate is MessageContentUpdate contentUpdate)
231-
{
232-
Console.Write(contentUpdate.Text);
233-
}
234-
else if (actionUpdate is RequiredActionUpdate newAction)
235-
{
236-
newActionUpdate = newAction;
237-
toolOutputs.Add(
238-
GetResolvedToolOutput(
239-
newActionUpdate.FunctionName,
240-
newActionUpdate.ToolCallId,
241-
newActionUpdate.FunctionArguments
242-
)
243-
);
244-
}
245-
else if (actionUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
246-
{
247-
Console.WriteLine();
248-
Console.WriteLine("--- Run completed! ---");
249-
}
250-
}
251-
streamRun = client.GetRun(thread.Id, streamRun.Id);
252-
toolOutputs.Clear();
216+
streamRun = submitToolOutputsUpdate.Value;
217+
}
218+
else if (streamingUpdate is MessageContentUpdate contentUpdate)
219+
{
220+
Console.Write(contentUpdate.Text);
221+
}
222+
else if (streamingUpdate.UpdateKind == StreamingUpdateReason.RunCompleted)
223+
{
224+
Console.WriteLine();
225+
Console.WriteLine("--- Run completed! ---");
253226
}
254-
break;
255227
}
256-
else if (streamingUpdate is MessageContentUpdate contentUpdate)
228+
if (toolOutputs.Count > 0)
257229
{
258-
Console.Write(contentUpdate.Text);
230+
stream = client.SubmitToolOutputsToStreamAsync(streamRun, toolOutputs);
259231
}
260232
}
233+
while (toolOutputs.Count > 0);
261234
```
262235

263236
7. Finally, we delete all the resources, we have created in this sample.

sdk/ai/Azure.AI.Projects/src/Custom/Agent/OpenApiToolDefinition.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ namespace Azure.AI.Projects
1111
{
1212
public partial class OpenApiToolDefinition
1313
{
14-
public OpenApiToolDefinition(string name, string description, BinaryData spec, OpenApiAuthDetails auth):this(
14+
public OpenApiToolDefinition(string name, string description, BinaryData spec, OpenApiAuthDetails auth, IList<string> defaultParams = null) :this(
1515
new OpenApiFunctionDefinition(
1616
name: name,
1717
description: description,
1818
spec: spec,
1919
auth: auth,
20+
defaultParams: defaultParams ?? [],
2021
serializedAdditionalRawData: null
2122
)
2223
){}

sdk/ai/Azure.AI.Projects/src/Generated/AIProjectsModelFactory.cs

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/ai/Azure.AI.Projects/src/Generated/Agent.cs

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)