mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-16 06:48:27 +00:00
Added guidelines from the organization to the BeyondFacts Lab (#1204)
This commit is contained in:
1 parent
cb54ad297d
commit
1361b984eb
38 files changed
+967
-255
No files matched your search
@@ -24,6 +24,8 @@ public sealed class BflChatRequestTests
|
||||
|
||||
private const string SYSTEM_PROMPT = "Der Prompt des Schritts.";
|
||||
|
||||
private const string RULES = "- Vor jeder öffentlichen Veranstaltung die Pressestelle kontaktieren.";
|
||||
|
||||
private string dataDirectory = string.Empty;
|
||||
private SettingsManager settingsManager = null!;
|
||||
private ServiceProvider serviceProvider = null!;
|
||||
@@ -65,7 +67,7 @@ public sealed class BflChatRequestTests
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
var isSent = await service.SendAsync(location.ChatId, this.Request(location, "Ich spreche auf einem Podium.", new(SYSTEM_PROMPT, [])));
|
||||
var isSent = await service.SendAsync(location.ChatId, this.Request(location, "Ich spreche auf einem Podium.", new(SYSTEM_PROMPT, [], string.Empty)));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
@@ -89,7 +91,7 @@ public sealed class BflChatRequestTests
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Passt das Lab zu meinem Interview?", new(SYSTEM_PROMPT, [])));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Passt das Lab zu meinem Interview?", new(SYSTEM_PROMPT, [], string.Empty)));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
@@ -110,7 +112,7 @@ public sealed class BflChatRequestTests
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, BflConversationService.OPENING_REQUEST, new(SYSTEM_PROMPT, [image]), isHidden: true));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, BflConversationService.OPENING_REQUEST, new(SYSTEM_PROMPT, [image], string.Empty), isHidden: true));
|
||||
|
||||
var stored = await store.LoadThreadAsync(location);
|
||||
var storedFile = await File.ReadAllTextAsync(Path.Combine(this.dataDirectory, BeyondFactsLabStore.ROOT_DIRECTORY_NAME, created.ProjectId.ToString("D"), "steps", BflStep.KNOWLEDGE.FolderName, "thread.json"));
|
||||
@@ -136,7 +138,7 @@ public sealed class BflChatRequestTests
|
||||
|
||||
var conversation = await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
var restrictionBefore = conversation.Thread!.RequiredOutboundDataRestriction;
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Wer sitzt mit auf dem Podium?", new(SYSTEM_PROMPT, [])));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Wer sitzt mit auf dem Podium?", new(SYSTEM_PROMPT, [], string.Empty)));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
@@ -146,6 +148,74 @@ public sealed class BflChatRequestTests
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheGuidelinesOfTheOrganizationGoAlongWithTheOpeningRequestOnly()
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var location = new BflStepThreadLocation(created.ProjectId, BflStep.STRATEGY);
|
||||
var image = new FileAttachmentImage("Poster.png", Path.Combine(this.dataDirectory, "poster-copy.png"), 1_024);
|
||||
ChatThread? sent = null;
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, BflConversationService.OPENING_REQUEST, new(SYSTEM_PROMPT, [image], RULES), isHidden: true));
|
||||
|
||||
var stored = await store.LoadThreadAsync(location);
|
||||
var storedFile = await File.ReadAllTextAsync(Path.Combine(this.dataDirectory, BeyondFactsLabStore.ROOT_DIRECTORY_NAME, created.ProjectId.ToString("D"), "steps", BflStep.STRATEGY.FolderName, "thread.json"));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TextOf(sent!.Blocks[0]), Is.EqualTo($"<hinweise_der_organisation>\n{RULES}\n</hinweise_der_organisation>\n\n{BflConversationService.OPENING_REQUEST}"));
|
||||
Assert.That(sent.Blocks[0].Content!.FileAttachments, Is.EqualTo(new FileAttachment[] { image }), "The images go along with the same message.");
|
||||
Assert.That(sent.SystemPrompt, Is.EqualTo(SYSTEM_PROMPT), "The guidelines never reach the system prompt.");
|
||||
Assert.That(sent.Blocks, Has.Count.EqualTo(stored!.Blocks.Count), "The request keeps as many messages as the chat.");
|
||||
Assert.That(TextOf(stored.Blocks[0]), Is.EqualTo(BflConversationService.OPENING_REQUEST), "The stored chat keeps the message as it was.");
|
||||
Assert.That(storedFile, Does.Not.Contain("Pressestelle"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheGuidelinesGoInFrontOfTheMessageOfThePersonWhoWritesFirst()
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var location = new BflStepThreadLocation(created.ProjectId, BflStep.FRAMEWORK);
|
||||
ChatThread? sent = null;
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Ich spreche auf einem Podium.", new(SYSTEM_PROMPT, [], RULES)));
|
||||
var firstRequest = sent!;
|
||||
await service.SendAsync(location.ChatId, this.Request(location, "Es geht um Wärmepumpen.", new(SYSTEM_PROMPT, [], RULES)));
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(firstRequest.Blocks.Select(block => block.Role), Is.EqualTo(new[] { ChatRole.USER, ChatRole.AI }), "No message of its own: two messages of the user in a row break some models.");
|
||||
Assert.That(TextOf(firstRequest.Blocks[0]), Does.StartWith("<hinweise_der_organisation>\n").And.EndWith("</hinweise_der_organisation>\n\nIch spreche auf einem Podium."));
|
||||
Assert.That(TextOf(sent!.Blocks[0]), Does.StartWith("<hinweise_der_organisation>\n"), "Every request carries the guidelines in front of the first message.");
|
||||
Assert.That(TextOf(sent.Blocks[2]), Is.EqualTo("Es geht um Wärmepumpen."), "Only the first message carries them.");
|
||||
Assert.That((await store.LoadThreadAsync(location))!.Blocks.Select(TextOf), Has.None.Contains("Pressestelle"));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task WithoutGuidelinesTheRequestCarriesTheOpeningRequestAsItIs()
|
||||
{
|
||||
var store = this.CreateStore();
|
||||
var created = await store.CreateAsync("Panel");
|
||||
var location = new BflStepThreadLocation(created.ProjectId, BflStep.GOALS_AND_ROLE);
|
||||
ChatThread? sent = null;
|
||||
var service = this.CreateService(thread => sent = thread);
|
||||
|
||||
await service.GetAsync(new BflChatStore(store, location), LAB, location.ChatId, () => BflThreadFactory.Create(location));
|
||||
await service.SendAsync(location.ChatId, this.Request(location, BflConversationService.OPENING_REQUEST, new(SYSTEM_PROMPT, [], string.Empty), isHidden: true));
|
||||
|
||||
Assert.That(TextOf(sent!.Blocks[0]), Is.EqualTo(BflConversationService.OPENING_REQUEST));
|
||||
}
|
||||
|
||||
private static string TextOf(ContentBlock block) => ((ContentText)block.Content!).Text;
|
||||
|
||||
private EmbeddedChatRequest Request(BflThreadLocation location, string text, BflRequestMaterial requestMaterial, bool isHidden = false) => new()
|
||||
{
|
||||
Provider = this.provider,
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools.PluginSystem;
|
||||
using AIStudio.Tools.Services;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace AIStudio.Tests.BeyondFactsLab;
|
||||
|
||||
/// <summary>
|
||||
/// Checks that a configuration plugin sets the notes of an organization for the BeyondFacts Lab, and that the lab
|
||||
/// takes no more of them than fits into every request.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Each test runs a configuration plugin the way AI Studio starts one, so that it checks how PluginConfiguration
|
||||
/// reads the notes as well. The settings are reached through Program.SERVICE_PROVIDER, and the managed state of each
|
||||
/// setting is static, which is why this fixture does not run alongside others.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
[NonParallelizable]
|
||||
public sealed class BflOrganizationRulesSettingTests
|
||||
{
|
||||
private static readonly Guid PLUGIN_ID = Guid.Parse("8b2e6f14-3c7a-4d95-a0e8-5f1b9c2d7e63");
|
||||
|
||||
private SettingsManager settingsManager = null!;
|
||||
private RustService rustService = null!;
|
||||
private ServiceProvider serviceProvider = null!;
|
||||
private IServiceProvider previousServiceProvider = null!;
|
||||
|
||||
[SetUp]
|
||||
public void CreateSettings()
|
||||
{
|
||||
// Only builds its HTTP clients. Nothing connects, because the plugins of these tests define no provider:
|
||||
this.rustService = new RustService("1", "unused");
|
||||
|
||||
// Creating the settings data registers every managed setting:
|
||||
this.settingsManager = new SettingsManager(NullLogger<SettingsManager>.Instance, this.rustService);
|
||||
|
||||
this.previousServiceProvider = Program.SERVICE_PROVIDER;
|
||||
this.serviceProvider = new ServiceCollection().AddSingleton(this.settingsManager).AddSingleton(this.rustService).BuildServiceProvider();
|
||||
Program.SERVICE_PROVIDER = this.serviceProvider;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void RestoreApplicationState()
|
||||
{
|
||||
// The managed state of a setting outlives this fixture, so we release what the plugin took over:
|
||||
ManagedConfiguration.CleanupLeftOverManagedConfigurations([], new HashSet<Guid>());
|
||||
|
||||
Program.SERVICE_PROVIDER = this.previousServiceProvider;
|
||||
this.serviceProvider.Dispose();
|
||||
this.rustService.Dispose();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithoutAPluginTheLabHasNoNotes()
|
||||
{
|
||||
Assert.That(this.settingsManager.ConfigurationData.BeyondFactsLab.OrganizationRules, Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task APluginSetsTheNotesWithLfLineBreaksAndWithoutSpacesAroundThem()
|
||||
{
|
||||
using var plugin = await RunPluginAsync("\"\\r\\n - Contact the press office.\\r\\n- Consult your head of department.\\r\\n\\r\\n\"");
|
||||
ManagedConfiguration.TryGet(x => x.BeyondFactsLab, x => x.OrganizationRules, out var configMeta);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(this.settingsManager.ConfigurationData.BeyondFactsLab.OrganizationRules, Is.EqualTo("- Contact the press office.\n- Consult your head of department."));
|
||||
Assert.That(configMeta.IsLocked, Is.True);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ThePluginMayUseAllTheCharactersTheLabTakes()
|
||||
{
|
||||
var notes = new string('a', DataBeyondFactsLab.ORGANIZATION_RULES_MAX_CHARACTERS);
|
||||
using var plugin = await RunPluginAsync($"\"{notes}\"");
|
||||
|
||||
Assert.That(this.settingsManager.ConfigurationData.BeyondFactsLab.OrganizationRules, Is.EqualTo(notes));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LongerNotesLeaveTheLabWithoutNotes()
|
||||
{
|
||||
var notes = new string('a', DataBeyondFactsLab.ORGANIZATION_RULES_MAX_CHARACTERS + 1);
|
||||
using var plugin = await RunPluginAsync($"\"{notes}\"");
|
||||
ManagedConfiguration.TryGet(x => x.BeyondFactsLab, x => x.OrganizationRules, out var configMeta);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(this.settingsManager.ConfigurationData.BeyondFactsLab.OrganizationRules, Is.Empty);
|
||||
Assert.That(configMeta.IsLocked, Is.False);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads a configuration plugin which sets the notes of the organization, and applies it the way AI Studio does
|
||||
/// when the plugin starts.
|
||||
/// </summary>
|
||||
/// <param name="luaValue">The notes, in the notation of Lua.</param>
|
||||
/// <returns>The started configuration plugin.</returns>
|
||||
private static async Task<PluginConfiguration> RunPluginAsync(string luaValue)
|
||||
{
|
||||
var code = $$"""
|
||||
ID = "{{PLUGIN_ID}}"
|
||||
NAME = "Configuration for the tests"
|
||||
DESCRIPTION = "A configuration plugin which sets the notes of an organization for the BeyondFacts Lab."
|
||||
VERSION = "1.0.0"
|
||||
TYPE = "CONFIGURATION"
|
||||
AUTHORS = {"MindWork AI"}
|
||||
SUPPORT_CONTACT = "MindWork AI"
|
||||
SOURCE_URL = "https://github.com/MindWorkAI/AI-Studio"
|
||||
CATEGORIES = {"CORE"}
|
||||
TARGET_GROUPS = {"EVERYONE"}
|
||||
IS_MAINTAINED = true
|
||||
DEPRECATION_MESSAGE = ""
|
||||
CONFIG = {}
|
||||
CONFIG["SETTINGS"] = {}
|
||||
CONFIG["SETTINGS"]["DataBeyondFactsLab.OrganizationRules"] = {{luaValue}}
|
||||
""";
|
||||
|
||||
var plugin = await PluginFactory.Load(null, code);
|
||||
if (plugin is not PluginConfiguration { IsValid: true } configurationPlugin)
|
||||
{
|
||||
var issues = string.Join(" ", plugin.Issues);
|
||||
plugin.Dispose();
|
||||
throw new InvalidOperationException($"The code of this test did not produce a valid configuration plugin: {issues}");
|
||||
}
|
||||
|
||||
await configurationPlugin.InitializeAsync(false);
|
||||
return configurationPlugin;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using AIStudio.Assistants.BeyondFactsLab;
|
||||
using AIStudio.Chat;
|
||||
using AIStudio.Settings.DataModel;
|
||||
|
||||
namespace AIStudio.Tests.BeyondFactsLab;
|
||||
|
||||
/// <summary>
|
||||
/// Checks which chats of the BeyondFacts Lab receive the guidelines of an organization, and how.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
public sealed class BflOrganizationRulesTests
|
||||
{
|
||||
private const string RULES = "- Vor jeder öffentlichen Veranstaltung die Pressestelle kontaktieren.";
|
||||
|
||||
[Test]
|
||||
public void OnlyTheChatsOfTheStepsReceiveTheGuidelines()
|
||||
{
|
||||
var settings = new DataBeyondFactsLab { OrganizationRules = RULES };
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
foreach (var step in BflStep.All)
|
||||
Assert.That(BflOrganizationRules.For(new BflStepThreadLocation(Guid.NewGuid(), step), settings), Is.EqualTo(RULES), step.ToString());
|
||||
|
||||
Assert.That(BflOrganizationRules.For(BflOnboardingThreadLocation.INSTANCE, settings), Is.Empty, "The conversation about whether the lab fits a task prepares no appearance.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithoutGuidelinesNothingGoesAlong()
|
||||
{
|
||||
var thread = ThreadWith("Ich spreche auf einem Podium.");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflOrganizationRules.Frame(string.Empty), Is.Empty);
|
||||
Assert.That(BflOrganizationRules.Frame(" \n"), Is.Empty);
|
||||
Assert.That(BflOrganizationRules.WithRules(thread, string.Empty), Is.SameAs(thread));
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AChatWithoutAMessageStaysAsItIs()
|
||||
{
|
||||
var thread = new ChatThread { Blocks = [] };
|
||||
|
||||
Assert.That(BflOrganizationRules.WithRules(thread, RULES), Is.SameAs(thread));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheRequestGetsACopyOfTheFirstMessageOnly()
|
||||
{
|
||||
var thread = ThreadWith("Ich spreche auf einem Podium.");
|
||||
var answer = thread.Blocks[1];
|
||||
|
||||
var request = BflOrganizationRules.WithRules(thread, RULES);
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(TextOf(request.Blocks[0]), Is.EqualTo($"<hinweise_der_organisation>\n{RULES}\n</hinweise_der_organisation>\n\nIch spreche auf einem Podium."));
|
||||
Assert.That(request.Blocks[1], Is.SameAs(answer), "The answer stays the same object.");
|
||||
Assert.That(TextOf(thread.Blocks[0]), Is.EqualTo("Ich spreche auf einem Podium."), "The chat keeps the message as it was.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyTheOpenPointsEndWithTheGuidelines()
|
||||
{
|
||||
const string TEXT = "# Offene Punkte\n\n## Recherchieren\n\n- [ ] Studienlage prüfen\n";
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflOrganizationRules.AddTo(BflResultKind.OPEN_POINTS, TEXT, RULES, "Vorgaben Ihrer Organisation"), Is.EqualTo($"# Offene Punkte\n\n## Recherchieren\n\n- [ ] Studienlage prüfen\n\n## Vorgaben Ihrer Organisation\n\n{RULES}"));
|
||||
Assert.That(BflOrganizationRules.AddTo(BflResultKind.OPEN_POINTS, TEXT, string.Empty, "Vorgaben Ihrer Organisation"), Is.EqualTo(TEXT));
|
||||
|
||||
foreach (var kind in BflResultKind.All.Where(kind => kind is not BflResultKind.OPEN_POINTS))
|
||||
Assert.That(BflOrganizationRules.AddTo(kind, TEXT, RULES, "Vorgaben Ihrer Organisation"), Is.EqualTo(TEXT), kind.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static string TextOf(ContentBlock block) => ((ContentText)block.Content!).Text;
|
||||
|
||||
private static ChatThread ThreadWith(string message) => new()
|
||||
{
|
||||
Blocks =
|
||||
[
|
||||
new ContentBlock { ContentType = ContentType.TEXT, Role = ChatRole.USER, Content = new ContentText { Text = message } },
|
||||
new ContentBlock { ContentType = ContentType.TEXT, Role = ChatRole.AI, Content = new ContentText { Text = "Worum geht es Ihnen?" } }
|
||||
]
|
||||
};
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public sealed class BflPromptComposerTests
|
||||
{
|
||||
private const string CORE = "Sprache: {{RESPONSE_LANGUAGE}}\n{{ADDRESS_FORM}}\n{{KNOWLEDGE}}\n{{STEP}}\n{{MATERIALS}}\n{{DETAILS}}\n{{MISSING_DETAILS}}";
|
||||
|
||||
private static readonly BflPromptParts PARTS = new(CORE, "Leitfaden", "Schritt", "Anrede");
|
||||
private static readonly BflPromptParts PARTS = new(CORE, "Leitfaden", "Schritt", "Anrede", string.Empty);
|
||||
|
||||
[Test]
|
||||
public void APlaceholderWithoutAValueIsAnError()
|
||||
@@ -35,6 +35,58 @@ public sealed class BflPromptComposerTests
|
||||
Assert.That(prompt, Is.EqualTo("Die Person schrieb {{KNOWLEDGE}}."), "What the person entered must never be read as a placeholder.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnEmptyPlaceholderOnALineOfItsOwnLeavesNoGap()
|
||||
{
|
||||
var values = new Dictionary<string, string> { [BflPromptTemplate.ORGANIZATION_RULES] = string.Empty, [BflPromptTemplate.STEP] = "Schritt" };
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflPromptTemplate.Fill("Davor.\n\n{{ORGANIZATION_RULES}}\n\n# Danach", values), Is.EqualTo("Davor.\n\n# Danach"));
|
||||
Assert.That(BflPromptTemplate.Fill("Davor.\r\n\r\n{{ ORGANIZATION_RULES }}\r\n\r\n# Danach", values), Is.EqualTo("Davor.\r\n\r\n# Danach"));
|
||||
Assert.That(BflPromptTemplate.Fill("- Erstens\n{{ORGANIZATION_RULES}}\n - Zweitens", values), Is.EqualTo("- Erstens\n - Zweitens"), "The indentation of the next line stays.");
|
||||
Assert.That(BflPromptTemplate.Fill("Davor.\n\n{{ORGANIZATION_RULES}}", values), Is.EqualTo("Davor.\n\n"));
|
||||
Assert.That(BflPromptTemplate.Fill("Im Satz {{ORGANIZATION_RULES}} bleibt die Zeile.", values), Is.EqualTo("Im Satz bleibt die Zeile."));
|
||||
Assert.That(BflPromptTemplate.Fill("{{STEP}}\n\n# Danach", values), Is.EqualTo("Schritt\n\n# Danach"), "A placeholder with a value keeps its line.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyWithGuidelinesThePromptOfAStepSaysHowToTreatThem()
|
||||
{
|
||||
foreach (var step in BflStep.All)
|
||||
{
|
||||
var parts = await BflPromptLibrary.LoadPartsAsync(step, AddressForm.FORMAL);
|
||||
var without = BflPromptComposer.Compose(parts, step, new Dictionary<BflStep, BflStepFormData>(), [], "Deutsch");
|
||||
var with = BflPromptComposer.Compose(parts, step, new Dictionary<BflStep, BflStepFormData>(), [], "Deutsch", organizationRules: "- Die Pressestelle kontaktieren.");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(without, Does.Not.Contain("hinweise_der_organisation").And.Not.Contain("# Hinweise der Organisation"), step.ToString());
|
||||
Assert.That(without, Does.Contain("aufzubauen.\n\n# Widersprüche und Lücken"), "No gap where the section would be.");
|
||||
Assert.That(with, Does.Contain(WithLf(parts.OrganizationRules.Trim()) + "\n\n# Widersprüche und Lücken"), step.ToString());
|
||||
Assert.That(with, Does.Not.Contain("Pressestelle kontaktieren"), "The guidelines themselves go along with the first message, never in the system prompt.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task OnlyWithGuidelinesTheOnboardingKnowsThatTheyExist()
|
||||
{
|
||||
var parts = await BflPromptLibrary.LoadOnboardingPartsAsync(AddressForm.FORMAL);
|
||||
|
||||
var without = BflPromptComposer.ComposeOnboarding(parts, "Deutsch");
|
||||
var with = BflPromptComposer.ComposeOnboarding(parts, "Deutsch", organizationRules: "- Die Pressestelle kontaktieren.");
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(without, Does.Not.Contain("Vorgaben"));
|
||||
Assert.That(without, Does.Not.Contain("{{"));
|
||||
Assert.That(with, Does.Contain(WithLf(parts.OrganizationRules.Trim())));
|
||||
Assert.That(with, Does.Not.Contain("Pressestelle kontaktieren"), "The onboarding never gets the text of the guidelines.");
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ThePromptOfEveryStepFillsEveryPlaceholder()
|
||||
{
|
||||
@@ -101,7 +153,7 @@ public sealed class BflPromptComposerTests
|
||||
[Test]
|
||||
public void TheOnboardingIsTheSameOnEverySystem()
|
||||
{
|
||||
var parts = new BflOnboardingPromptParts("Sprache: {{RESPONSE_LANGUAGE}}\r\n{{ADDRESS_FORM}}\r\nEnde", " Anrede\r\n");
|
||||
var parts = new BflOnboardingPromptParts("Sprache: {{RESPONSE_LANGUAGE}}\r\n{{ADDRESS_FORM}}\r\nEnde", " Anrede\r\n", string.Empty);
|
||||
|
||||
var prompt = BflPromptComposer.ComposeOnboarding(parts, "Deutsch");
|
||||
|
||||
@@ -111,7 +163,7 @@ public sealed class BflPromptComposerTests
|
||||
[Test]
|
||||
public void TheOnboardingKnowsNoDetailsOfAPreparation()
|
||||
{
|
||||
var parts = new BflOnboardingPromptParts("{{DETAILS}}", "Anrede");
|
||||
var parts = new BflOnboardingPromptParts("{{DETAILS}}", "Anrede", string.Empty);
|
||||
|
||||
Assert.Throws<FormatException>(() => BflPromptComposer.ComposeOnboarding(parts, "Deutsch"));
|
||||
}
|
||||
@@ -324,7 +376,7 @@ public sealed class BflPromptComposerTests
|
||||
[Test]
|
||||
public void TheOnboardingKnowsNoMaterial()
|
||||
{
|
||||
var parts = new BflOnboardingPromptParts("{{MATERIALS}}", "Anrede");
|
||||
var parts = new BflOnboardingPromptParts("{{MATERIALS}}", "Anrede", string.Empty);
|
||||
|
||||
Assert.Throws<FormatException>(() => BflPromptComposer.ComposeOnboarding(parts, "Deutsch"));
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ public sealed class BflPromptLibraryTests
|
||||
|
||||
using (Assert.EnterMultipleScope())
|
||||
{
|
||||
Assert.That(BflPromptComposer.Compose(new(core, "Leitfaden", "Schritt", "Anrede"), BflStep.FRAMEWORK, new Dictionary<BflStep, BflStepFormData>(), [], "Deutsch"), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.ComposeOnboarding(new(onboarding, "Anrede"), "Deutsch"), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.Compose(new(core, "Leitfaden", "Schritt", "Anrede", "Vorgaben"), BflStep.FRAMEWORK, new Dictionary<BflStep, BflStepFormData>(), [], "Deutsch"), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.ComposeOnboarding(new(onboarding, "Anrede", "Vorgaben"), "Deutsch"), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.ComposeWorkStateRequest(workState, BflStep.FRAMEWORK, new BflStepFormData()), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.ComposeResultRequest(result, new Dictionary<BflStep, BflWorkState>()), Does.Not.Contain("{{"));
|
||||
Assert.That(BflPromptComposer.ComposeResearch(new(research, "Auftrag"), [], "Deutsch"), Does.Not.Contain("{{"));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace AIStudio.Tests.BeyondFactsLab;
|
||||
[TestFixture]
|
||||
public sealed class BflResearchInStrategyTests
|
||||
{
|
||||
private static readonly BflPromptParts PARTS = new("{{RESEARCH}}", "Leitfaden", "Schritt", "Anrede");
|
||||
private static readonly BflPromptParts PARTS = new("{{RESEARCH}}", "Leitfaden", "Schritt", "Anrede", string.Empty);
|
||||
|
||||
private static readonly DateTimeOffset CREATED_AT_UTC = new(2026, 11, 10, 14, 0, 0, TimeSpan.Zero);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ public sealed class BflToolStatusTests
|
||||
[Test]
|
||||
public void TheSameSetupGivesTheSamePrompt()
|
||||
{
|
||||
var parts = new BflPromptParts("{{TOOLS}}", "Leitfaden", "Schritt", "Anrede");
|
||||
var parts = new BflPromptParts("{{TOOLS}}", "Leitfaden", "Schritt", "Anrede", string.Empty);
|
||||
var forms = BflStep.All.ToDictionary(step => step, _ => new BflStepFormData());
|
||||
|
||||
var first = BflPromptComposer.Compose(parts, BflStep.STRATEGY, forms, [], "Deutsch", null, new BflResearchAvailability(ToolOfferBlockReason.NONE, ToolOfferBlockReason.NONE));
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace AIStudio.Tests.BeyondFactsLab;
|
||||
[TestFixture]
|
||||
public sealed class BflWorkStatePromptTests
|
||||
{
|
||||
private static readonly BflPromptParts PARTS = new("{{WORK_STATES}}", "Leitfaden", "Schritt", "Anrede");
|
||||
private static readonly BflPromptParts PARTS = new("{{WORK_STATES}}", "Leitfaden", "Schritt", "Anrede", string.Empty);
|
||||
|
||||
private static readonly DateTimeOffset NOW = new(2026, 11, 10, 9, 0, 0, TimeSpan.Zero);
|
||||
|
||||
|
||||
Reference in new issue
Block a user