refine
This commit is contained in:
parent
6308bdea5f
commit
9c14caede9
|
|
@ -23,7 +23,12 @@ public class SideCarAttribute : AsyncMoAttribute
|
|||
var instance = context.Target;
|
||||
var retType = context.ReturnType;
|
||||
|
||||
var serviceProvider = ((IHaveServiceProvider)instance).ServiceProvider;
|
||||
var serviceProvider = (instance as IHaveServiceProvider)?.ServiceProvider;
|
||||
if (serviceProvider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var (sidecar, sidecarMethod) = GetSideCarMethod(serviceProvider, methodName, retType, methodArgs);
|
||||
if (sidecar == null || sidecarMethod == null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,18 +4,22 @@ public class SideCarOptions
|
|||
{
|
||||
public bool IsInheritStates { get; set; }
|
||||
public IEnumerable<string>? InheritStateKeys { get; set; }
|
||||
public IEnumerable<string>? ExcludedStateKeys { get; set; }
|
||||
|
||||
public static SideCarOptions Empty()
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
public static SideCarOptions InheritStates(IEnumerable<string>? targetStates = null)
|
||||
public static SideCarOptions InheritStates(
|
||||
IEnumerable<string>? includedStates = null,
|
||||
IEnumerable<string>? excludedStates = null)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
IsInheritStates = true,
|
||||
InheritStateKeys = targetStates
|
||||
InheritStateKeys = includedStates,
|
||||
ExcludedStateKeys = excludedStates
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -194,14 +194,17 @@ public class BotSharpConversationSideCar : IConversationSideCar
|
|||
|
||||
if (_sideCarOptions?.IsInheritStates == true)
|
||||
{
|
||||
var hasIncludedStates = _sideCarOptions?.InheritStateKeys?.Any() == true;
|
||||
var hasExcludedStates = _sideCarOptions?.ExcludedStateKeys?.Any() == true;
|
||||
var curStates = state.GetCurrentState();
|
||||
|
||||
foreach (var pair in curStates)
|
||||
{
|
||||
var endNode = pair.Value.Values.LastOrDefault();
|
||||
if (endNode == null) continue;
|
||||
|
||||
if (_sideCarOptions?.InheritStateKeys?.Any() == true
|
||||
&& !_sideCarOptions.InheritStateKeys.Contains(pair.Key))
|
||||
if ((hasIncludedStates && !_sideCarOptions.InheritStateKeys.Contains(pair.Key))
|
||||
|| (hasExcludedStates && _sideCarOptions.ExcludedStateKeys.Contains(pair.Key)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -241,10 +241,9 @@ public partial class FileRepository
|
|||
if (!string.IsNullOrEmpty(convDir))
|
||||
{
|
||||
var breakpointFile = Path.Combine(convDir, BREAKPOINT_FILE);
|
||||
|
||||
if (!File.Exists(breakpointFile))
|
||||
{
|
||||
File.Create(breakpointFile);
|
||||
File.WriteAllText(breakpointFile, "[]");
|
||||
}
|
||||
|
||||
var content = File.ReadAllText(breakpointFile);
|
||||
|
|
@ -285,7 +284,7 @@ public partial class FileRepository
|
|||
var breakpointFile = Path.Combine(convDir, BREAKPOINT_FILE);
|
||||
if (!File.Exists(breakpointFile))
|
||||
{
|
||||
File.Create(breakpointFile);
|
||||
File.WriteAllText(breakpointFile, "[]");
|
||||
}
|
||||
|
||||
var content = File.ReadAllText(breakpointFile);
|
||||
|
|
@ -920,7 +919,6 @@ public partial class FileRepository
|
|||
private bool SaveTruncatedDialogs(string dialogDir, List<DialogElement> dialogs)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dialogDir) || dialogs == null) return false;
|
||||
if (!File.Exists(dialogDir)) File.Create(dialogDir);
|
||||
|
||||
var texts = ParseDialogElements(dialogs);
|
||||
File.WriteAllText(dialogDir, texts);
|
||||
|
|
@ -930,7 +928,6 @@ public partial class FileRepository
|
|||
private bool SaveTruncatedStates(string stateDir, List<StateKeyValue> states)
|
||||
{
|
||||
if (string.IsNullOrEmpty(stateDir) || states == null) return false;
|
||||
if (!File.Exists(stateDir)) File.Create(stateDir);
|
||||
|
||||
var stateStr = JsonSerializer.Serialize(states, _options);
|
||||
File.WriteAllText(stateDir, stateStr);
|
||||
|
|
@ -940,7 +937,6 @@ public partial class FileRepository
|
|||
private bool SaveTruncatedLatestStates(string latestStateDir, List<StateKeyValue> states)
|
||||
{
|
||||
if (string.IsNullOrEmpty(latestStateDir) || states == null) return false;
|
||||
if (!File.Exists(latestStateDir)) File.Create(latestStateDir);
|
||||
|
||||
var latestStates = BuildLatestStates(states);
|
||||
var stateStr = JsonSerializer.Serialize(latestStates, _options);
|
||||
|
|
@ -951,7 +947,6 @@ public partial class FileRepository
|
|||
private bool SaveTruncatedBreakpoints(string breakpointDir, List<ConversationBreakpoint> breakpoints)
|
||||
{
|
||||
if (string.IsNullOrEmpty(breakpointDir) || breakpoints == null) return false;
|
||||
if (!File.Exists(breakpointDir)) File.Create(breakpointDir);
|
||||
|
||||
var breakpointStr = JsonSerializer.Serialize(breakpoints, _options);
|
||||
File.WriteAllText(breakpointDir, breakpointStr);
|
||||
|
|
|
|||
|
|
@ -15,17 +15,17 @@ public partial class FileRepository
|
|||
}
|
||||
|
||||
var configFile = Path.Combine(vectorDir, COLLECTION_CONFIG_FILE);
|
||||
if (!File.Exists(configFile))
|
||||
{
|
||||
File.WriteAllText(configFile, "[]");
|
||||
}
|
||||
|
||||
if (reset)
|
||||
{
|
||||
File.WriteAllText(configFile, JsonSerializer.Serialize(configs ?? new(), _options));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!File.Exists(configFile))
|
||||
{
|
||||
File.Create(configFile);
|
||||
}
|
||||
|
||||
var str = File.ReadAllText(configFile);
|
||||
var savedConfigs = JsonSerializer.Deserialize<List<VectorCollectionConfig>>(str, _options) ?? new();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,31 +33,30 @@ public partial class KnowledgeService
|
|||
return false;
|
||||
}
|
||||
|
||||
var vectorDb = GetVectorDb();
|
||||
var created = await vectorDb.CreateCollection(collectionName, dimension);
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var created = db.AddKnowledgeCollectionConfigs(new List<VectorCollectionConfig>
|
||||
{
|
||||
new VectorCollectionConfig
|
||||
{
|
||||
Name = collectionName,
|
||||
Type = collectionType,
|
||||
VectorStore = new VectorStoreConfig
|
||||
{
|
||||
Provider = _settings.VectorDb.Provider
|
||||
},
|
||||
TextEmbedding = new KnowledgeEmbeddingConfig
|
||||
{
|
||||
Provider = provider,
|
||||
Model = model,
|
||||
Dimension = dimension
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (created)
|
||||
{
|
||||
var db = _services.GetRequiredService<IBotSharpRepository>();
|
||||
var userId = await GetUserId();
|
||||
|
||||
db.AddKnowledgeCollectionConfigs(new List<VectorCollectionConfig>
|
||||
{
|
||||
new VectorCollectionConfig
|
||||
{
|
||||
Name = collectionName,
|
||||
Type = collectionType,
|
||||
VectorStore = new VectorStoreConfig
|
||||
{
|
||||
Provider = _settings.VectorDb.Provider
|
||||
},
|
||||
TextEmbedding = new KnowledgeEmbeddingConfig
|
||||
{
|
||||
Provider = provider,
|
||||
Model = model,
|
||||
Dimension = dimension
|
||||
}
|
||||
}
|
||||
});
|
||||
var vectorDb = GetVectorDb();
|
||||
created = await vectorDb.CreateCollection(collectionName, dimension);
|
||||
}
|
||||
|
||||
return created;
|
||||
|
|
|
|||
Loading…
Reference in a new issue