mirror of https://github.com/abpframework/abp.git
Browse Source
Replaces separate ChatClient and Kernel configuration dictionaries with a unified WorkspaceConfigurationDictionary. Removes related collection classes and extensions, updates service registration logic, and renames IKernel to IKernelAccessor. This change simplifies configuration and improves extensibility for managing multiple AI workspaces.pull/23533/head
8 changed files with 59 additions and 174 deletions
@ -1,56 +0,0 @@ |
|||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.Extensions.AI; |
|
||||
|
|
||||
namespace Volo.Abp.AI.Delegates; |
|
||||
|
|
||||
public class ChatClientWithTemperature : DelegatingChatClient |
|
||||
{ |
|
||||
private readonly float _temperature; |
|
||||
|
|
||||
public ChatClientWithTemperature(IChatClient innerClient, float temperature) |
|
||||
: base(innerClient) |
|
||||
{ |
|
||||
_temperature = temperature; |
|
||||
} |
|
||||
|
|
||||
public override Task<ChatResponse> GetResponseAsync( |
|
||||
IEnumerable<ChatMessage> messages, |
|
||||
ChatOptions? options = null, |
|
||||
CancellationToken cancellationToken = default) |
|
||||
{ |
|
||||
return base.GetResponseAsync( |
|
||||
messages, |
|
||||
BuildChatOptions(options), |
|
||||
cancellationToken |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync( |
|
||||
IEnumerable<ChatMessage> messages, |
|
||||
ChatOptions? options = null, |
|
||||
CancellationToken cancellationToken = default) |
|
||||
{ |
|
||||
return base.GetStreamingResponseAsync( |
|
||||
messages, |
|
||||
BuildChatOptions(options), |
|
||||
cancellationToken |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
private ChatOptions BuildChatOptions(ChatOptions? options) |
|
||||
{ |
|
||||
if (options?.Temperature != null) |
|
||||
{ |
|
||||
return options; |
|
||||
} |
|
||||
|
|
||||
options ??= new ChatOptions(); |
|
||||
|
|
||||
options.Temperature ??= _temperature; |
|
||||
|
|
||||
return options; |
|
||||
} |
|
||||
} |
|
||||
@ -1,37 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace Volo.Abp.AI; |
|
||||
|
|
||||
public class ChatClientConfigurationDictionary : Dictionary<string, ChatClientConfiguration> |
|
||||
{ |
|
||||
public static string DefaultChatClientName => "Default"; |
|
||||
|
|
||||
// TODO: Consider to rename to Configure only.
|
|
||||
public void ConfigureDefault(Action<ChatClientConfiguration> configureAction) => |
|
||||
Configure(DefaultChatClientName, configureAction); |
|
||||
|
|
||||
public void Configure<T>(Action<ChatClientConfiguration> configureAction) |
|
||||
{ |
|
||||
Configure(typeof(T), configureAction); |
|
||||
} |
|
||||
|
|
||||
public void Configure(Type chatClientType, Action<ChatClientConfiguration> configureAction) |
|
||||
{ |
|
||||
Configure( |
|
||||
WorkspaceNameAttribute.GetWorkspaceName(chatClientType), |
|
||||
configureAction |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public void Configure(string name, Action<ChatClientConfiguration> configureAction) |
|
||||
{ |
|
||||
if (!this.TryGetValue(name, out var configuration)) |
|
||||
{ |
|
||||
configuration = new ChatClientConfiguration(name); |
|
||||
this[name] = configuration; |
|
||||
} |
|
||||
|
|
||||
configureAction(configuration); |
|
||||
} |
|
||||
} |
|
||||
@ -1,16 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.Extensions.AI; |
|
||||
using Volo.Abp.AI.Delegates; |
|
||||
|
|
||||
namespace Volo.Abp.AI.Extensions; |
|
||||
|
|
||||
public static class ChatClientWithTemperatureExtensions |
|
||||
{ |
|
||||
public static ChatClientBuilder UseTemperature(this ChatClientBuilder builder, float temperature) |
|
||||
{ |
|
||||
return builder.Use(chatClient => new ChatClientWithTemperature(chatClient, temperature)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,38 +0,0 @@ |
|||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
|
|
||||
namespace Volo.Abp.AI; |
|
||||
|
|
||||
public class KernelConfigurationDictionary : Dictionary<string, KernelConfiguration> |
|
||||
{ |
|
||||
public static string DefaultKernelName => "Default"; |
|
||||
|
|
||||
public void ConfigureDefault(Action<KernelConfiguration> configureAction) => |
|
||||
Configure(DefaultKernelName, configureAction); |
|
||||
|
|
||||
public void Configure<TWorkSpace>(Action<KernelConfiguration> configureAction) |
|
||||
{ |
|
||||
Configure(typeof(TWorkSpace), configureAction); |
|
||||
} |
|
||||
|
|
||||
public void Configure(Type workspaceType, Action<KernelConfiguration> configureAction) |
|
||||
{ |
|
||||
Configure( |
|
||||
WorkspaceNameAttribute.GetWorkspaceName(workspaceType), |
|
||||
configureAction |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
public void Configure(string name, Action<KernelConfiguration> configureAction) |
|
||||
{ |
|
||||
if (!TryGetValue(name, out var configuration)) |
|
||||
{ |
|
||||
configuration = new KernelConfiguration(name); |
|
||||
this[name] = configuration; |
|
||||
} |
|
||||
|
|
||||
configureAction(configuration); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
Loading…
Reference in new issue