add readonly

This commit is contained in:
Jicheng Lu 2024-04-02 15:39:14 -05:00
parent da42be0477
commit 40bafdc327
6 changed files with 14 additions and 4 deletions

View file

@ -14,7 +14,7 @@ public interface IConversationStateService
bool ContainsState(string name);
Dictionary<string, string> GetStates();
IConversationStateService SetState<T>(string name, T value, bool isNeedVersion = true,
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User);
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User, bool readOnly = false);
void SaveStateByArgs(JsonDocument args);
void CleanStates();
void Save();

View file

@ -28,4 +28,7 @@ public class StateChangeModel
[JsonPropertyName("source")]
public string Source { get; set; }
[JsonPropertyName("readonly")]
public bool Readonly { get; set; }
}

View file

@ -6,6 +6,7 @@ public class StateKeyValue
{
public string Key { get; set; }
public bool Versioning { get; set; }
public bool Readonly { get; set; }
public List<StateValue> Values { get; set; } = new List<StateValue>();
public StateKeyValue()

View file

@ -35,7 +35,7 @@ public class ConversationStateService : IConversationStateService, IDisposable
/// <param name="isNeedVersion">whether the state is related to message or not</param>
/// <returns></returns>
public IConversationStateService SetState<T>(string name, T value, bool isNeedVersion = true,
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User)
int activeRounds = -1, string valueType = StateDataType.String, string source = StateSource.User, bool readOnly = false)
{
if (value == null)
{
@ -72,7 +72,8 @@ public class ConversationStateService : IConversationStateService, IDisposable
AfterValue = currentValue,
AfterActiveRounds = curActiveRounds,
DataType = valueType,
Source = source
Source = source,
Readonly = readOnly
}).Wait();
}
}
@ -80,7 +81,8 @@ public class ConversationStateService : IConversationStateService, IDisposable
var newPair = new StateKeyValue
{
Key = name,
Versioning = isNeedVersion
Versioning = isNeedVersion,
Readonly = readOnly
};
var newValue = new StateValue

View file

@ -438,6 +438,7 @@ public class StreamingLogHook : ConversationHookBase, IContentGeneratingHook, IR
AfterActiveRounds = stateChange.AfterActiveRounds,
DataType = stateChange.DataType,
Source = stateChange.Source,
Readonly = stateChange.Readonly,
CreateTime = DateTime.UtcNow
};

View file

@ -6,6 +6,7 @@ public class StateMongoElement
{
public string Key { get; set; }
public bool Versioning { get; set; }
public bool Readonly { get; set; }
public List<StateValueMongoElement> Values { get; set; }
public static StateMongoElement ToMongoElement(StateKeyValue state)
@ -14,6 +15,7 @@ public class StateMongoElement
{
Key = state.Key,
Versioning = state.Versioning,
Readonly = state.Readonly,
Values = state.Values?.Select(x => StateValueMongoElement.ToMongoElement(x))?.ToList() ?? new List<StateValueMongoElement>()
};
}
@ -24,6 +26,7 @@ public class StateMongoElement
{
Key = state.Key,
Versioning = state.Versioning,
Readonly = state.Readonly,
Values = state.Values?.Select(x => StateValueMongoElement.ToDomainElement(x))?.ToList() ?? new List<StateValue>()
};
}