UpdateBreakpoint resetStates
This commit is contained in:
parent
52eb65ffd3
commit
f7cbbe84de
|
|
@ -73,4 +73,7 @@ public abstract class ConversationHookBase : IConversationHook
|
|||
|
||||
public virtual Task OnMessageDeleted(string conversationId, string messageId)
|
||||
=> Task.CompletedTask;
|
||||
|
||||
public virtual Task OnBreakpointUpdated(string conversationId, bool resetStates)
|
||||
=> Task.CompletedTask;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,4 +93,11 @@ public interface IConversationHook
|
|||
/// <param name="messageId"></param>
|
||||
/// <returns></returns>
|
||||
Task OnMessageDeleted(string conversationId, string messageId);
|
||||
|
||||
/// <summary>
|
||||
/// Brakpoint updated
|
||||
/// </summary>
|
||||
/// <param name="conversationId"></param>
|
||||
/// <returns></returns>
|
||||
Task OnBreakpointUpdated(string conversationId, bool resetStates);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ public interface IConversationService
|
|||
/// <summary>
|
||||
/// Use this feature when you want to hide some context from LLM.
|
||||
/// </summary>
|
||||
/// <param name="resetStates">Whether to reset all states</param>
|
||||
/// <returns></returns>
|
||||
Task UpdateBreakpoint();
|
||||
Task UpdateBreakpoint(bool resetStates = false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ public interface IConversationStateService
|
|||
Dictionary<string, string> GetStates();
|
||||
IConversationStateService SetState<T>(string name, T value, bool isNeedVersion = true);
|
||||
void SaveStateByArgs(JsonDocument args);
|
||||
void CleanState();
|
||||
void CleanStates();
|
||||
void Save();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,26 @@ namespace BotSharp.Core.Conversations.Services;
|
|||
|
||||
public partial class ConversationService : IConversationService
|
||||
{
|
||||
public async Task UpdateBreakpoint()
|
||||
public async Task UpdateBreakpoint(bool resetStates = false)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
db.UpdateConversationBreakpoint(_conversationId, DateTime.UtcNow);
|
||||
|
||||
// Reset states
|
||||
if (resetStates)
|
||||
{
|
||||
var states = _services.GetRequiredService<IConversationStateService>();
|
||||
states.CleanStates();
|
||||
}
|
||||
|
||||
var hooks = _services.GetServices<IConversationHook>()
|
||||
.OrderBy(x => x.Priority)
|
||||
.ToList();
|
||||
|
||||
// Before executing functions
|
||||
foreach (var hook in hooks)
|
||||
{
|
||||
await hook.OnBreakpointUpdated(_conversationId, resetStates);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
|||
_logger.LogInformation($"Saved states of conversation {_conversationId}");
|
||||
}
|
||||
|
||||
public void CleanState()
|
||||
public void CleanStates()
|
||||
{
|
||||
_states.Clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,27 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
|||
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated", BuildContentLog(input));
|
||||
}
|
||||
|
||||
public override async Task OnBreakpointUpdated(string conversationId, bool resetStates)
|
||||
{
|
||||
var log = $"Conversation breakpoint is updated";
|
||||
if (resetStates)
|
||||
{
|
||||
log += ", states are reset";
|
||||
}
|
||||
var routing = _services.GetRequiredService<IRoutingService>();
|
||||
var agentId = routing.Context.ConversationId;
|
||||
var agent = await _agentService.LoadAgent(agentId);
|
||||
|
||||
var input = new ContentLogInputModel()
|
||||
{
|
||||
Name = agent.Name,
|
||||
ConversationId = conversationId,
|
||||
Source = ContentLogSource.FunctionCall,
|
||||
Log = log
|
||||
};
|
||||
await _chatHub.Clients.User(_user.Id).SendAsync("OnConversationContentLogGenerated", BuildContentLog(input));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IRoutingHook
|
||||
|
|
|
|||
Loading…
Reference in a new issue