Class OpenAIChatAgent
OpenAI client agent. This agent is a thin wrapper around OpenAI.OpenAIClient to provide a simple interface for chat completions.
OpenAIChatAgent supports the following message types:
- MessageEnvelope<T> where T is OpenAI.Chat.ChatMessage: chat message.
OpenAIChatAgent returns the following message types:
- MessageEnvelope<T> where T is OpenAI.Chat.ChatCompletion: chat response message. MessageEnvelope<T> where T is OpenAI.Chat.StreamingChatCompletionUpdate: streaming chat completions update.
public class OpenAIChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
- Inheritance
-
OpenAIChatAgent
- Implements
- Inherited Members
- Extension Methods
Constructors
OpenAIChatAgent(ChatClient, string, ChatCompletionOptions, string?)
Create a new instance of OpenAIChatAgent.
public OpenAIChatAgent(ChatClient chatClient, string name, ChatCompletionOptions options, string? systemMessage = "You are a helpful AI assistant")
Parameters
chatClient
ChatClientopenai chat client
name
stringagent name
options
ChatCompletionOptionschat completion option. The option can't contain messages
systemMessage
stringsystem message
OpenAIChatAgent(ChatClient, string, string?, float?, int?, int?, ChatResponseFormat?, IEnumerable<ChatTool>?)
Create a new instance of OpenAIChatAgent.
public OpenAIChatAgent(ChatClient chatClient, string name, string? systemMessage = "You are a helpful AI assistant", float? temperature = null, int? maxTokens = null, int? seed = null, ChatResponseFormat? responseFormat = null, IEnumerable<ChatTool>? functions = null)
Parameters
chatClient
ChatClientopenai client
name
stringagent name
systemMessage
stringsystem message
temperature
float?temperature
maxTokens
int?max tokens to generated
seed
int?seed to use, set it to enable deterministic output
responseFormat
ChatResponseFormatresponse format, set it to OpenAI.Chat.ChatResponseFormat.JsonObject to enable json mode.
functions
IEnumerable<ChatTool>functions
Properties
Name
public string Name { get; }
Property Value
Methods
GenerateReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
Generate reply
public Task<IMessage> GenerateReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages
IEnumerable<IMessage>conversation history
options
GenerateReplyOptionscompletion option. If provided, it should override existing option if there's any
cancellationToken
CancellationToken
Returns
GenerateStreamingReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
public IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messages
IEnumerable<IMessage>options
GenerateReplyOptionscancellationToken
CancellationToken