2025-11-24 11:37:18 +00:00
|
|
|
using AIStudio.Provider;
|
2026-01-31 19:50:10 +00:00
|
|
|
using AIStudio.Tools.PluginSystem;
|
|
|
|
|
|
|
|
|
|
using Lua;
|
2025-11-24 11:37:18 +00:00
|
|
|
|
|
|
|
|
namespace AIStudio.Settings.DataModel;
|
|
|
|
|
|
2026-01-31 19:50:10 +00:00
|
|
|
public sealed record DataDocumentAnalysisPolicy : ConfigurationBaseObject
|
2025-11-24 11:37:18 +00:00
|
|
|
{
|
2026-01-31 19:50:10 +00:00
|
|
|
private static readonly ILogger LOG = Program.LOGGER_FACTORY.CreateLogger<DataDocumentAnalysisPolicy>();
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string Id { get; init; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override uint Num { get; init; }
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override string Name
|
|
|
|
|
{
|
|
|
|
|
get => this.PolicyName;
|
|
|
|
|
init => this.PolicyName = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override bool IsEnterpriseConfiguration { get; init; }
|
|
|
|
|
|
2025-11-24 11:37:18 +00:00
|
|
|
/// <summary>
|
2026-01-31 19:50:10 +00:00
|
|
|
/// The name of the document analysis policy.
|
2025-11-24 11:37:18 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public string PolicyName { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-01-31 19:50:10 +00:00
|
|
|
/// The description of the document analysis policy.
|
2025-11-24 11:37:18 +00:00
|
|
|
/// </summary>
|
|
|
|
|
public string PolicyDescription { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Is this policy protected? If so, it cannot be deleted or modified by the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool IsProtected { get; set; }
|
2026-01-31 19:50:10 +00:00
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public override Guid EnterpriseConfigurationPluginId { get; init; } = Guid.Empty;
|
2025-11-24 11:37:18 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The rules for the document analysis policy.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string AnalysisRules { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The rules for the output of the document analysis, e.g., the desired format, structure, etc.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string OutputRules { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The minimum confidence level required for a provider to be considered.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public ConfidenceLevel MinimumProviderConfidence { get; set; } = ConfidenceLevel.NONE;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Which LLM provider should be preselected?
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string PreselectedProvider { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Preselect a profile?
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string PreselectedProfile { get; set; } = string.Empty;
|
2026-01-31 19:50:10 +00:00
|
|
|
|
|
|
|
|
public static bool TryProcessConfiguration(int idx, LuaTable table, Guid configPluginId, out ConfigurationBaseObject policy)
|
|
|
|
|
{
|
|
|
|
|
policy = new DataDocumentAnalysisPolicy();
|
|
|
|
|
if (!table.TryGetValue("Id", out var idValue) || !idValue.TryRead<string>(out var idText) || !Guid.TryParse(idText, out var id))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} does not contain a valid ID. The ID must be a valid GUID.", idx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!table.TryGetValue("PolicyName", out var nameValue) || !nameValue.TryRead<string>(out var name) || string.IsNullOrWhiteSpace(name))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} does not contain a valid PolicyName field.", idx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!table.TryGetValue("PolicyDescription", out var descriptionValue) || !descriptionValue.TryRead<string>(out var description) || string.IsNullOrWhiteSpace(description))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} does not contain a valid PolicyDescription field.", idx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!table.TryGetValue("AnalysisRules", out var analysisRulesValue) || !analysisRulesValue.TryRead<string>(out var analysisRules) || string.IsNullOrWhiteSpace(analysisRules))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} does not contain valid AnalysisRules field.", idx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!table.TryGetValue("OutputRules", out var outputRulesValue) || !outputRulesValue.TryRead<string>(out var outputRules) || string.IsNullOrWhiteSpace(outputRules))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} does not contain valid OutputRules field.", idx);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var minimumConfidence = ConfidenceLevel.NONE;
|
|
|
|
|
if (table.TryGetValue("MinimumProviderConfidence", out var minConfValue) && minConfValue.TryRead<string>(out var minConfText))
|
|
|
|
|
{
|
|
|
|
|
if (!Enum.TryParse(minConfText, true, out minimumConfidence))
|
|
|
|
|
{
|
|
|
|
|
LOG.LogWarning("The configured document analysis policy {PolicyIndex} contains an invalid MinimumProviderConfidence: {ConfidenceLevel}.", idx, minConfText);
|
|
|
|
|
minimumConfidence = ConfidenceLevel.NONE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var preselectedProvider = string.Empty;
|
|
|
|
|
if (table.TryGetValue("PreselectedProvider", out var providerValue) && providerValue.TryRead<string>(out var providerId))
|
|
|
|
|
preselectedProvider = providerId;
|
|
|
|
|
|
|
|
|
|
var preselectedProfile = string.Empty;
|
|
|
|
|
if (table.TryGetValue("PreselectedProfile", out var profileValue) && profileValue.TryRead<string>(out var profileId))
|
|
|
|
|
preselectedProfile = profileId;
|
|
|
|
|
|
|
|
|
|
policy = new DataDocumentAnalysisPolicy
|
|
|
|
|
{
|
|
|
|
|
Id = id.ToString(),
|
|
|
|
|
Num = 0, // will be set later by the PluginConfigurationObject
|
|
|
|
|
PolicyName = name,
|
|
|
|
|
PolicyDescription = description,
|
|
|
|
|
AnalysisRules = analysisRules,
|
|
|
|
|
OutputRules = outputRules,
|
|
|
|
|
MinimumProviderConfidence = minimumConfidence,
|
|
|
|
|
PreselectedProvider = preselectedProvider,
|
|
|
|
|
PreselectedProfile = preselectedProfile,
|
|
|
|
|
IsProtected = true,
|
|
|
|
|
IsEnterpriseConfiguration = true,
|
|
|
|
|
EnterpriseConfigurationPluginId = configPluginId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-11-24 11:37:18 +00:00
|
|
|
}
|