@@ -136,9 +136,19 @@ protected internal ChatClient(ClientPipeline pipeline, string model, OpenAIClien
136136 /// <param name="cancellationToken"> A token that can be used to cancel this method call. </param>
137137 /// <exception cref="ArgumentNullException"> <paramref name="messages"/> is null. </exception>
138138 /// <exception cref="ArgumentException"> <paramref name="messages"/> is an empty collection, and was expected to be non-empty. </exception>
139- public virtual async Task < ClientResult < ChatCompletion > > CompleteChatAsync ( IEnumerable < ChatMessage > messages , ChatCompletionOptions options = null , CancellationToken cancellationToken = default )
139+ public virtual Task < ClientResult < ChatCompletion > > CompleteChatAsync ( IEnumerable < ChatMessage > messages , ChatCompletionOptions options = null , CancellationToken cancellationToken = default )
140+ {
141+ return CompleteChatAsync ( messages , options , cancellationToken . ToRequestOptions ( ) ?? new RequestOptions ( ) ) ;
142+ }
143+
144+ internal async Task < ClientResult < ChatCompletion > > CompleteChatAsync ( IEnumerable < ChatMessage > messages , ChatCompletionOptions options , RequestOptions requestOptions )
140145 {
141146 Argument . AssertNotNullOrEmpty ( messages , nameof ( messages ) ) ;
147+ Argument . AssertNotNull ( requestOptions , nameof ( requestOptions ) ) ;
148+ if ( requestOptions . BufferResponse is false )
149+ {
150+ throw new InvalidOperationException ( "'requestOptions.BufferResponse' must be 'true' when calling 'CompleteChatAsync'." ) ;
151+ }
142152
143153 options ??= new ( ) ;
144154 CreateChatCompletionOptions ( messages , ref options ) ;
@@ -148,7 +158,7 @@ public virtual async Task<ClientResult<ChatCompletion>> CompleteChatAsync(IEnume
148158 {
149159 using BinaryContent content = options . ToBinaryContent ( ) ;
150160
151- ClientResult result = await CompleteChatAsync ( content , cancellationToken . ToRequestOptions ( ) ) . ConfigureAwait ( false ) ;
161+ ClientResult result = await CompleteChatAsync ( content , requestOptions ) . ConfigureAwait ( false ) ;
152162 ChatCompletion chatCompletion = ( ChatCompletion ) result ;
153163 scope ? . RecordChatCompletion ( chatCompletion ) ;
154164 return ClientResult . FromValue ( chatCompletion , result . GetRawResponse ( ) ) ;
@@ -218,17 +228,27 @@ public virtual ClientResult<ChatCompletion> CompleteChat(params ChatMessage[] me
218228 /// <exception cref="ArgumentNullException"> <paramref name="messages"/> is null. </exception>
219229 /// <exception cref="ArgumentException"> <paramref name="messages"/> is an empty collection, and was expected to be non-empty. </exception>
220230 public virtual AsyncCollectionResult < StreamingChatCompletionUpdate > CompleteChatStreamingAsync ( IEnumerable < ChatMessage > messages , ChatCompletionOptions options = null , CancellationToken cancellationToken = default )
231+ {
232+ return CompleteChatStreamingAsync ( messages , options , cancellationToken . ToRequestOptions ( streaming : true ) ) ;
233+ }
234+
235+ internal AsyncCollectionResult < StreamingChatCompletionUpdate > CompleteChatStreamingAsync ( IEnumerable < ChatMessage > messages , ChatCompletionOptions options , RequestOptions requestOptions )
221236 {
222237 Argument . AssertNotNull ( messages , nameof ( messages ) ) ;
238+ Argument . AssertNotNull ( requestOptions , nameof ( requestOptions ) ) ;
239+ if ( requestOptions . BufferResponse is true )
240+ {
241+ throw new InvalidOperationException ( "'requestOptions.BufferResponse' must be 'false' when calling 'CompleteChatStreamingAsync'." ) ;
242+ }
223243
224244 options ??= new ( ) ;
225245 CreateChatCompletionOptions ( messages , ref options , stream : true ) ;
226246
227247 using BinaryContent content = options . ToBinaryContent ( ) ;
228248 return new AsyncSseUpdateCollection < StreamingChatCompletionUpdate > (
229- async ( ) => await CompleteChatAsync ( content , cancellationToken . ToRequestOptions ( streaming : true ) ) . ConfigureAwait ( false ) ,
249+ async ( ) => await CompleteChatAsync ( content , requestOptions ) . ConfigureAwait ( false ) ,
230250 StreamingChatCompletionUpdate . DeserializeStreamingChatCompletionUpdate ,
231- cancellationToken ) ;
251+ requestOptions . CancellationToken ) ;
232252 }
233253
234254 /// <summary>
0 commit comments