Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dotnet.azure/.tests.staging/AoaiTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public AoaiTestBase(bool isAsync) { }
public TClient GetTestClient()
{
AzureOpenAIClient topLevelClient = GetTestTopLevelClient(null);
string getDeployment() => "gpt-4o";
string getDeployment() => "gpt-4";

object clientObject = null;

Expand Down
67 changes: 2 additions & 65 deletions .dotnet.azure/.tests.staging/AssistantTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public AssistantTests(bool isAsync) : base(isAsync) { }
public async Task BasicAssistantOperationsWork()
{
AssistantClient client = GetTestClient();
string modelName = "gpt-4o"; // client.DeploymentOrThrow();
string modelName = "gpt-4"; // client.DeploymentOrThrow();
Assistant assistant = await client.CreateAssistantAsync(modelName);
Validate(assistant);
Assert.That(assistant.Name, Is.Null.Or.Empty);
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task BasicAssistantOperationsWork()
},
});
Assert.That(modifiedAssistant.Id, Is.EqualTo(assistant.Id));
AsyncPageableCollection<Assistant> recentAssistants = client.GetAssistantsAsync();
IAsyncEnumerable<Assistant> recentAssistants = client.GetAssistantsAsync().GetAllValuesAsync();
//SyncOrAsync(
// client, c => c.GetAssistants(), c => c.GetAssistantsAsync());
Assistant recentAssistant = null;
Expand Down Expand Up @@ -670,68 +670,5 @@ public async Task BasicAssistantOperationsWork()
// Assert.That(content, Has.Length.GreaterThan(0));
// }

[Test]
public async Task BrowserToolWorks()
{
Uri endpoint = new("https://openai-sdk-testing-tip.openai.azure.com");
TokenCredential credential = new DefaultAzureCredential();
AzureOpenAIClientOptions options = new();
options.AddPolicy(new GenericActionPipelinePolicy(
requestAction: request =>
{
request.Headers.Set("X-Ms-Enable-Preview", "true");
}),
PipelinePosition.PerCall);
AzureOpenAIClient azureClient = new(endpoint, credential, options);
AssistantClient client = azureClient.GetAssistantClient();

Assistant assistant = await client.CreateAssistantAsync(
"gpt-4-0125-preview",
new AssistantCreationOptions()
{
Instructions = "When asked to retrieve up-to-date information, use the browser tool.",
Tools =
{
new BingSearchToolDefinition()
{
BingResourceId = "/subscriptions/6a6fff00-4464-4eab-a6b1-0b533c7202e0/resourceGroups/rg-agent-test-westus2/providers/Microsoft.Bing/accounts/chattest-westus2-bing",
},
},
});
Validate(assistant);

ThreadCreationOptions threadOptions = new()
{
InitialMessages =
{
"What's the date and what's headline news today?"
},
};

List<TextAnnotationUpdate> annotationUpdates = [];
await foreach (StreamingUpdate update in client.CreateThreadAndRunStreamingAsync(assistant.Id, threadOptions))
{
if (update is MessageContentUpdate contentUpdate)
{
Console.Write(contentUpdate.Text);
if (contentUpdate.TextAnnotation is not null)
{
annotationUpdates.Add(contentUpdate.TextAnnotation);
}
}
}
Console.WriteLine();

if (annotationUpdates.Count > 0)
{
Console.WriteLine("Citations:");
for (int i = 0; i < annotationUpdates.Count; i++)
{
Console.WriteLine($"{(i + 1)}: {annotationUpdates[i].GetBingSearchTitle()}");
Console.WriteLine($" {annotationUpdates[i].GetBingSearchUrl().AbsoluteUri}");
}
}
}

private static readonly DateTimeOffset s_2024 = new(2024, 1, 1, 0, 0, 0, TimeSpan.Zero);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public override ClientResult CreateAssistant(BinaryContent content, RequestOptio
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
}

