refine load attachment
This commit is contained in:
parent
1b89a267ea
commit
ff5a553296
|
|
@ -31,7 +31,7 @@ public class LoadAttachmentFn : IFunctionCallback
|
|||
var wholeDialogs = conv.GetDialogHistory();
|
||||
var fileTypes = args?.FileTypes?.Split(",")?.ToList() ?? new List<string>();
|
||||
var dialogs = await AssembleFiles(conv.ConversationId, wholeDialogs, fileTypes);
|
||||
var agent = await agentService.LoadAgent(AIAssistant);
|
||||
var agent = await agentService.LoadAgent(!string.IsNullOrEmpty(message.CurrentAgentId) ? message.CurrentAgentId : AIAssistant);
|
||||
var fileAgent = new Agent
|
||||
{
|
||||
Id = agent.Id,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BotSharp.Core.Files.Hooks;
|
||||
|
||||
public class AttachmentProcessingHook : AgentHookBase
|
||||
{
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly AgentSettings _agentSettings;
|
||||
|
||||
public override string SelfId => string.Empty;
|
||||
|
||||
|
|
@ -12,7 +13,6 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
: base(services, settings)
|
||||
{
|
||||
_services = services;
|
||||
_agentSettings = settings;
|
||||
}
|
||||
|
||||
public override void OnAgentLoaded(Agent agent)
|
||||
|
|
@ -23,39 +23,29 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
|
||||
if (hasConvFiles)
|
||||
{
|
||||
agent.Instruction += "\r\n\r\nIf user wants to describe images or pdf files, please call load_attachment.";
|
||||
}
|
||||
agent.Instruction += "\r\n\r\nPlease call load_attachment if user wants to describe files, such as images, pdf.\r\n\r\n";
|
||||
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
|
||||
public override bool OnFunctionsLoaded(List<FunctionDef> functions)
|
||||
{
|
||||
var fileService = _services.GetRequiredService<IBotSharpFileService>();
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
var hasConvFiles = fileService.HasConversationUserFiles(conv.ConversationId);
|
||||
|
||||
if (hasConvFiles)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(new
|
||||
if (agent.Functions != null)
|
||||
{
|
||||
user_request = new
|
||||
var json = JsonSerializer.Serialize(new
|
||||
{
|
||||
type = "string",
|
||||
description = "The request posted by user, which is related to analyzing requested files. User can request for multiple files to process at one time."
|
||||
},
|
||||
file_types = new
|
||||
{
|
||||
type = "string",
|
||||
description = "The file types requested by user to analyze, such as image, png, jpeg, and pdf. There can be multiple file types in a single request. An example output is, 'image,pdf'"
|
||||
}
|
||||
});
|
||||
user_request = new
|
||||
{
|
||||
type = "string",
|
||||
description = "The request posted by user, which is related to analyzing requested files. User can request for multiple files to process at one time."
|
||||
},
|
||||
file_types = new
|
||||
{
|
||||
type = "string",
|
||||
description = "The file types requested by user to analyze, such as image, png, jpeg, and pdf. There can be multiple file types in a single request. An example output is, 'image,pdf'"
|
||||
}
|
||||
});
|
||||
|
||||
functions.Add(new FunctionDef
|
||||
{
|
||||
Name = "load_attachment",
|
||||
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 =
|
||||
agent.Functions.Add(new FunctionDef
|
||||
{
|
||||
Name = "load_attachment",
|
||||
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 =
|
||||
{
|
||||
Properties = JsonSerializer.Deserialize<JsonDocument>(json),
|
||||
Required = new List<string>
|
||||
|
|
@ -64,8 +54,10 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
"file_types"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return base.OnFunctionsLoaded(functions); ;
|
||||
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using BotSharp.Abstraction.Agents.Models;
|
|||
using BotSharp.Abstraction.Conversations;
|
||||
using BotSharp.Abstraction.Conversations.Models;
|
||||
using BotSharp.Abstraction.Files;
|
||||
using BotSharp.Abstraction.Files.Models;
|
||||
using BotSharp.Abstraction.Loggers;
|
||||
using BotSharp.Abstraction.MLTasks;
|
||||
using BotSharp.Abstraction.Utilities;
|
||||
|
|
@ -16,7 +15,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BotSharp.Plugin.AzureOpenAI.Providers;
|
||||
|
|
|
|||
Loading…
Reference in a new issue