Class OpenAIChatAgent
OpenAI client agent. This agent is a thin wrapper around OpenAIClient to provide a simple interface for chat completions. To better work with other agents, it's recommended to use GPTAgent which supports more message types and have a better compatibility with other agents.
OpenAIChatAgent supports the following message types:
- MessageEnvelope<T> where T is ChatRequestMessage: chat request message.
OpenAIChatAgent returns the following message types:
- MessageEnvelope<T> where T is ChatResponseMessage: chat response message. MessageEnvelope<T> where T is StreamingChatCompletionsUpdate: streaming chat completions update.
public class OpenAIChatAgent : IStreamingAgent, IAgent, IAgentMetaInformation
- Inheritance
-
OpenAIChatAgent
- Implements
- Inherited Members
- Extension Methods
Constructors
OpenAIChatAgent(OpenAIClient, string, ChatCompletionsOptions, string)
Create a new instance of OpenAIChatAgent.
public OpenAIChatAgent(OpenAIClient openAIClient, string name, ChatCompletionsOptions options, string systemMessage = "You are a helpful AI assistant")
Parameters
openAIClientOpenAIClientopenai client
namestringagent name
optionsChatCompletionsOptionschat completion option. The option can't contain messages
systemMessagestringsystem message
OpenAIChatAgent(OpenAIClient, string, string, string, float, int, int?, ChatCompletionsResponseFormat?, IEnumerable<FunctionDefinition>?)
Create a new instance of OpenAIChatAgent.
public OpenAIChatAgent(OpenAIClient openAIClient, string name, string modelName, string systemMessage = "You are a helpful AI assistant", float temperature = 0.7, int maxTokens = 1024, int? seed = null, ChatCompletionsResponseFormat? responseFormat = null, IEnumerable<FunctionDefinition>? functions = null)
Parameters
openAIClientOpenAIClientopenai client
namestringagent name
modelNamestringmodel name. e.g. gpt-turbo-3.5
systemMessagestringsystem message
temperaturefloattemperature
maxTokensintmax tokens to generated
seedint?seed to use, set it to enable deterministic output
responseFormatChatCompletionsResponseFormatresponse format, set it to JsonObject to enable json mode.
functionsIEnumerable<FunctionDefinition>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