Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ public interface IConversationService
Task<List<Conversation>> GetLastConversations();
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
Task<bool> DeleteConversations(IEnumerable<string> ids);
Task<bool> TruncateConversation(string conversationId, string messageId);

/// <summary>
/// Truncate conversation
/// </summary>
/// <param name="conversationId">Target conversation id</param>
/// <param name="messageId">Target message id to delete</param>
/// <param name="newMessageId">If not null, delete messages while input a new message; otherwise delete messages only</param>
/// <returns></returns>
Task<bool> TruncateConversation(string conversationId, string messageId, string? newMessageId = null);
Task<List<ContentLogOutputModel>> GetConversationContentLogs(string conversationId);
Task<List<ConversationStateLogModel>> GetConversationStateLogs(string conversationId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ public class IncomingMessageModel : MessageConfig
/// Postback message
/// </summary>
public PostbackMessageModel? Postback { get; set; }

public List<BotSharpFile> Files { get; set; } = new List<BotSharpFile>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public class RoleDialogModel : ITrackableMessage

public FunctionCallFromLlm Instruction { get; set; }

public List<BotSharpFile> Files { get; set; } = new List<BotSharpFile>();

private RoleDialogModel()
{
}
Expand All @@ -87,6 +89,7 @@ public RoleDialogModel(string role, string text)
Role = role;
Content = text;
MessageId = Guid.NewGuid().ToString();
CreatedAt = DateTime.UtcNow;
}

public override string ToString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace BotSharp.Abstraction.Files;

public interface IBotSharpFileService
{
string GetDirectory(string conversationId);
IEnumerable<OutputFileModel> GetConversationFiles(string conversationId, string messageId);
string? GetMessageFile(string conversationId, string messageId, string fileName);
void SaveMessageFiles(string conversationId, string messageId, List<BotSharpFile> files);

/// <summary>
/// Delete files under messages
/// </summary>
/// <param name="conversationId">Conversation Id</param>
/// <param name="messageIds">Files in these messages will be deleted</param>
/// <param name="targetMessageId">The starting message to delete</param>
/// <param name="newMessageId">If not null, delete messages while input a new message; otherwise, delete messages only</param>
/// <returns></returns>
bool DeleteMessageFiles(string conversationId, IEnumerable<string> messageIds, string targetMessageId, string? newMessageId = null);
bool DeleteConversationFiles(IEnumerable<string> conversationIds);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

namespace BotSharp.Abstraction.Files.Models;

public class BotSharpFile
{
[JsonPropertyName("file_name")]
public string FileName { get; set; }

[JsonPropertyName("file_data")]
public string FileData { get; set; }

[JsonPropertyName("content_type")]
public string ContentType { get; set; }

[JsonPropertyName("file_size")]
public int FileSize { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BotSharp.Abstraction.Files.Models;

public class OutputFileModel
{
[JsonPropertyName("file_url")]
public string FileUrl { get; set; }

[JsonPropertyName("file_name")]
public string FileName { get; set; }

[JsonPropertyName("file_type")]
public string FileType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public interface IBotSharpRepository
ConversationBreakpoint? GetConversationBreakpoint(string conversationId);
List<Conversation> GetLastConversations();
List<string> GetIdleConversations(int batchSize, int messageLimit, int bufferHours);
bool TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
IEnumerable<string> TruncateConversation(string conversationId, string messageId, bool cleanLog = false);
#endregion

#region Execution Log
Expand Down
1 change: 1 addition & 0 deletions src/Infrastructure/BotSharp.Abstraction/Using.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
global using BotSharp.Abstraction.Templating;
global using BotSharp.Abstraction.Translation.Attributes;
global using BotSharp.Abstraction.Messaging.Enums;
global using BotSharp.Abstraction.Files.Models;
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using BotSharp.Abstraction.Files;
using BotSharp.Abstraction.Instructs;
using BotSharp.Abstraction.Messaging;
using BotSharp.Abstraction.Plugins.Models;
using BotSharp.Abstraction.Routing.Planning;
using BotSharp.Abstraction.Settings;
using BotSharp.Abstraction.Templating;
using BotSharp.Core.Files;
using BotSharp.Core.Instructs;
using BotSharp.Core.Messaging;
using BotSharp.Core.Routing.Planning;
Expand Down Expand Up @@ -35,7 +37,7 @@ public void RegisterDI(IServiceCollection services, IConfiguration config)
services.AddScoped<IConversationStorage, ConversationStorage>();
services.AddScoped<IConversationService, ConversationService>();
services.AddScoped<IConversationStateService, ConversationStateService>();
services.AddScoped<IConversationAttachmentService, ConversationAttachmentService>();
services.AddScoped<IBotSharpFileService, BotSharpFileService>();
services.AddScoped<ITranslationService, TranslationService>();

// Rich content messaging
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public async Task<bool> SendMessage(string agentId,
#endif

message.CurrentAgentId = agent.Id;
message.CreatedAt = DateTime.UtcNow;
if (string.IsNullOrEmpty(message.SenderId))
{
message.SenderId = _user.Id;
Expand All @@ -47,6 +46,11 @@ public async Task<bool> SendMessage(string agentId,
routing.Context.SetMessageId(_conversationId, message.MessageId);
routing.Context.Push(agent.Id);

// Save message files
var fileService = _services.GetRequiredService<IBotSharpFileService>();
fileService.SaveMessageFiles(_conversationId, message.MessageId, message.Files);
message.Files?.Clear();

// Before chat completion hook
foreach (var hook in hooks)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ namespace BotSharp.Core.Conversations.Services;

public partial class ConversationService : IConversationService
{
public async Task<bool> TruncateConversation(string conversationId, string messageId)
public async Task<bool> TruncateConversation(string conversationId, string messageId, string? newMessageId = null)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var isSaved = db.TruncateConversation(conversationId, messageId, true);
var fileService = _services.GetRequiredService<IBotSharpFileService>();
var deleteMessageIds = db.TruncateConversation(conversationId, messageId, cleanLog: true);

fileService.DeleteMessageFiles(conversationId, deleteMessageIds, messageId, newMessageId);

var hooks = _services.GetServices<IConversationHook>().ToList();
foreach (var hook in hooks)
{
await hook.OnMessageDeleted(conversationId, messageId);
}
return await Task.FromResult(isSaved);
return await Task.FromResult(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public ConversationService(
public async Task<bool> DeleteConversations(IEnumerable<string> ids)
{
var db = _services.GetRequiredService<IBotSharpRepository>();
var fileService = _services.GetRequiredService<IBotSharpFileService>();
var isDeleted = db.DeleteConversations(ids);
fileService.DeleteConversationFiles(ids);
return await Task.FromResult(isDeleted);
}

Expand Down
Loading