Added a preview of the document analysis assistant (#561)
Build and Release / Read metadata (push) Waiting to run
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-apple-darwin, osx-arm64, macos-latest, aarch64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-pc-windows-msvc.exe, win-arm64, windows-latest, aarch64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-apple-darwin, osx-x64, macos-latest, x86_64-apple-darwin, dmg updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-pc-windows-msvc.exe, win-x64, windows-latest, x86_64-pc-windows-msvc, nsis updater) (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-x86_64-unknown-linux-gnu, linux-x64, ubuntu-22.04, x86_64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions
Build and Release / Prepare & create release (push) Blocked by required conditions
Build and Release / Publish release (push) Blocked by required conditions
Build and Release / Build app (${{ matrix.dotnet_runtime }}) (-aarch64-unknown-linux-gnu, linux-arm64, ubuntu-22.04-arm, aarch64-unknown-linux-gnu, appimage deb updater) (push) Blocked by required conditions

Co-authored-by: Peer Schütt <20603780+peerschuett@users.noreply.github.com>
This commit is contained in:
Thorsten SommerandPeer Schütt authored and GitHub committed 2025-11-24 12:37:18 +01:00
1 parent 8b0ee49ba9
commit 009bb33d83
42 files changed
+1947 -101

No files matched your search

@@ -84,6 +84,8 @@ public sealed class Data
public DataCoding Coding { get; init; } = new();
public DataERI ERI { get; init; } = new();
public DataDocumentAnalysis DocumentAnalysis { get; init; } = new();
public DataTextSummarizer TextSummarizer { get; init; } = new();
@@ -0,0 +1,9 @@
namespace AIStudio.Settings.DataModel;
public sealed class DataDocumentAnalysis
{
/// <summary>
/// Configured document analysis policies.
/// </summary>
public List<DataDocumentAnalysisPolicy> Policies { get; set; } = [];
}
@@ -0,0 +1,52 @@
using AIStudio.Provider;
namespace AIStudio.Settings.DataModel;
public sealed class DataDocumentAnalysisPolicy
{
/// <summary>
/// Preselect the policy name?
/// </summary>
public string PolicyName { get; set; } = string.Empty;
/// <summary>
/// Preselect the policy description?
/// </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; }
/// <summary>
/// Is this a managed policy? Managed policies are created and managed by the organization
/// and cannot be modified or deleted by the user.
/// </summary>
public bool IsManaged { get; set; }
/// <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;
}
@@ -11,4 +11,5 @@ public enum PreviewFeatures
PRE_PLUGINS_2025,
PRE_READ_PDF_2025,
PRE_DOCUMENT_ANALYSIS_2025,
}
@@ -13,6 +13,7 @@ public static class PreviewFeaturesExtensions
PreviewFeatures.PRE_PLUGINS_2025 => TB("Plugins: Preview of our plugin system where you can extend the functionality of the app"),
PreviewFeatures.PRE_READ_PDF_2025 => TB("Read PDF: Preview of our PDF reading system where you can read and extract text from PDF files"),
PreviewFeatures.PRE_DOCUMENT_ANALYSIS_2025 => TB("Document Analysis: Preview of our document analysis system where you can analyze and extract information from documents"),
_ => TB("Unknown preview feature")
};
@@ -20,6 +20,7 @@ public static class PreviewVisibilityExtensions
if (visibility >= PreviewVisibility.PROTOTYPE)
{
features.Add(PreviewFeatures.PRE_RAG_2024);
features.Add(PreviewFeatures.PRE_DOCUMENT_ANALYSIS_2025);
}
if (visibility >= PreviewVisibility.EXPERIMENTAL)
@@ -1,3 +1,4 @@
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
@@ -9,6 +10,9 @@ namespace AIStudio.Settings;
/// <remarks>
/// When the target enum value does not exist, the value will be the default value.
/// This converter handles enum values as property names and values.
/// <br/><br/>
/// We assume that enum names are in UPPER_SNAKE_CASE, and the JSON strings may be
/// in any case style (e.g., camelCase, PascalCase, snake_case, UPPER_SNAKE_CASE, etc.)
/// </remarks>
public sealed class TolerantEnumConverter : JsonConverter<object>
{
@@ -16,30 +20,46 @@ public sealed class TolerantEnumConverter : JsonConverter<object>
public override bool CanConvert(Type typeToConvert) => typeToConvert.IsEnum;
public override object? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override object? Read(ref Utf8JsonReader reader, Type enumType, JsonSerializerOptions options)
{
// Is this token a string?
if (reader.TokenType == JsonTokenType.String)
{
// Try to use that string as the name of the enum value:
if (Enum.TryParse(typeToConvert, reader.GetString(), out var result))
var text = reader.GetString();
// Convert the text to UPPER_SNAKE_CASE:
text = ConvertToUpperSnakeCase(text);
// Try to parse the enum value:
if (Enum.TryParse(enumType, text, out var result))
return result;
}
// In any other case, we will return the default enum value:
LOG.LogWarning($"Cannot read '{reader.GetString()}' as '{typeToConvert.Name}' enum; token type: {reader.TokenType}");
return Activator.CreateInstance(typeToConvert);
LOG.LogWarning($"Cannot read '{reader.GetString()}' as '{enumType.Name}' enum; token type: {reader.TokenType}");
return Activator.CreateInstance(enumType);
}
public override object ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override object ReadAsPropertyName(ref Utf8JsonReader reader, Type enumType, JsonSerializerOptions options)
{
// Is this token a property name?
if (reader.TokenType == JsonTokenType.PropertyName)
{
// Try to use that property name as the name of the enum value:
if (Enum.TryParse(typeToConvert, reader.GetString(), out var result))
var text = reader.GetString();
// Convert the text to UPPER_SNAKE_CASE:
text = ConvertToUpperSnakeCase(text);
// Try to parse the enum value:
if (Enum.TryParse(enumType, text, out var result))
return result;
}
// In any other case, we will return the default enum value:
LOG.LogWarning($"Cannot read '{reader.GetString()}' as '{typeToConvert.Name}' enum; token type: {reader.TokenType}");
return Activator.CreateInstance(typeToConvert)!;
LOG.LogWarning($"Cannot read '{reader.GetString()}' as '{enumType.Name}' enum; token type: {reader.TokenType}");
return Activator.CreateInstance(enumType)!;
}
public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOptions options)
@@ -51,4 +71,44 @@ public sealed class TolerantEnumConverter : JsonConverter<object>
{
writer.WritePropertyName(value.ToString()!);
}
/// <summary>
/// Converts a string to UPPER_SNAKE_CASE.
/// </summary>
/// <param name="text">The text to convert.</param>
/// <returns>The converted text as UPPER_SNAKE_CASE.</returns>
private static string ConvertToUpperSnakeCase(string? text)
{
// Handle null or empty strings:
if (string.IsNullOrWhiteSpace(text))
return string.Empty;
// Create a string builder with the same length as the
// input text. We will add underscores as needed, which
// may increase the length -- we cannot predict how many
// underscores will be added, so we just start with the
// original length:
var sb = new StringBuilder(text.Length);
// State to track if the last character was lowercase.
// This helps to determine when to add underscores:
var lastCharWasLowerCase = false;
// Iterate through each character in the input text:
foreach(var c in text)
{
// If the current character is uppercase and the last
// character was lowercase, we need to add an underscore:
if (char.IsUpper(c) && lastCharWasLowerCase)
sb.Append('_');
// Append the uppercase version of the current character:
sb.Append(char.ToUpperInvariant(c));
// Keep track of whether the current character is lowercase:
lastCharWasLowerCase = char.IsLower(c);
}
return sb.ToString();
}
}