Merge branch 'SciSharp:master' into master
This commit is contained in:
commit
2601c0c1dc
|
|
@ -16,6 +16,11 @@ public partial class ConversationService
|
|||
{
|
||||
var conversation = await GetConversationRecord(agentId);
|
||||
|
||||
// Save message files
|
||||
var fileService = _services.GetRequiredService<IBotSharpFileService>();
|
||||
fileService.SaveMessageFiles(_conversationId, message.MessageId, FileSourceType.User, message.Files);
|
||||
message.Files?.Clear();
|
||||
|
||||
var agentService = _services.GetRequiredService<IAgentService>();
|
||||
Agent agent = await agentService.LoadAgent(agentId);
|
||||
|
||||
|
|
@ -46,11 +51,6 @@ public partial class ConversationService
|
|||
routing.Context.SetMessageId(_conversationId, message.MessageId);
|
||||
routing.Context.Push(agent.Id);
|
||||
|
||||
// Save message files
|
||||
var fileService = _services.GetRequiredService<IBotSharpFileService>();
|
||||
fileService.SaveMessageFiles(_conversationId, message.MessageId, FileSourceType.User, message.Files);
|
||||
message.Files?.Clear();
|
||||
|
||||
// Save payload
|
||||
if (replyMessage != null && !string.IsNullOrEmpty(replyMessage.Payload))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -221,14 +221,16 @@ public partial class BotSharpFileService
|
|||
}
|
||||
|
||||
var (_, bytes) = GetFileInfoFromData(file.FileData);
|
||||
Thread.Sleep(100);
|
||||
var subDir = Path.Combine(dir, source, $"{i + 1}");
|
||||
if (!ExistDirectory(subDir))
|
||||
{
|
||||
Directory.CreateDirectory(subDir);
|
||||
}
|
||||
|
||||
File.WriteAllBytes(Path.Combine(subDir, file.FileName), bytes);
|
||||
using var fs = new FileStream(Path.Combine(subDir, file.FileName), FileMode.Create);
|
||||
fs.Write(bytes, 0, bytes.Length);
|
||||
fs.Flush(true);
|
||||
Thread.Sleep(2000);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -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,9 +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;
|
||||
|
||||
|
|
@ -11,10 +13,9 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
: base(services, settings)
|
||||
{
|
||||
_services = services;
|
||||
_agentSettings = settings;
|
||||
}
|
||||
|
||||
public override bool OnFunctionsLoaded(List<FunctionDef> functions)
|
||||
public override void OnAgentLoaded(Agent agent)
|
||||
{
|
||||
var fileService = _services.GetRequiredService<IBotSharpFileService>();
|
||||
var conv = _services.GetRequiredService<IConversationService>();
|
||||
|
|
@ -22,25 +23,29 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
|
||||
if (hasConvFiles)
|
||||
{
|
||||
var json = JsonSerializer.Serialize(new
|
||||
{
|
||||
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'"
|
||||
}
|
||||
});
|
||||
agent.Instruction += "\r\n\r\nPlease call load_attachment if user wants to describe files, such as images, pdf.\r\n\r\n";
|
||||
|
||||
functions.Add(new FunctionDef
|
||||
if (agent.Functions != null)
|
||||
{
|
||||
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 =
|
||||
var json = JsonSerializer.Serialize(new
|
||||
{
|
||||
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'"
|
||||
}
|
||||
});
|
||||
|
||||
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>
|
||||
|
|
@ -49,8 +54,10 @@ public class AttachmentProcessingHook : AgentHookBase
|
|||
"file_types"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
return base.OnFunctionsLoaded(functions); ;
|
||||
|
||||
base.OnAgentLoaded(agent);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class TranslationService : ITranslationService
|
|||
if (data == null) return;
|
||||
|
||||
var dataType = data.GetType();
|
||||
if (IsStringType(dataType))
|
||||
if (IsStringType(dataType) && !string.IsNullOrWhiteSpace(data.ToString()))
|
||||
{
|
||||
res.Add(data.ToString());
|
||||
return;
|
||||
|
|
@ -139,7 +139,7 @@ public class TranslationService : ITranslationService
|
|||
{
|
||||
foreach (var item in (data as IEnumerable<string>))
|
||||
{
|
||||
if (item == null) continue;
|
||||
if (string.IsNullOrWhiteSpace(item)) continue;
|
||||
res.Add(item);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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