Added guidelines from the organization to the BeyondFacts Lab (#1204)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-15 11:40:15 +01:00
1 parent cb54ad297d
commit 1361b984eb
38 files changed
+967 -255

No files matched your search

@@ -8,7 +8,9 @@ namespace AIStudio.Assistants.BeyondFactsLab;
/// <remarks>
/// A prompt with a placeholder nobody fills is an error, not a prompt with a gap: the model would read the
/// placeholder as text. The values are inserted in one pass, so a value which contains a placeholder itself, such
/// as a detail the person entered, stays as it is.
/// as a detail the person entered, stays as it is. A placeholder which stands on a line of its own and gets an empty
/// value takes its line and the empty lines after it along, so that an optional section, such as the one about the
/// guidelines of an organization, leaves no gap.
/// </remarks>
public static partial class BflPromptTemplate
{
@@ -77,6 +79,11 @@ public static partial class BflPromptTemplate
/// </summary>
public const string RESEARCH = "RESEARCH";
/// <summary>
/// How the model treats the guidelines of the organization, only while there are any, see BflOrganizationRules.
/// </summary>
public const string ORGANIZATION_RULES = "ORGANIZATION_RULES";
/// <summary>
/// What a research agent looks into, see BflResearchTopic.
/// </summary>
@@ -99,11 +106,16 @@ public static partial class BflPromptTemplate
/// <param name="values">The value of each placeholder, by its name.</param>
/// <returns>The prompt.</returns>
/// <exception cref="FormatException">The template has a placeholder without a value.</exception>
public static string Fill(string template, IReadOnlyDictionary<string, string> values) => PlaceholderPattern().Replace(template, match =>
public static string Fill(string template, IReadOnlyDictionary<string, string> values)
{
var name = match.Groups["name"].Value;
return values.TryGetValue(name, out var value) ? value : throw new FormatException($"The prompt has the placeholder '{name}', which has no value.");
});
// Only the template changes here, before any value goes in, so that values still go in in one pass:
var withoutEmptyLines = StandAlonePlaceholderPattern().Replace(template, match => values.TryGetValue(match.Groups["name"].Value, out var value) && value.Length is 0 ? string.Empty : match.Value);
return PlaceholderPattern().Replace(withoutEmptyLines, match =>
{
var name = match.Groups["name"].Value;
return values.TryGetValue(name, out var value) ? value : throw new FormatException($"The prompt has the placeholder '{name}', which has no value.");
});
}
/// <summary>
/// Finds the placeholders of a template, as Fill reads them.
@@ -114,4 +126,10 @@ public static partial class BflPromptTemplate
[GeneratedRegex(@"\{\{\s*(?<name>[^{}]*?)\s*\}\}")]
private static partial Regex PlaceholderPattern();
/// <summary>
/// Finds a placeholder which stands on a line of its own, together with the line break and the empty lines after it.
/// </summary>
[GeneratedRegex(@"^[ \t]*\{\{\s*(?<name>[^{}]*?)\s*\}\}[ \t]*(?:\r?\n[ \t]*)*(?:\r?\n|\z)", RegexOptions.Multiline)]
private static partial Regex StandAlonePlaceholderPattern();
}