public override async Task<ClientResult> GetAssistantsAsync(int? limit, string order, string after, string before, RequestOptions options)
public override IAsyncEnumerable<ClientResult> GetAssistantsAsync(int? limit, string order, string after, string before, RequestOptions options)
{
using PipelineMessage message = CreateGetAssistantsRequest(limit, order, after, before, options);
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
AzureAssistantsPageEnumerator enumerator = new(Pipeline, _endpoint, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.CreateAsync(enumerator);
}

public override ClientResult GetAssistants(int? limit, string order, string after, string before, RequestOptions options)
public override IEnumerable<ClientResult> GetAssistants(int? limit, string order, string after, string before, RequestOptions options)
{
using PipelineMessage message = CreateGetAssistantsRequest(limit, order, after, before, options);
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
AzureAssistantsPageEnumerator enumerator = new(Pipeline, _endpoint, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.Create(enumerator);
}

public override async Task<ClientResult> GetAssistantAsync(string assistantId, RequestOptions options)
Expand Down Expand Up @@ -108,21 +108,21 @@ public override ClientResult CreateMessage(string threadId, BinaryContent conten
}

/// <inheritdoc cref="InternalAssistantMessageClient.GetMessagesAsync"/>
public override async Task<ClientResult> GetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
public override IAsyncEnumerable<ClientResult> GetMessagesAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));

using PipelineMessage message = CreateGetMessagesRequest(threadId, limit, order, after, before, options);
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
AzureMessagesPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantMessageClient.GetMessages"/>
public override ClientResult GetMessages(string threadId, int? limit, string order, string after, string before, RequestOptions options)
public override IEnumerable<ClientResult> GetMessages(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));

using PipelineMessage message = CreateGetMessagesRequest(threadId, limit, order, after, before, options);
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
AzureMessagesPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.Create(enumerator);
}

/// <inheritdoc cref="InternalAssistantMessageClient.GetMessageAsync"/>
Expand Down Expand Up @@ -260,21 +260,21 @@ public override ClientResult CreateRun(string threadId, BinaryContent content, R
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunsAsync"/>
public override async Task<ClientResult> GetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
public override IAsyncEnumerable<ClientResult> GetRunsAsync(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));

using PipelineMessage message = CreateGetRunsRequest(threadId, limit, order, after, before, options);
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
AzureRunsPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRuns"/>
public override ClientResult GetRuns(string threadId, int? limit, string order, string after, string before, RequestOptions options)
public override IEnumerable<ClientResult> GetRuns(string threadId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));

