Skip to content

Commit d8e67d6

Browse files
Add OpenAIResponseClient.GetResponse{Streaming}Async overloads that take RequestOptions (#753)
1 parent 9275622 commit d8e67d6

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/Custom/Responses/OpenAIResponseClient.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,21 @@ public virtual CollectionResult<StreamingResponseUpdate> CreateResponseStreaming
228228
cancellationToken);
229229
}
230230

231-
public virtual async Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, CancellationToken cancellationToken = default)
231+
public virtual Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, CancellationToken cancellationToken = default)
232+
{
233+
return GetResponseAsync(responseId, cancellationToken.ToRequestOptions() ?? new RequestOptions());
234+
}
235+
236+
internal async Task<ClientResult<OpenAIResponse>> GetResponseAsync(string responseId, RequestOptions requestOptions)
232237
{
233238
Argument.AssertNotNullOrEmpty(responseId, nameof(responseId));
239+
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
240+
if (requestOptions.BufferResponse is false)
241+
{
242+
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'true' when calling 'GetResponseAsync'.");
243+
}
234244

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

249259
public virtual AsyncCollectionResult<StreamingResponseUpdate> GetResponseStreamingAsync(string responseId, int? startingAfter = null, CancellationToken cancellationToken = default)
260+
{
261+
return GetResponseStreamingAsync(responseId, cancellationToken.ToRequestOptions(streaming: true), startingAfter);
262+
}
263+
264+
internal AsyncCollectionResult<StreamingResponseUpdate> GetResponseStreamingAsync(string responseId, RequestOptions requestOptions, int? startingAfter = null)
250265
{
251266
Argument.AssertNotNull(responseId, nameof(responseId));
267+
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
268+
if (requestOptions.BufferResponse is true)
269+
{
270+
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'false' when calling 'GetResponseStreamingAsync'.");
271+
}
252272

253273
return new AsyncSseUpdateCollection<StreamingResponseUpdate>(
254-
async () => await GetResponseAsync(responseId, stream: true, startingAfter, cancellationToken.ToRequestOptions(streaming: true)).ConfigureAwait(false),
274+
async () => await GetResponseAsync(responseId, stream: true, startingAfter, requestOptions).ConfigureAwait(false),
255275
StreamingResponseUpdate.DeserializeStreamingResponseUpdate,
256-
cancellationToken);
276+
requestOptions.CancellationToken);
257277
}
258278

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

0 commit comments

Comments
 (0)