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
chatClientChatClientopenai chat client
namestringagent name
optionsChatCompletionOptionschat completion option. The option can't contain messages
systemMessagestringsystem 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
chatClientChatClientopenai client
namestringagent name
systemMessagestringsystem message
temperaturefloat?temperature
maxTokensint?max tokens to generated
seedint?seed to use, set it to enable deterministic output
responseFormatChatResponseFormatresponse format, set it to OpenAI.Chat.ChatResponseFormat to enable json mode.
functionsIEnumerable<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
messagesIEnumerable<IMessage>conversation history
optionsGenerateReplyOptionscompletion option. If provided, it should override existing option if there's any
cancellationTokenCancellationToken
Returns
GenerateStreamingReplyAsync(IEnumerable<IMessage>, GenerateReplyOptions?, CancellationToken)
public IAsyncEnumerable<IMessage> GenerateStreamingReplyAsync(IEnumerable<IMessage> messages, GenerateReplyOptions? options = null, CancellationToken cancellationToken = default)
Parameters
messagesIEnumerable<IMessage>optionsGenerateReplyOptionscancellationTokenCancellationToken