using PipelineMessage message = CreateGetRunsRequest(threadId, limit, order, after, before, options);
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
AzureRunsPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.Create(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunAsync"/>
Expand Down Expand Up @@ -380,23 +380,23 @@ public override ClientResult SubmitToolOutputsToRun(string threadId, string runI
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunStepsAsync"/>
public override async Task<ClientResult> GetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
public override IAsyncEnumerable<ClientResult> GetRunStepsAsync(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Argument.AssertNotNullOrEmpty(runId, nameof(runId));

using PipelineMessage message = CreateGetRunStepsRequest(threadId, runId, limit, order, after, before, options);
return ClientResult.FromResponse(await Pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false));
AzureRunStepsPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, runId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.CreateAsync(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunSteps"/>
public override ClientResult GetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
public override IEnumerable<ClientResult> GetRunSteps(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
{
Argument.AssertNotNullOrEmpty(threadId, nameof(threadId));
Argument.AssertNotNullOrEmpty(runId, nameof(runId));

using PipelineMessage message = CreateGetRunStepsRequest(threadId, runId, limit, order, after, before, options);
return ClientResult.FromResponse(Pipeline.ProcessMessage(message, options));
AzureRunStepsPageEnumerator enumerator = new(Pipeline, _endpoint, threadId, runId, limit, order, after, before, _apiVersion, options);
return PageCollectionHelpers.Create(enumerator);
}

/// <inheritdoc cref="InternalAssistantRunClient.GetRunStepAsync"/>
Expand Down Expand Up @@ -492,9 +492,6 @@ public override ClientResult DeleteThread(string threadId, RequestOptions option
private new PipelineMessage CreateCreateAssistantRequest(BinaryContent content, RequestOptions options = null)
=> NewJsonPostBuilder(content, options).WithPath("assistants").Build();

private new PipelineMessage CreateGetAssistantsRequest(int? limit, string order, string after, string before, RequestOptions options)
=> NewGetListBuilder(limit, order, after, before, options).WithPath("assistants").Build();

private new PipelineMessage CreateGetAssistantRequest(string assistantId, RequestOptions options)
=> NewJsonGetBuilder(options).WithPath("assistants", assistantId).Build();

Expand Down Expand Up @@ -522,9 +519,6 @@ private PipelineMessage CreateDeleteThreadRequest(string threadId, RequestOption
private PipelineMessage CreateCreateMessageRequest(string threadId, BinaryContent content, RequestOptions options)
=> NewJsonPostBuilder(content, options).WithPath("threads", threadId, "messages").Build();

private PipelineMessage CreateGetMessagesRequest(string threadId, int? limit, string order, string after, string before, RequestOptions options)
=> NewGetListBuilder(limit, order, after, before, options).WithPath("threads", threadId, "messages").Build();

private PipelineMessage CreateGetMessageRequest(string threadId, string messageId, RequestOptions options)
=> NewJsonGetBuilder(options).WithPath("threads", threadId, "messages", messageId).Build();

Expand All @@ -540,9 +534,6 @@ private PipelineMessage CreateCreateThreadAndRunRequest(BinaryContent content, R
private PipelineMessage CreateCreateRunRequest(string threadId, BinaryContent content, RequestOptions options)
=> NewJsonPostBuilder(content, options).WithPath("threads", threadId, "runs").Build();

private PipelineMessage CreateGetRunsRequest(string threadId, int? limit, string order, string after, string before, RequestOptions options)
=> NewGetListBuilder(limit, order, after, before, options).WithPath("threads", threadId, "runs").Build();

private PipelineMessage CreateGetRunRequest(string threadId, string runId, RequestOptions options)
=> NewJsonGetBuilder(options).WithPath("threads", threadId, "runs", runId).Build();

Expand All @@ -555,16 +546,14 @@ private PipelineMessage CreateCancelRunRequest(string threadId, string runId, Re
private PipelineMessage CreateSubmitToolOutputsToRunRequest(string threadId, string runId, BinaryContent content, RequestOptions options)
=> NewJsonPostBuilder(content, options).WithPath("threads", threadId, "runs", runId, "submit_tool_outputs").Build();

private PipelineMessage CreateGetRunStepsRequest(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
=> NewGetListBuilder(limit, order, after, before, options).WithPath("threads", threadId, "runs", runId, "steps").Build();

private PipelineMessage CreateGetRunStepRequest(string threadId, string runId, string stepId, RequestOptions options)
=> NewJsonGetBuilder(options).WithPath("threads", threadId, "runs", runId, "steps", stepId).Build();

private AzureOpenAIPipelineMessageBuilder NewBuilder(RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithHeader(s_OpenAIBetaFeatureHeader, s_OpenAIBetaAssistantsV2HeaderValue)
.WithAssistantsHeader()
.WithOptions(options);

private AzureOpenAIPipelineMessageBuilder NewJsonPostBuilder(BinaryContent content, RequestOptions options)
=> NewBuilder(options)
.WithMethod("POST")
Expand All @@ -583,11 +572,5 @@ private AzureOpenAIPipelineMessageBuilder NewJsonDeleteBuilder(RequestOptions op

private AzureOpenAIPipelineMessageBuilder NewGetListBuilder(int? limit, string order, string after, string before, RequestOptions options)
=> NewJsonGetBuilder(options)
.WithOptionalQueryParameter("limit", limit)
.WithOptionalQueryParameter("order", order)
.WithOptionalQueryParameter("after", after)
.WithOptionalQueryParameter("before", before);

private static readonly string s_OpenAIBetaFeatureHeader = "OpenAI-Beta";
private static readonly string s_OpenAIBetaAssistantsV2HeaderValue = "assistants=v2";
.WithCommonListParameters(limit, order, after, before);
}
21 changes: 0 additions & 21 deletions .dotnet.azure/src/Custom/Assistants/AzureRunStepToolCall.cs

This file was deleted.

59 changes: 0 additions & 59 deletions .dotnet.azure/src/Custom/Assistants/AzureTextAnnotation.cs

This file was deleted.

Loading