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
strictModeboolIf 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
contextMiddlewareContextagentIAgentcancellationTokenCancellationToken
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
contextMiddlewareContextagentIStreamingAgentcancellationTokenCancellationToken
Returns
PostProcessMessage(IMessage)
public IMessage PostProcessMessage(IMessage message)
Parameters
messageIMessage
Returns
PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate>, string?)
public IMessage? PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate> update, string? currentToolName)
Parameters
updateIMessage<StreamingChatCompletionsUpdate>currentToolNamestring
Returns
ProcessIncomingMessages(IAgent, IEnumerable<IMessage>)
public IEnumerable<IMessage> ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages)
Parameters
agentIAgentmessagesIEnumerable<IMessage>