Merge pull request #217 from iceljc/features/add-delete-conversation
add delete conversation
This commit is contained in:
commit
80e157ae06
|
|
@ -10,7 +10,7 @@ public interface IConversationService
|
||||||
Task<List<Conversation>> GetConversations();
|
Task<List<Conversation>> GetConversations();
|
||||||
Task<Conversation> UpdateConversationTitle(string id, string title);
|
Task<Conversation> UpdateConversationTitle(string id, string title);
|
||||||
Task<List<Conversation>> GetLastConversations();
|
Task<List<Conversation>> GetLastConversations();
|
||||||
Task DeleteConversation(string id);
|
Task<bool> DeleteConversation(string id);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Send message to LLM
|
/// Send message to LLM
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public interface IBotSharpRepository
|
||||||
|
|
||||||
#region Conversation
|
#region Conversation
|
||||||
void CreateNewConversation(Conversation conversation);
|
void CreateNewConversation(Conversation conversation);
|
||||||
|
bool DeleteConversation(string conversationId);
|
||||||
List<DialogElement> GetConversationDialogs(string conversationId);
|
List<DialogElement> GetConversationDialogs(string conversationId);
|
||||||
void AppendConversationDialogs(string conversationId, List<DialogElement> dialogs);
|
void AppendConversationDialogs(string conversationId, List<DialogElement> dialogs);
|
||||||
List<StateKeyValue> GetConversationStates(string conversationId);
|
List<StateKeyValue> GetConversationStates(string conversationId);
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,13 @@ public partial class ConversationService : IConversationService
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task DeleteConversation(string id)
|
public async Task<bool> DeleteConversation(string id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
var isDeleted = db.DeleteConversation(id);
|
||||||
|
return await Task.FromResult(isDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Conversation> UpdateConversationTitle(string id, string title)
|
public async Task<Conversation> UpdateConversationTitle(string id, string title)
|
||||||
{
|
{
|
||||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,11 @@ public class BotSharpDbContext : Database, IBotSharpRepository
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DeleteConversation(string conversationId)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
public Conversation GetConversation(string conversationId)
|
public Conversation GetConversation(string conversationId)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ using BotSharp.Abstraction.Users.Models;
|
||||||
using BotSharp.Abstraction.Agents.Models;
|
using BotSharp.Abstraction.Agents.Models;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using BotSharp.Abstraction.Routing.Models;
|
using BotSharp.Abstraction.Routing.Models;
|
||||||
|
|
||||||
namespace BotSharp.Core.Repository;
|
namespace BotSharp.Core.Repository;
|
||||||
|
|
||||||
public class FileRepository : IBotSharpRepository
|
public class FileRepository : IBotSharpRepository
|
||||||
|
|
@ -625,6 +624,17 @@ public class FileRepository : IBotSharpRepository
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DeleteConversation(string conversationId)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(conversationId)) return false;
|
||||||
|
|
||||||
|
var dir = Path.Combine(_dbSettings.FileRepository, _conversationSettings.DataDir, conversationId);
|
||||||
|
if (!Directory.Exists(dir)) return false;
|
||||||
|
|
||||||
|
Directory.Delete(dir, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public List<DialogElement> GetConversationDialogs(string conversationId)
|
public List<DialogElement> GetConversationDialogs(string conversationId)
|
||||||
{
|
{
|
||||||
var dialogs = new List<DialogElement>();
|
var dialogs = new List<DialogElement>();
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,11 @@ public class ConversationController : ControllerBase, IApiAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("/conversation/{conversationId}")]
|
[HttpDelete("/conversation/{conversationId}")]
|
||||||
public async Task DeleteConversation([FromRoute] string conversationId)
|
public async Task<bool> DeleteConversation([FromRoute] string conversationId)
|
||||||
{
|
{
|
||||||
var service = _services.GetRequiredService<IConversationService>();
|
var conversationService = _services.GetRequiredService<IConversationService>();
|
||||||
|
var response = await conversationService.DeleteConversation(conversationId);
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("/conversation/{agentId}/{conversationId}")]
|
[HttpPost("/conversation/{agentId}/{conversationId}")]
|
||||||
|
|
|
||||||
|
|
@ -627,6 +627,17 @@ public class MongoRepository : IBotSharpRepository
|
||||||
_dc.ConversationDialogs.InsertOne(dialog);
|
_dc.ConversationDialogs.InsertOne(dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DeleteConversation(string conversationId)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(conversationId)) return false;
|
||||||
|
var filterConv = Builders<ConversationCollection>.Filter.Eq(x => x.Id, conversationId);
|
||||||
|
var filterDialog = Builders<ConversationDialogCollection>.Filter.Eq(x => x.ConversationId, conversationId);
|
||||||
|
|
||||||
|
var dialogDeleted = _dc.ConversationDialogs.DeleteMany(filterDialog);
|
||||||
|
var convDeleted = _dc.Conversations.DeleteMany(filterConv);
|
||||||
|
return convDeleted.DeletedCount > 0 || dialogDeleted.DeletedCount > 0;
|
||||||
|
}
|
||||||
|
|
||||||
public List<DialogElement> GetConversationDialogs(string conversationId)
|
public List<DialogElement> GetConversationDialogs(string conversationId)
|
||||||
{
|
{
|
||||||
var dialogs = new List<DialogElement>();
|
var dialogs = new List<DialogElement>();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue