Browse Source

Remove ChatClientWithTools due it's already possible by configuring default ME I

pull/23533/head
enisn 5 months ago
parent
commit
9bea4fa503
No known key found for this signature in database GPG Key ID: A052619F04155D1C
  1. 73
      framework/src/Volo.Abp.AI.Abstractions/Volo/Abp/AI/Delegates/ChatClientWithTools.cs
  2. 21
      framework/src/Volo.Abp.AI/Volo/Abp/AI/Extensions/ChatClientWithToolsExtensions.cs

73
framework/src/Volo.Abp.AI.Abstractions/Volo/Abp/AI/Delegates/ChatClientWithTools.cs

@ -1,73 +0,0 @@
using System;
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 ChatClientWithTools : DelegatingChatClient
{
public IList<AIFunction> Tools { get; private set; }
public ChatToolMode? ToolMode { get; private set; }
public bool? AllowMultipleToolCalls { get; private set; }
public ChatClientWithTools(IChatClient innerClient, IEnumerable<AIFunction> tools, ChatToolMode? toolMode = null, bool? allowMultipleToolCalls = null)
: base(innerClient)
{
Tools = tools.ToList();
ToolMode = toolMode;
AllowMultipleToolCalls = allowMultipleToolCalls;
}
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)
{
options ??= new ChatOptions();
options.Tools ??= new List<AITool>();
foreach (var tool in Tools)
{
options.Tools.Add(tool);
}
if (ToolMode is not null)
{
options.ToolMode = ToolMode;
}
if (AllowMultipleToolCalls is not null)
{
options.AllowMultipleToolCalls = AllowMultipleToolCalls.Value;
}
return options;
}
}

21
framework/src/Volo.Abp.AI/Volo/Abp/AI/Extensions/ChatClientWithToolsExtensions.cs

@ -1,21 +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 ChatClientWithToolsExtensions
{
public static ChatClientBuilder UseTools(
this ChatClientBuilder builder,
IEnumerable<AIFunction> tools,
ChatToolMode? toolMode = null,
bool? allowMultipleToolCalls = null)
{
return builder.Use(chatClient
=> new ChatClientWithTools(chatClient, tools, toolMode, allowMultipleToolCalls));
}
}
Loading…
Cancel
Save