2024-02-15 20:43:36 +00:00
|
|
|
using BotSharp.Abstraction.Loggers.Models;
|
2023-12-04 23:42:46 +00:00
|
|
|
using BotSharp.Abstraction.Repositories.Filters;
|
|
|
|
|
|
2023-06-03 02:07:30 +00:00
|
|
|
namespace BotSharp.Abstraction.Conversations;
|
|
|
|
|
|
|
|
|
|
public interface IConversationService
|
|
|
|
|
{
|
2023-09-06 03:19:36 +00:00
|
|
|
IConversationStateService States { get; }
|
2023-10-30 16:48:18 +00:00
|
|
|
string ConversationId { get; }
|
2023-06-27 18:31:13 +00:00
|
|
|
Task<Conversation> NewConversation(Conversation conversation);
|
2024-10-07 21:35:39 +00:00
|
|
|
void SetConversationId(string conversationId, List<MessageState> states, bool isReadOnly = false);
|
2023-07-19 22:30:23 +00:00
|
|
|
Task<Conversation> GetConversation(string id);
|
2023-12-04 23:42:46 +00:00
|
|
|
Task<PagedItems<Conversation>> GetConversations(ConversationFilter filter);
|
2023-11-22 05:07:19 +00:00
|
|
|
Task<Conversation> UpdateConversationTitle(string id, string title);
|
2024-12-12 03:28:00 +00:00
|
|
|
Task<Conversation> UpdateConversationTitleAlias(string id, string titleAlias);
|
2024-10-18 20:50:39 +00:00
|
|
|
Task<bool> UpdateConversationTags(string conversationId, List<string> tags);
|
2024-10-11 20:07:41 +00:00
|
|
|
Task<bool> UpdateConversationMessage(string conversationId, UpdateMessageRequest request);
|
2023-11-10 16:01:03 +00:00
|
|
|
Task<List<Conversation>> GetLastConversations();
|
2024-09-09 17:26:26 +00:00
|
|
|
Task<List<string>> GetIdleConversations(int batchSize, int messageLimit, int bufferHours, IEnumerable<string> excludeAgentIds);
|
2024-03-07 07:34:52 +00:00
|
|
|
Task<bool> DeleteConversations(IEnumerable<string> ids);
|
2024-05-06 22:31:52 +00:00
|
|
|
|
|
|
|
|
/// <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);
|
2023-08-14 22:14:05 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Send message to LLM
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="agentId"></param>
|
|
|
|
|
/// <param name="lastDalog"></param>
|
2024-02-28 20:40:59 +00:00
|
|
|
/// <param name="onResponseReceived">Received the response from AI Agent</param>
|
2023-08-14 22:14:05 +00:00
|
|
|
/// <param name="onFunctionExecuting">This delegate is useful when you want to report progress on UI</param>
|
2023-08-20 19:02:59 +00:00
|
|
|
/// <param name="onFunctionExecuted">This delegate is useful when you want to report progress on UI</param>
|
2023-08-14 22:14:05 +00:00
|
|
|
/// <returns></returns>
|
2023-11-27 03:04:48 +00:00
|
|
|
Task<bool> SendMessage(string agentId,
|
2023-08-14 22:14:05 +00:00
|
|
|
RoleDialogModel lastDalog,
|
2024-03-16 14:43:00 +00:00
|
|
|
PostbackMessageModel? replyMessage,
|
2024-09-12 10:49:45 +00:00
|
|
|
Func<RoleDialogModel, Task> onResponseReceived);
|
2023-08-14 22:14:05 +00:00
|
|
|
|
2024-10-07 21:42:20 +00:00
|
|
|
List<RoleDialogModel> GetDialogHistory(int lastCount = 100, bool fromBreakpoint = true, IEnumerable<string>? includeMessageTypes = null);
|
2023-06-27 18:31:13 +00:00
|
|
|
Task CleanHistory(string agentId);
|
2024-03-24 01:31:15 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Use this feature when you want to hide some context from LLM.
|
|
|
|
|
/// </summary>
|
2024-03-24 13:56:21 +00:00
|
|
|
/// <param name="resetStates">Whether to reset all states</param>
|
2024-04-08 03:15:51 +00:00
|
|
|
/// <param name="reason">Append user init words</param>
|
2024-05-27 13:17:50 +00:00
|
|
|
/// <param name="excludedStates"></param>
|
2024-03-24 01:31:15 +00:00
|
|
|
/// <returns></returns>
|
2024-05-27 13:17:50 +00:00
|
|
|
Task UpdateBreakpoint(bool resetStates = false, string? reason = null, params string[] excludedStates);
|
2024-05-27 01:40:24 +00:00
|
|
|
|
2024-05-29 02:50:16 +00:00
|
|
|
Task<string> GetConversationSummary(IEnumerable<string> conversationId);
|
2024-06-19 23:04:47 +00:00
|
|
|
|
|
|
|
|
Task<Conversation> GetConversationRecordOrCreateNew(string agentId);
|
2024-06-25 03:46:13 +00:00
|
|
|
|
|
|
|
|
bool IsConversationMode();
|
2025-01-28 23:00:08 +00:00
|
|
|
|
|
|
|
|
void SaveStates();
|
2025-02-11 20:27:53 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Get conversation keys for searching
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="query">search query</param>
|
|
|
|
|
/// <param name="convLimit">conversation limit</param>
|
|
|
|
|
/// <param name="preLoad">if pre-loading, then keys are not filter by the search query</param>
|
|
|
|
|
/// <returns></returns>
|
2025-02-14 17:19:39 +00:00
|
|
|
Task<List<string>> GetConversationStateSearhKeys(string query, int convLimit = 100, int keyLimit = 10, bool preload = false);
|
2025-03-06 22:46:38 +00:00
|
|
|
|
|
|
|
|
Task<bool> MigrateLatestStates(int batchSize = 100, int errorLimit = 10);
|
2023-06-03 02:07:30 +00:00
|
|
|
}
|