Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 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
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.ClientModel;
using System.ClientModel.Primitives;

#nullable enable

namespace Azure.AI.OpenAI.Assistants;

internal partial class AzureAssistantsPageEnumerator : AssistantsPageEnumerator
Comment thread
trrwilson marked this conversation as resolved.
{
private readonly Uri _endpoint;
private readonly string _apiVersion;

public AzureAssistantsPageEnumerator(
ClientPipeline pipeline,
Uri endpoint,
int? limit, string order, string after, string before,
string apiVersion,
RequestOptions options)
: base(pipeline, endpoint, limit, order, after, before, options)
{
_endpoint = endpoint;
_apiVersion = apiVersion;
}

internal override async Task<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));
}

internal override 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));
}

private new PipelineMessage CreateGetAssistantsRequest(int? limit, string order, string after, string before, RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithAssistantsHeader()
.WithOptions(options)
.WithMethod("GET")
.WithAccept("application/json")
.WithCommonListParameters(limit, order, after, before)
.WithPath("assistants")
.Build();
}
51 changes: 51 additions & 0 deletions .dotnet.azure/src/Custom/Assistants/AzureMessagesPageEnumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.ClientModel;
using System.ClientModel.Primitives;

#nullable enable

namespace Azure.AI.OpenAI.Assistants;

internal partial class AzureMessagesPageEnumerator : MessagesPageEnumerator
Comment thread
trrwilson marked this conversation as resolved.
{
private readonly Uri _endpoint;
private readonly string _apiVersion;

public AzureMessagesPageEnumerator(
ClientPipeline pipeline,
Uri endpoint,
string threadId,
int? limit, string order, string after, string before,
string apiVersion,
RequestOptions options)
: base(pipeline, endpoint, threadId, limit, order, after, before, options)
{
_endpoint = endpoint;
_apiVersion = apiVersion;
}

internal override async Task<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));
}

internal override 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));
}

private PipelineMessage CreateGetMessagesRequest(string threadId, int? limit, string order, string after, string before, RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithAssistantsHeader()
.WithOptions(options)
.WithMethod("GET")
.WithAccept("application/json")
.WithCommonListParameters(limit, order, after, before)
.WithPath("threads", threadId, "messages")
.Build();
}
53 changes: 53 additions & 0 deletions .dotnet.azure/src/Custom/Assistants/AzureRunStepsPageEnumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System.ClientModel;
using System.ClientModel.Primitives;

#nullable enable

namespace Azure.AI.OpenAI.Assistants;

internal partial class AzureRunStepsPageEnumerator : RunStepsPageEnumerator
{
private readonly Uri _endpoint;
private readonly string _apiVersion;

public AzureRunStepsPageEnumerator(
ClientPipeline pipeline,
Uri endpoint,
string threadId, string runId,
int? limit, string? order, string? after, string? before,
string apiVersion,
RequestOptions options)
: base(pipeline, endpoint, threadId, runId, limit, order, after, before, options)
{
_endpoint = endpoint;
_apiVersion = apiVersion;
}

internal override async Task<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));
}

internal override 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));
}

private PipelineMessage CreateGetRunStepsRequest(string threadId, string runId, int? limit, string order, string after, string before, RequestOptions options)
=> new AzureOpenAIPipelineMessageBuilder(Pipeline, _endpoint, _apiVersion)
.WithAssistantsHeader()
.WithOptions(options)
.WithMethod("GET")
.WithAccept("application/json")
.WithCommonListParameters(limit, order, after, before)
.WithPath("threads", threadId, "runs", runId, "steps")
.Build();
}
Loading