Class ChatEndpoint
Given a chat conversation, the model will return a chat completion response.
https://platform.openai.com/docs/api-reference/chat
public sealed class ChatEndpoint : OpenAIBaseEndpoint
- Inheritance
-
ChatEndpoint
- Inherited Members
Constructors
ChatEndpoint(OpenAIClient)
public ChatEndpoint(OpenAIClient client)
Parameters
client
OpenAIClient
Properties
IsAzureDeployment
Indicates if the endpoint has an Azure Deployment.
protected override bool? IsAzureDeployment { get; }
Property Value
- bool?
Remarks
If the endpoint is an Azure deployment, is true. If it is not an Azure deployment, is false. If it is not an Azure supported Endpoint, is null.
Root
The root endpoint address.
protected override string Root { get; }
Property Value
Methods
GetCompletionAsync(ChatRequest, CancellationToken)
Creates a completion for the chat message.
public Task<ChatResponse> GetCompletionAsync(ChatRequest chatRequest, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
GetCompletionAsync<T>(ChatRequest, CancellationToken)
Creates a completion for the chat message.
public Task<(T, ChatResponse)> GetCompletionAsync<T>(ChatRequest chatRequest, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
- Task<(T, ChatResponse)>
Type Parameters
T
JsonSchema to use for structured outputs.
StreamCompletionAsync(ChatRequest, Action<ChatResponse>, bool, CancellationToken)
Created a completion for the chat message and stream the results to the resultHandler
as they come in.
public Task<ChatResponse> StreamCompletionAsync(ChatRequest chatRequest, Action<ChatResponse> resultHandler, bool streamUsage = false, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
resultHandler
Action<ChatResponse>A Action<T> to be invoked as each new result arrives.
streamUsage
boolOptional, If set, an additional chunk will be streamed before the 'data: [DONE]' message. The 'usage' field on this chunk shows the token usage statistics for the entire request, and the 'choices' field will always be an empty array. All other chunks will also include a 'usage' field, but with a null value.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
StreamCompletionAsync(ChatRequest, Func<ChatResponse, Task>, bool, CancellationToken)
Created a completion for the chat message and stream the results to the resultHandler
as they come in.
public Task<ChatResponse> StreamCompletionAsync(ChatRequest chatRequest, Func<ChatResponse, Task> resultHandler, bool streamUsage = false, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
resultHandler
Func<ChatResponse, Task>A Func<T, TResult> to to be invoked as each new result arrives.
streamUsage
boolOptional, If set, an additional chunk will be streamed before the 'data: [DONE]' message. The 'usage' field on this chunk shows the token usage statistics for the entire request, and the 'choices' field will always be an empty array. All other chunks will also include a 'usage' field, but with a null value.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
StreamCompletionAsync<T>(ChatRequest, Action<ChatResponse>, bool, CancellationToken)
Created a completion for the chat message and stream the results to the resultHandler
as they come in.
public Task<(T, ChatResponse)> StreamCompletionAsync<T>(ChatRequest chatRequest, Action<ChatResponse> resultHandler, bool streamUsage = false, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
resultHandler
Action<ChatResponse>A Action<T> to be invoked as each new result arrives.
streamUsage
boolOptional, If set, an additional chunk will be streamed before the 'data: [DONE]' message. The 'usage' field on this chunk shows the token usage statistics for the entire request, and the 'choices' field will always be an empty array. All other chunks will also include a 'usage' field, but with a null value.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
- Task<(T, ChatResponse)>
Type Parameters
T
JsonSchema to use for structured outputs.
StreamCompletionAsync<T>(ChatRequest, Func<ChatResponse, Task>, bool, CancellationToken)
Created a completion for the chat message and stream the results to the resultHandler
as they come in.
public Task<(T, ChatResponse)> StreamCompletionAsync<T>(ChatRequest chatRequest, Func<ChatResponse, Task> resultHandler, bool streamUsage = false, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
resultHandler
Func<ChatResponse, Task>A Func<T, TResult> to to be invoked as each new result arrives.
streamUsage
boolOptional, If set, an additional chunk will be streamed before the 'data: [DONE]' message. The 'usage' field on this chunk shows the token usage statistics for the entire request, and the 'choices' field will always be an empty array. All other chunks will also include a 'usage' field, but with a null value.
cancellationToken
CancellationTokenOptional, CancellationToken.
Returns
- Task<(T, ChatResponse)>
Type Parameters
T
JsonSchema to use for structured outputs.
StreamCompletionEnumerableAsync(ChatRequest, bool, CancellationToken)
Created a completion for the chat message and stream the results as they come in.
If you are not using C# 8 supporting IAsyncEnumerable{T} or if you are using the .NET Framework,
you may need to use StreamCompletionAsync(ChatRequest, Action<ChatResponse>, bool, CancellationToken) instead.
public IAsyncEnumerable<ChatResponse> StreamCompletionEnumerableAsync(ChatRequest chatRequest, bool streamUsage = false, CancellationToken cancellationToken = default)
Parameters
chatRequest
ChatRequestThe chat request which contains the message content.
streamUsage
boolOptional, If set, an additional chunk will be streamed before the 'data: [DONE]' message. The 'usage' field on this chunk shows the token usage statistics for the entire request, and the 'choices' field will always be an empty array. All other chunks will also include a 'usage' field, but with a null value.
cancellationToken
CancellationTokenOptional, CancellationToken.