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
openAIClient
OpenAIClientopenai client
name
stringagent name
options
ChatCompletionsOptionschat completion option. The option can't contain messages
systemMessage
stringsystem 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
openAIClient
OpenAIClientopenai client
name
stringagent name
modelName
stringmodel name. e.g. gpt-turbo-3.5
systemMessage
stringsystem message
temperature
floattemperature
maxTokens
intmax tokens to generated
seed
int?seed to use, set it to enable deterministic output
responseFormat
ChatCompletionsResponseFormatresponse format, set it to JsonObject to enable json mode.
functions
IEnumerable<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
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