mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-16 18:48:28 +00:00
Added the research on individual participants to the BeyondFacts Lab (#1207)
This commit is contained in:
1 parent
3ca4b3878b
commit
92d0ff68f4
69 files changed
+3869
-186
No files matched your search
@@ -39,9 +39,10 @@ public static class BflPromptComposer
|
||||
/// <param name="research">The research of the preparation, by its topics; only the step "Strategy" gets it. Null when there is none.</param>
|
||||
/// <param name="organizationRules">The guidelines of the organization, which the first message carries, see BflOrganizationRules; only while there are any, the prompt says how to treat them. Null when there are none.</param>
|
||||
/// <param name="valueDeck">The value deck in the language of the app, with which the step "Values and perspectives" shows the card sort of the person among its details; the other steps leave it out. Null when there is none.</param>
|
||||
/// <param name="people">The research on single people of the list of participants, in the order of the list; only the step "Strategy" gets it. Null when there is none.</param>
|
||||
/// <returns>The system prompt.</returns>
|
||||
/// <exception cref="FormatException">The core prompt has a placeholder without a value.</exception>
|
||||
public static string Compose(BflPromptParts parts, BflStep step, IReadOnlyDictionary<BflStep, BflStepFormData> forms, IReadOnlyList<BflMaterialExcerpt> materials, string responseLanguage, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, BflResearchAvailability? tools = null, IReadOnlyDictionary<BflResearchTopic, BflResearch>? research = null, string? organizationRules = null, BflValueDeck? valueDeck = null) => BflPromptTemplate.Fill(parts.Core, new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
public static string Compose(BflPromptParts parts, BflStep step, IReadOnlyDictionary<BflStep, BflStepFormData> forms, IReadOnlyList<BflMaterialExcerpt> materials, string responseLanguage, IReadOnlyDictionary<BflStep, BflWorkState>? workStates = null, BflResearchAvailability? tools = null, IReadOnlyDictionary<BflResearchTopic, BflResearch>? research = null, string? organizationRules = null, BflValueDeck? valueDeck = null, IReadOnlyList<BflPersonResearch>? people = null) => BflPromptTemplate.Fill(parts.Core, new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
[BflPromptTemplate.RESPONSE_LANGUAGE] = responseLanguage,
|
||||
[BflPromptTemplate.ADDRESS_FORM] = parts.Address.Trim(),
|
||||
@@ -49,7 +50,7 @@ public static class BflPromptComposer
|
||||
[BflPromptTemplate.STEP] = parts.Step.Trim(),
|
||||
[BflPromptTemplate.MATERIALS] = Materials(materials),
|
||||
[BflPromptTemplate.TOOLS] = BflToolStatus.ForStep(tools ?? NO_TOOLS).Trim(),
|
||||
[BflPromptTemplate.RESEARCH] = Research(step, research ?? new Dictionary<BflResearchTopic, BflResearch>(), forms),
|
||||
[BflPromptTemplate.RESEARCH] = Research(step, research ?? new Dictionary<BflResearchTopic, BflResearch>(), people ?? [], forms),
|
||||
[BflPromptTemplate.WORK_STATES] = WorkStates(step, workStates ?? new Dictionary<BflStep, BflWorkState>(), forms),
|
||||
[BflPromptTemplate.DETAILS] = Details(step, forms, valueDeck),
|
||||
[BflPromptTemplate.MISSING_DETAILS] = MissingDetails(step, forms),
|
||||
@@ -132,6 +133,107 @@ public static class BflPromptComposer
|
||||
[BflPromptTemplate.PUBLIC_DETAILS] = PublicDetails(details)
|
||||
}).ReplaceLineEndings(LINE_BREAK.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Puts together the system prompt of an agent of the research on a person.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Like the research on a topic, it carries nothing of the preparation but the public details about the event. The
|
||||
/// person comes from the list of participants, which an agent found on the web, and the earlier stages are what
|
||||
/// agents found on the web as well; both are the answers of models which read only filtered web content.
|
||||
/// </remarks>
|
||||
/// <param name="parts">The texts of the prompt; the topic is the task of the stage.</param>
|
||||
/// <param name="details">The public details about the event, see PublicDetailsOf.</param>
|
||||
/// <param name="participant">The person, as the list of participants gives them.</param>
|
||||
/// <param name="earlierStages">What the earlier stages of this research found, in their order.</param>
|
||||
/// <param name="responseLanguage">The name of the language the agent writes in, e.g., the language of the app.</param>
|
||||
/// <returns>The system prompt.</returns>
|
||||
/// <exception cref="FormatException">The prompt has a placeholder without a value.</exception>
|
||||
public static string ComposePersonResearch(BflResearchPromptParts parts, IReadOnlyList<BflResearchDetail> details, BflParticipant participant, IReadOnlyList<BflPersonStageResearch> earlierStages, string responseLanguage) => BflPromptTemplate.Fill(parts.Research, new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
[BflPromptTemplate.RESPONSE_LANGUAGE] = responseLanguage,
|
||||
[BflPromptTemplate.TOPIC] = parts.Topic.Trim(),
|
||||
[BflPromptTemplate.TOOL_CALLS] = ToolSelectionRules.MAX_TOOL_CALLS.ToString(CultureInfo.InvariantCulture),
|
||||
[BflPromptTemplate.PERSON] = Person(participant),
|
||||
[BflPromptTemplate.EARLIER_STAGES] = EarlierStages(earlierStages),
|
||||
[BflPromptTemplate.PUBLIC_DETAILS] = PublicDetails(details)
|
||||
}).ReplaceLineEndings(LINE_BREAK.ToString());
|
||||
|
||||
/// <summary>
|
||||
/// Puts together the system prompt with which the lab suggests whom of a long list of participants to research.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Unlike a research, it knows the details of the preparation, since the people who matter most depend on the
|
||||
/// contribution of the person. Only the details of the first three steps count, about the event, the knowledge,
|
||||
/// and the goal and role of the person, and nothing the person confided. The request has no tools, and the lab
|
||||
/// accepts nothing but names from the list as its answer, see BflParticipantSelectionCheck, so that none of the
|
||||
/// details reaches a search.
|
||||
/// </remarks>
|
||||
/// <param name="template">The prompt, see BflPromptLibrary.PARTICIPANT_SELECTION_PATH.</param>
|
||||
/// <param name="forms">The forms of the preparation, by their steps.</param>
|
||||
/// <param name="participants">The list of participants.</param>
|
||||
/// <returns>The system prompt.</returns>
|
||||
/// <exception cref="FormatException">The prompt has a placeholder without a value.</exception>
|
||||
public static string ComposeParticipantSelection(string template, IReadOnlyDictionary<BflStep, BflStepFormData> forms, IReadOnlyList<BflParticipant> participants)
|
||||
{
|
||||
var earlierForms = forms.Where(form => form.Key < BflStep.VALUES_AND_PERSPECTIVES).ToDictionary(form => form.Key, form => form.Value);
|
||||
var list = string.Join($"{LINE_BREAK}{LINE_BREAK}", participants.Select(participant => participant.Entry.Trim().Length is 0
|
||||
? $"### {participant.Name}"
|
||||
: $"### {participant.Name}{LINE_BREAK}{participant.Entry.Trim()}"));
|
||||
|
||||
return BflPromptTemplate.Fill(template, new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
[BflPromptTemplate.SELECTION_SIZE] = BflParticipantSelection.MAX_SUGGESTED_PEOPLE.ToString(CultureInfo.InvariantCulture),
|
||||
[BflPromptTemplate.DETAILS] = Details(BflStep.STRATEGY, earlierForms, null),
|
||||
[BflPromptTemplate.PARTICIPANTS] = list.Length is 0 ? "Die Liste ist leer." : list
|
||||
}).ReplaceLineEndings(LINE_BREAK.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts together the request which asks the model once to correct its suggestion of whom to research.
|
||||
/// </summary>
|
||||
/// <param name="problems">What is wrong with the suggestion, see BflParticipantSelectionCheck.Problems.</param>
|
||||
/// <returns>The request.</returns>
|
||||
public static string ComposeParticipantSelectionRepairRequest(IReadOnlyList<string> problems)
|
||||
{
|
||||
var text = new StringBuilder("Das Lab konnte deine Auswahl nicht übernehmen:").Append(LINE_BREAK);
|
||||
foreach (var problem in problems)
|
||||
text.Append("- ").Append(problem).Append(LINE_BREAK);
|
||||
|
||||
return text.Append(LINE_BREAK).Append("Antworte noch einmal nur mit dem JSON-Objekt in der verlangten Form, und nur mit Namen aus der Liste.").ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Describes the person an agent of the research on people looks into, as the list of participants gives them.
|
||||
/// </summary>
|
||||
/// <param name="participant">The person.</param>
|
||||
private static string Person(BflParticipant participant)
|
||||
{
|
||||
var text = new StringBuilder("Name: ").Append(participant.Name).Append(LINE_BREAK).Append(LINE_BREAK);
|
||||
var entry = participant.Entry.Trim();
|
||||
return (entry.Length is 0
|
||||
? text.Append("Die Liste nennt nur den Namen.")
|
||||
: text.Append("Eintrag in der Liste:").Append(LINE_BREAK).Append(entry.ReplaceLineEndings(LINE_BREAK.ToString()))).ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists what the earlier stages of a research on a person found, each with its title and the day it was done.
|
||||
/// </summary>
|
||||
/// <param name="earlierStages">The earlier stages, in their order.</param>
|
||||
private static string EarlierStages(IReadOnlyList<BflPersonStageResearch> earlierStages)
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
foreach (var stage in earlierStages.Where(stage => stage.Research.Text.Trim().Length > 0))
|
||||
{
|
||||
if (text.Length > 0)
|
||||
text.Append(LINE_BREAK);
|
||||
|
||||
text.Append($"<stufe titel=\"{stage.Stage.Title}\" stand=\"{stage.Research.CreatedAtUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}\">").Append(LINE_BREAK);
|
||||
text.Append(stage.Research.Text.Trim().ReplaceLineEndings(LINE_BREAK.ToString())).Append(LINE_BREAK).Append("</stufe>").Append(LINE_BREAK);
|
||||
}
|
||||
|
||||
return text.Length is 0 ? "Du bist die erste Stufe; es gibt noch keine Ergebnisse." : text.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the public details about the event from the forms of a preparation: the only details a research receives.
|
||||
/// </summary>
|
||||
@@ -164,13 +266,15 @@ public static class BflPromptComposer
|
||||
/// The other steps leave the research out: what the person takes over from it, such as the participants, reaches
|
||||
/// them through the confirmed work state of the step "Strategy". A research whose public details changed since is
|
||||
/// marked, so that the model checks it with the person. The research comes in the order of its topics, each with
|
||||
/// the day it was done. For an event which is not public, an earlier research no longer counts: the person said
|
||||
/// that its details are not public, see BflEventVisibility.
|
||||
/// the day it was done, followed by the research on single people with their stages, in the order of the list. For
|
||||
/// an event which is not public, an earlier research no longer counts: the person said that its details are not
|
||||
/// public, see BflEventVisibility.
|
||||
/// </remarks>
|
||||
/// <param name="step">The step the chat belongs to.</param>
|
||||
/// <param name="research">The research of the preparation, by its topics.</param>
|
||||
/// <param name="people">The research on single people of the list of participants, in the order of the list.</param>
|
||||
/// <param name="forms">The forms of the preparation, by their steps.</param>
|
||||
private static string Research(BflStep step, IReadOnlyDictionary<BflResearchTopic, BflResearch> research, IReadOnlyDictionary<BflStep, BflStepFormData> forms)
|
||||
private static string Research(BflStep step, IReadOnlyDictionary<BflResearchTopic, BflResearch> research, IReadOnlyList<BflPersonResearch> people, IReadOnlyDictionary<BflStep, BflStepFormData> forms)
|
||||
{
|
||||
if (step is not BflStep.STRATEGY)
|
||||
return "Die Recherche nutzt der Schritt „Strategie“. Was die Person daraus übernimmt, steht in dessen bestätigtem Arbeitsstand.";
|
||||
@@ -195,6 +299,27 @@ public static class BflPromptComposer
|
||||
text.Append(found.Text.Trim().ReplaceLineEndings(LINE_BREAK.ToString())).Append(LINE_BREAK).Append("</thema>").Append(LINE_BREAK);
|
||||
}
|
||||
|
||||
foreach (var person in people.Where(person => person.Stages.Any(stage => stage.Research.Text.Trim().Length > 0)))
|
||||
{
|
||||
if (text.Length > 0)
|
||||
text.Append(LINE_BREAK);
|
||||
|
||||
text.Append($"<person name=\"{person.Name}\">").Append(LINE_BREAK);
|
||||
if (person.IsOutdated(details))
|
||||
text.Append("(Die öffentlichen Angaben haben sich seit dieser Recherche geändert. Sie passt womöglich nicht mehr zur Veranstaltung.)").Append(LINE_BREAK);
|
||||
|
||||
if (!person.IsComplete)
|
||||
text.Append("(Diese Recherche endete vor ihrer letzten Stufe; es fehlen Teile.)").Append(LINE_BREAK);
|
||||
|
||||
foreach (var stage in person.Stages.Where(stage => stage.Research.Text.Trim().Length > 0))
|
||||
{
|
||||
text.Append($"<stufe titel=\"{stage.Stage.Title}\" stand=\"{stage.Research.CreatedAtUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)}\">").Append(LINE_BREAK);
|
||||
text.Append(stage.Research.Text.Trim().ReplaceLineEndings(LINE_BREAK.ToString())).Append(LINE_BREAK).Append("</stufe>").Append(LINE_BREAK);
|
||||
}
|
||||
|
||||
text.Append("</person>").Append(LINE_BREAK);
|
||||
}
|
||||
|
||||
return text.Length is 0 ? "Es gibt noch keine Recherche." : text.ToString().TrimEnd();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user