mirror of https://github.com/abpframework/abp.git
2 changed files with 0 additions and 94 deletions
@ -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; |
|
||||
} |
|
||||
} |
|
||||
@ -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…
Reference in new issue