Skip to content

Commit 9d3a798

Browse files
committed
Make new overloads internal
1 parent 36b009e commit 9d3a798

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/Custom/Chat/ChatClient.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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());
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>

src/Custom/Responses/OpenAIResponseClient.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,10 @@ public virtual Task<ClientResult<OpenAIResponse>> CreateResponseAsync(IEnumerabl
124124
return CreateResponseAsync(inputItems, options, cancellationToken.ToRequestOptions());
125125
}
126126

127-
public virtual async Task<ClientResult<OpenAIResponse>> CreateResponseAsync(IEnumerable<ResponseItem> inputItems, ResponseCreationOptions options, RequestOptions requestOptions)
127+
internal async Task<ClientResult<OpenAIResponse>> CreateResponseAsync(IEnumerable<ResponseItem> inputItems, ResponseCreationOptions options, RequestOptions requestOptions)
128128
{
129129
Argument.AssertNotNullOrEmpty(inputItems, nameof(inputItems));
130130
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
131-
132131
if (requestOptions.BufferResponse is false)
133132
{
134133
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'true' when calling 'CreateResponseAsync'.");
@@ -176,11 +175,10 @@ public virtual AsyncCollectionResult<StreamingResponseUpdate> CreateResponseStre
176175
return CreateResponseStreamingAsync(inputItems, options, cancellationToken.ToRequestOptions(streaming: true));
177176
}
178177

179-
public virtual AsyncCollectionResult<StreamingResponseUpdate> CreateResponseStreamingAsync(IEnumerable<ResponseItem> inputItems, ResponseCreationOptions options, RequestOptions requestOptions)
178+
internal AsyncCollectionResult<StreamingResponseUpdate> CreateResponseStreamingAsync(IEnumerable<ResponseItem> inputItems, ResponseCreationOptions options, RequestOptions requestOptions)
180179
{
181180
Argument.AssertNotNullOrEmpty(inputItems, nameof(inputItems));
182181
Argument.AssertNotNull(requestOptions, nameof(requestOptions));
183-
184182
if (requestOptions.BufferResponse is true)
185183
{
186184
throw new InvalidOperationException("'requestOptions.BufferResponse' must be 'false' when calling 'CreateResponseStreamingAsync'.");

0 commit comments

Comments
 (0)