add active round log
This commit is contained in:
parent
f751d751d5
commit
f61ee50014
|
|
@ -14,6 +14,12 @@ public class StateChangeModel
|
||||||
[JsonPropertyName("before_value")]
|
[JsonPropertyName("before_value")]
|
||||||
public string BeforeValue { get; set; }
|
public string BeforeValue { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("before_active_rounds")]
|
||||||
|
public int? BeforeActiveRounds { get; set; }
|
||||||
|
|
||||||
[JsonPropertyName("after_value")]
|
[JsonPropertyName("after_value")]
|
||||||
public string AfterValue { get; set; }
|
public string AfterValue { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("after_active_rounds")]
|
||||||
|
public int? AfterActiveRounds { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,29 +43,31 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
||||||
var preValue = string.Empty;
|
var preValue = string.Empty;
|
||||||
var currentValue = value.ToString();
|
var currentValue = value.ToString();
|
||||||
var hooks = _services.GetServices<IConversationHook>();
|
var hooks = _services.GetServices<IConversationHook>();
|
||||||
|
var curActiveRounds = activeRounds > 0 ? activeRounds : -1;
|
||||||
|
int? preActiveRounds = null;
|
||||||
|
|
||||||
if (ContainsState(name) && _states.TryGetValue(name, out var pair))
|
if (ContainsState(name) && _states.TryGetValue(name, out var pair))
|
||||||
{
|
{
|
||||||
var lastNode = pair?.Values.LastOrDefault();
|
var lastNode = pair?.Values?.LastOrDefault();
|
||||||
|
preActiveRounds = lastNode?.ActiveRounds;
|
||||||
preValue = lastNode?.Data ?? string.Empty;
|
preValue = lastNode?.Data ?? string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation($"[STATE] {name} = {value}");
|
_logger.LogInformation($"[STATE] {name} = {value}");
|
||||||
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
var routingCtx = _services.GetRequiredService<IRoutingContext>();
|
||||||
|
|
||||||
if (!ContainsState(name) || preValue != currentValue)
|
foreach (var hook in hooks)
|
||||||
{
|
{
|
||||||
foreach (var hook in hooks)
|
hook.OnStateChanged(new StateChangeModel
|
||||||
{
|
{
|
||||||
hook.OnStateChanged(new StateChangeModel
|
ConversationId = _conversationId,
|
||||||
{
|
MessageId = routingCtx.MessageId,
|
||||||
ConversationId = _conversationId,
|
Name = name,
|
||||||
MessageId = routingCtx.MessageId,
|
BeforeValue = preValue,
|
||||||
Name = name,
|
BeforeActiveRounds = preActiveRounds,
|
||||||
BeforeValue = preValue,
|
AfterValue = currentValue,
|
||||||
AfterValue = currentValue
|
AfterActiveRounds = curActiveRounds
|
||||||
}).Wait();
|
}).Wait();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPair = new StateKeyValue
|
var newPair = new StateKeyValue
|
||||||
|
|
@ -79,7 +81,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
|
||||||
Data = currentValue,
|
Data = currentValue,
|
||||||
MessageId = routingCtx.MessageId,
|
MessageId = routingCtx.MessageId,
|
||||||
Active = true,
|
Active = true,
|
||||||
ActiveRounds = activeRounds > 0 ? activeRounds : -1,
|
ActiveRounds = curActiveRounds,
|
||||||
UpdateTime = DateTime.UtcNow,
|
UpdateTime = DateTime.UtcNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,9 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
|
||||||
MessageId = stateChange.MessageId,
|
MessageId = stateChange.MessageId,
|
||||||
Name = stateChange.Name,
|
Name = stateChange.Name,
|
||||||
BeforeValue = stateChange.BeforeValue,
|
BeforeValue = stateChange.BeforeValue,
|
||||||
|
BeforeActiveRounds = stateChange.BeforeActiveRounds,
|
||||||
AfterValue = stateChange.AfterValue,
|
AfterValue = stateChange.AfterValue,
|
||||||
|
AfterActiveRounds = stateChange.AfterActiveRounds,
|
||||||
CreateTime = DateTime.UtcNow
|
CreateTime = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue