commit
9fa062106a
|
|
@ -2,6 +2,6 @@ namespace BotSharp.Abstraction.Agents.Enums;
|
|||
|
||||
public class AgentUtility
|
||||
{
|
||||
public const string FileAnalyzer = "file-analyzer";
|
||||
public const string FileReader = "file-reader";
|
||||
public const string ImageGenerator = "image-generator";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@
|
|||
<ItemGroup>
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\agent.json" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\functions\generate_image.json" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\functions\read_file.json" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\instruction.liquid" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\functions\load_attachment.json" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\templates\generate_image.fn.liquid" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\templates\load_attachment.fn.liquid" />
|
||||
<None Remove="data\agents\00000000-0000-0000-0000-000000000000\templates\read_file.fn.liquid" />
|
||||
<None Remove="data\agents\01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b\agent.json" />
|
||||
<None Remove="data\agents\01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b\functions.json" />
|
||||
<None Remove="data\agents\01dcc3e5-0af7-49e6-ad7a-a760bd12dc4b\functions\human_intervention_needed.json" />
|
||||
|
|
@ -159,10 +159,10 @@
|
|||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\instruction.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\functions\load_attachment.json">
|
||||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\functions\read_file.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\templates\load_attachment.fn.liquid">
|
||||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\templates\read_file.fn.liquid">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="data\agents\00000000-0000-0000-0000-000000000000\functions\generate_image.json">
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public partial class ConversationService
|
|||
|
||||
var content = $"Received [{agent.Name}] {message.Role}: {message.Content}";
|
||||
#if DEBUG
|
||||
Console.WriteLine(content, Color.GreenYellow);
|
||||
Console.WriteLine(content);
|
||||
#else
|
||||
_logger.LogInformation(content);
|
||||
#endif
|
||||
|
|
@ -103,7 +103,7 @@ public partial class ConversationService
|
|||
response.Role = AgentRole.Assistant;
|
||||
var text = $"Sending [{agentName}] {response.Role}: {response.Content}";
|
||||
#if DEBUG
|
||||
Console.WriteLine(text, Color.Yellow);
|
||||
Console.WriteLine(text);
|
||||
#else
|
||||
_logger.LogInformation(text);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ public class TokenStatistics : ITokenStatistics
|
|||
}
|
||||
var stats = $"Token Usage: {_promptTokenCount} prompt + {_completionTokenCount} completion = {Total} total tokens ({_timer.ElapsedMilliseconds / 1000f:f2}s). One-Way cost: {Cost:C4}, accumulated cost: {AccumulatedCost:C4}. [{_model}]";
|
||||
#if DEBUG
|
||||
Console.WriteLine(stats, Color.DarkGray);
|
||||
Console.WriteLine(stats);
|
||||
#else
|
||||
_logger.LogInformation(stats);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ public class FilePlugin : IBotSharpPlugin
|
|||
{
|
||||
services.AddScoped<IBotSharpFileService, BotSharpFileService>();
|
||||
|
||||
services.AddScoped<IAgentHook, FileAnalyzerHook>();
|
||||
services.AddScoped<IAgentUtilityHook, FileAnalyzerUtilityHook>();
|
||||
services.AddScoped<IAgentHook, FileReaderHook>();
|
||||
services.AddScoped<IAgentUtilityHook, FileReaderUtilityHook>();
|
||||
services.AddScoped<IAgentHook, ImageGeneratorHook>();
|
||||
services.AddScoped<IAgentUtilityHook, ImageGeneratorUtilityHook>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,20 +3,20 @@ using BotSharp.Abstraction.MLTasks;
|
|||
|
||||
namespace BotSharp.Core.Files.Functions;
|
||||
|
||||
public class LoadAttachmentFn : IFunctionCallback
|
||||
public class ReadFileFn : IFunctionCallback
|
||||
{
|
||||
public string Name => "load_attachment";
|
||||
public string Indication => "Analyzing files";
|
||||
public string Name => "read_file";
|
||||
public string Indication => "Reading files";
|
||||
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger<LoadAttachmentFn> _logger;
|
||||
private readonly ILogger<ReadFileFn> _logger;
|
||||
private readonly IEnumerable<string> _imageTypes = new List<string> { "image", "images", "png", "jpg", "jpeg" };
|
||||
private readonly IEnumerable<string> _pdfTypes = new List<string> { "pdf" };
|
||||
private static string UTILITY_ASSISTANT = Guid.Empty.ToString();
|
||||
|
||||
public LoadAttachmentFn(
|
||||
public ReadFileFn(
|
||||
IServiceProvider services,
|
||||
ILogger<LoadAttachmentFn> logger)
|
||||
ILogger<ReadFileFn> logger)
|
||||
{
|
||||
_services = services;
|
||||
_logger = logger;
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
namespace BotSharp.Core.Files.Hooks;
|
||||
|
||||
public class FileAnalyzerHook : AgentHookBase
|
||||
public class FileReaderHook : AgentHookBase
|
||||
{
|
||||
private static string UTILITY_ASSISTANT = Guid.Empty.ToString();
|
||||
private static string FUNCTION_NAME = "load_attachment";
|
||||
private static string FUNCTION_NAME = "read_file";
|
||||
|
||||
public override string SelfId => string.Empty;
|
||||
|
||||
public FileAnalyzerHook(IServiceProvider services, AgentSettings settings)
|
||||
public FileReaderHook(IServiceProvider services, AgentSettings settings)
|
||||
: base(services, settings)
|
||||
{
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ public class FileAnalyzerHook : AgentHookBase
|
|||
{
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
var isConvMode = conv.IsConversationMode();
|
||||
var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(AgentUtility.FileAnalyzer);
|
||||
var isEnabled = !agent.Utilities.IsNullOrEmpty() && agent.Utilities.Contains(AgentUtility.FileReader);
|
||||
|
||||
if (isConvMode && isEnabled)
|
||||
{
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
namespace BotSharp.Core.Files.Hooks;
|
||||
|
||||
public class FileAnalyzerUtilityHook : IAgentUtilityHook
|
||||
public class FileReaderUtilityHook : IAgentUtilityHook
|
||||
{
|
||||
public void AddUtilities(List<string> utilities)
|
||||
{
|
||||
utilities.Add(AgentUtility.FileAnalyzer);
|
||||
utilities.Add(AgentUtility.FileReader);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "load_attachment",
|
||||
"name": "read_file",
|
||||
"description": "If the user's request is related to analyzing files and/or images, you can call this function to analyze files and images.",
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
|
|
@ -1 +0,0 @@
|
|||
Please call load_attachment if user wants to describe files, such as images, pdf.
|
||||
|
|
@ -0,0 +1 @@
|
|||
Please call read_file if user wants to describe files, such as images, pdf.
|
||||
|
|
@ -62,10 +62,12 @@ public class TextEmbeddingProvider : ITextEmbedding
|
|||
{
|
||||
var state = _services.GetRequiredService<IConversationStateService>();
|
||||
var stateDimension = state.GetState("embedding_dimension");
|
||||
var defaultDimension = Dimension > 0 ? Dimension : DEFAULT_DIMENSION;
|
||||
|
||||
if (int.TryParse(stateDimension, out var dimension))
|
||||
{
|
||||
return dimension > 0 ? dimension :(Dimension > 0 ? Dimension: DEFAULT_DIMENSION);
|
||||
return dimension > 0 ? dimension : defaultDimension;
|
||||
}
|
||||
return Dimension > 0 ? Dimension : DEFAULT_DIMENSION;
|
||||
return defaultDimension;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ public class ImageGenerationProvider : IImageGeneration
|
|||
GeneratedImageStyle retStyle;
|
||||
switch (value)
|
||||
{
|
||||
case "standard":
|
||||
case "natural":
|
||||
retStyle = GeneratedImageStyle.Natural;
|
||||
break;
|
||||
case "vivid":
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@ using Microsoft.Extensions.Logging;
|
|||
|
||||
namespace BotSharp.Plugin.HttpHandler.Functions;
|
||||
|
||||
public class HandleHttpRequest : IFunctionCallback
|
||||
public class HandleHttpRequestFn : IFunctionCallback
|
||||
{
|
||||
public string Name => "handle_http_request";
|
||||
public string Indication => "Handling http request";
|
||||
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly ILogger<HandleHttpRequest> _logger;
|
||||
private readonly ILogger<HandleHttpRequestFn> _logger;
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
private readonly IHttpContextAccessor _context;
|
||||
private readonly BotSharpOptions _options;
|
||||
|
||||
public HandleHttpRequest(IServiceProvider services,
|
||||
ILogger<HandleHttpRequest> logger,
|
||||
public HandleHttpRequestFn(IServiceProvider services,
|
||||
ILogger<HandleHttpRequestFn> logger,
|
||||
IHttpClientFactory httpClientFactory,
|
||||
IHttpContextAccessor context,
|
||||
BotSharpOptions options)
|
||||
|
|
@ -41,14 +41,16 @@ public class HandleHttpRequest : IFunctionCallback
|
|||
var response = await SendHttpRequest(url, method, content);
|
||||
var responseContent = await HandleHttpResponse(response);
|
||||
message.RichContent = BuildRichContent(responseContent);
|
||||
return await Task.FromResult(true);
|
||||
message.StopCompletion = true;
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var msg = $"Fail when sending http request. Url: {url}, method: {method}, content: {content}";
|
||||
_logger.LogWarning($"{msg}\n(Error: {ex.Message})");
|
||||
message.RichContent = BuildRichContent($"{msg}");
|
||||
return await Task.FromResult(false);
|
||||
message.StopCompletion = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue