语言

SemanticRoutingChatClient 类

定义

通过语义上的相似性路由请求,以应用提供的示例话语。

public ref class SemanticRoutingChatClient sealed : Microsoft::Extensions::AI::RoutingChatClient
[System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")]
public sealed class SemanticRoutingChatClient : Microsoft.Extensions.AI.RoutingChatClient
public sealed class SemanticRoutingChatClient : Microsoft.Extensions.AI.RoutingChatClient
[<System.Diagnostics.CodeAnalysis.Experimental("MEAI001", UrlFormat="https://aka.ms/dotnet-extensions-warnings/{0}")>]
type SemanticRoutingChatClient = class
    inherit RoutingChatClient
type SemanticRoutingChatClient = class
    inherit RoutingChatClient
Public NotInheritable Class SemanticRoutingChatClient
Inherits RoutingChatClient
继承
SemanticRoutingChatClient
属性

注解

配置文件嵌入在延迟和缓存中生成。 每个请求嵌入最后一条用户消息,并在聚合最佳匹配配置文件话语的余弦相似性后,选择得分最高的客户端。 如果未提供任何用户消息或最高分数低于配置的阈值,则会选择配置的默认客户端。

配置的客户端实例用作稳定的路由标识,并按引用进行区分。 按呼叫选项不参与该标识。 默认情况下,此实例拥有客户端并嵌入生成器,并在释放时释放它们。

示例言语路由方法灵感来自 Aurelio Labs 的语义路由器项目。

构造函数

名称 说明
SemanticRoutingChatClient(IEmbeddingGenerator<String,Embedding<Single>>, IReadOnlyDictionary<IChatClient,IReadOnlyList<String>>, IChatClient, Single, Int32, SemanticRoutingChatClient+ScoreAggregation, Boolean)

初始化 SemanticRoutingChatClient 类的新实例。

方法

名称 说明
Dispose()

执行与释放、释放或重置非托管资源关联的应用程序定义任务。

(继承自 RoutingChatClient)
Dispose(Boolean)

提供一种机制,用于释放派生实例拥有的资源。

(继承自 RoutingChatClient)
GetResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)

发送聊天消息并返回响应。

(继承自 RoutingChatClient)
GetService(Type, Object)

IChatClient请求指定类型的serviceType对象。

(继承自 RoutingChatClient)
GetStreamingResponseAsync(IEnumerable<ChatMessage>, ChatOptions, CancellationToken)

发送聊天消息并流式传输响应。

(继承自 RoutingChatClient)
SelectClientAsync(RoutingContext, CancellationToken)

选择要为请求调用的客户端。

(继承自 RoutingChatClient)

扩展方法

名称 说明
AsBuilder(IChatClient)

创建一个新的 ChatClientBuilder 使用 innerClient 作为其内部客户端。

GetRequiredService(IChatClient, Type, Object)

IChatClient请求指定类型的serviceType对象,如果一个对象不可用,则会引发异常。

GetRequiredService<TService>(IChatClient, Object)

IChatClient询问类型的TService对象,如果对象不可用,则会引发异常。

GetResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

发送聊天消息并返回响应消息。

GetResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

发送用户聊天短信并返回响应消息。

GetResponseAsync<T>(IChatClient, ChatMessage, ChatOptions, Nullable<Boolean>, CancellationToken)

发送聊天消息,请求与类型 T匹配的响应。

GetResponseAsync<T>(IChatClient, ChatMessage, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

发送聊天消息,请求与类型 T匹配的响应。

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, ChatOptions, Nullable<Boolean>, CancellationToken)

发送聊天消息,请求与类型 T匹配的响应。

GetResponseAsync<T>(IChatClient, IEnumerable<ChatMessage>, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

发送聊天消息,请求与类型 T匹配的响应。

GetResponseAsync<T>(IChatClient, String, ChatOptions, Nullable<Boolean>, CancellationToken)

发送用户聊天短信,请求与类型 T匹配的响应。

GetResponseAsync<T>(IChatClient, String, JsonSerializerOptions, ChatOptions, Nullable<Boolean>, CancellationToken)

发送用户聊天短信,请求与类型 T匹配的响应。

GetService<TService>(IChatClient, Object)

IChatClient请求类型的对象TService。

GetStreamingResponseAsync(IChatClient, ChatMessage, ChatOptions, CancellationToken)

发送聊天消息并流式传输响应消息。

GetStreamingResponseAsync(IChatClient, String, ChatOptions, CancellationToken)

发送用户聊天短信并流式传输响应消息。

适用于