Table of Contents

Class OpenAIChatRequestMessageConnector

Namespace
AutoGen.OpenAI.V1
Assembly
AutoGen.OpenAI.V1.dll

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

- TextMessage

- ImageMessage

- MultiModalMessage

- ToolCallMessage

- ToolCallResultMessage

- 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 bool

If 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

string

Methods

InvokeAsync(MiddlewareContext, IAgent, CancellationToken)

The method to invoke the middleware

public Task<IMessage> InvokeAsync(MiddlewareContext context, IAgent agent, CancellationToken cancellationToken = default)

Parameters

context MiddlewareContext
agent IAgent
cancellationToken CancellationToken

Returns

Task<IMessage>

InvokeAsync(MiddlewareContext, IStreamingAgent, CancellationToken)

public IAsyncEnumerable<IMessage> InvokeAsync(MiddlewareContext context, IStreamingAgent agent, CancellationToken cancellationToken = default)

Parameters

context MiddlewareContext
agent IStreamingAgent
cancellationToken CancellationToken

Returns

IAsyncEnumerable<IMessage>

PostProcessMessage(IMessage)

public IMessage PostProcessMessage(IMessage message)

Parameters

message IMessage

Returns

IMessage

PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate>, string?)

public IMessage? PostProcessStreamingMessage(IMessage<StreamingChatCompletionsUpdate> update, string? currentToolName)

Parameters

update IMessage<StreamingChatCompletionsUpdate>
currentToolName string

Returns

IMessage

ProcessIncomingMessages(IAgent, IEnumerable<IMessage>)

public IEnumerable<IMessage> ProcessIncomingMessages(IAgent agent, IEnumerable<IMessage> messages)

Parameters

agent IAgent
messages IEnumerable<IMessage>

Returns

IEnumerable<IMessage>