Skip to content
Merged
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
28 changes: 24 additions & 4 deletions src/Custom/Responses/OpenAIResponseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,21 @@ public virtual CollectionResult<StreamingResponseUpdate> CreateResponseStreaming
cancellationToken);
}

public virtual async Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, CancellationToken cancellationToken = default)
public virtual Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, CancellationToken cancellationToken = default)
{
return GetResponseAsync(responseId, cancellationToken.ToRequestOptions() ?? new RequestOptions());
}

internal async Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, RequestOptions requestOptions)
{
Argument.AssertNotNullOrEmpty(responseId, nameof(responseId));
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
if (requestOptions.BufferResponse is false)
{
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'true' when calling 'GetResponseAsync'.");
}

ClientResult protocolResult = await GetResponseAsync(responseId, stream: null, startingAfter: null, cancellationToken.ToRequestOptions()).ConfigureAwait(false);
ClientResult protocolResult = await GetResponseAsync(responseId, stream: null, startingAfter: null, requestOptions).ConfigureAwait(false);
OpenAIResponse convenienceResult = (OpenAIResponse)protocolResult;
return ClientResult.FromValue(convenienceResult, protocolResult.GetRawResponse());
}
Expand All @@ -247,13 +257,23 @@ public virtual ClientResult<OpenAIResponse> GetResponse(string responseId, Cance
}

public virtual AsyncCollectionResult<StreamingResponseUpdate> GetResponseStreamingAsync(string responseId, int? startingAfter = null, CancellationToken cancellationToken = default)
{
return GetResponseStreamingAsync(responseId, cancellationToken.ToRequestOptions(streaming: true), startingAfter);
}

internal AsyncCollectionResult<StreamingResponseUpdate> GetResponseStreamingAsync(string responseId, RequestOptions requestOptions, int? startingAfter = null)
{
Argument.AssertNotNull(responseId, nameof(responseId));
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
if (requestOptions.BufferResponse is true)
{
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'false' when calling 'GetResponseStreamingAsync'.");
}

return new AsyncSseUpdateCollection<StreamingResponseUpdate>(
async () => await GetResponseAsync(responseId, stream: true, startingAfter, cancellationToken.ToRequestOptions(streaming: true)).ConfigureAwait(false),
async () => await GetResponseAsync(responseId, stream: true, startingAfter, requestOptions).ConfigureAwait(false),
StreamingResponseUpdate.DeserializeStreamingResponseUpdate,
cancellationToken);
requestOptions.CancellationToken);
}

public virtual CollectionResult<StreamingResponseUpdate> GetResponseStreaming(string responseId, int? startingAfter = null, CancellationToken cancellationToken = default)
Expand Down