Class OpenAIChatRequestMessageConnector
This middleware converts the incoming IMessage to IMessage<T> where T is ChatRequestMessage before sending to agent. And converts the output ChatResponseMessage to IMessage after receiving from agent.
Supported IMessage are
- IMessage<T> where T is ChatRequestMessage
- AggregateMessage<TMessage1, TMessage2> where TMessage1 is ToolCallMessage and TMessage2 is ToolCallResultMessage
public class OpenAIChatRequestMessageConnector : IStreamingMiddleware, IMiddleware
- Inheritance
-
OpenAIChatRequestMessageConnector
- Implements
- Inherited Members
Constructors
OpenAIChatRequestMessageConnector(bool)
Create a new instance of OpenAIChatRequestMessageConnector.
public OpenAIChatRequestMessageConnector(bool strictMode = false)
Parameters
strictMode
boolIf true, OpenAIChatRequestMessageConnector will throw an InvalidOperationException When the message type is not supported. If false, it will ignore the unsupported message type.
Properties
Name
the name of the middleware
public string? Name { get; }
Property Value
Methods
InvokeAsync(MiddlewareContext, IAgent, CancellationToken)
The method to invoke the middleware
public Task<IMessage> InvokeAsync(MiddlewareContext context, IAgent agent, CancellationToken cancellationToken = default)
Parameters
context
MiddlewareContextagent
IAgentcancellationToken
CancellationToken
Returns
InvokeAsync(MiddlewareContext, IStreamingAgent, CancellationToken)
The streaming version of InvokeAsync(MiddlewareContext, IAgent, CancellationToken).
public IAsyncEnumerable<IMessage> InvokeAsync(MiddlewareContext context, IStreamingAgent agent, CancellationToken cancellationToken = default)
Parameters
context
MiddlewareContextagent
IStreamingAgentcancellationToken
CancellationToken
Returns
PostProcessMessage(IMessage)
public IMessage PostProcessMessage(IMessage message)
Parameters
message
IMessage
Returns
PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate>, string?)
public IMessage? PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate> update, string? currentToolName)
Parameters
update
IMessage<StreamingChatCompletionsUpdate>currentToolName
string
Returns
ProcessIncomingMessages(IAgent, IEnumerable<IMessage>)
public IEnumerable<IMessage> ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages)
Parameters
agent
IAgentmessages
IEnumerable<IMessage>