mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-08-24 20:52:11 +00:00
developed a JSON contract for charts and injected it into the main system prompt
This commit is contained in:
parent
f54deb287a
commit
191be98031
@ -13,6 +13,34 @@ namespace AIStudio.Chat;
|
|||||||
public sealed record ChatThread
|
public sealed record ChatThread
|
||||||
{
|
{
|
||||||
private static readonly ILogger<ChatThread> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ChatThread>();
|
private static readonly ILogger<ChatThread> LOGGER = Program.LOGGER_FACTORY.CreateLogger<ChatThread>();
|
||||||
|
|
||||||
|
private const string CHART_OUTPUT_INSTRUCTIONS = """
|
||||||
|
When a chart is useful or explicitly requested, you may include one or more complete chart blocks in your normal response. Use exactly this fenced JSON format:
|
||||||
|
```aistudio-chart
|
||||||
|
{
|
||||||
|
"schema_version": 1,
|
||||||
|
"type": "bar",
|
||||||
|
"title": "Chart title",
|
||||||
|
"caption": "Contextual interpretation of the chart",
|
||||||
|
"data": {
|
||||||
|
"categories": ["A", "B"],
|
||||||
|
"series": [
|
||||||
|
{
|
||||||
|
"name": "Series",
|
||||||
|
"values": [1, 2]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- Supported types are `bar`, `stacked_bar`, `line`, `pie`, and `donut`.
|
||||||
|
- Every series needs exactly one finite numeric value per category.
|
||||||
|
- Pie and donut charts need exactly one series and non-negative values.
|
||||||
|
- Add a concise caption that correctly contextualizes the chart and may explain the chart's main finding.
|
||||||
|
- Use only the fields shown above.
|
||||||
|
- Keep other explanatory text outside the chart block.
|
||||||
|
""";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unique identifier of the chat thread.
|
/// The unique identifier of the chat thread.
|
||||||
@ -56,6 +84,12 @@ public sealed record ChatThread
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IncludeDateTime { get; set; } = false;
|
public bool IncludeDateTime { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates whether the model may emit locally rendered chart blocks.
|
||||||
|
/// False by default so internal structured model requests remain unchanged.
|
||||||
|
/// </summary>
|
||||||
|
public bool AllowChartOutput { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The data source options for this chat thread.
|
/// The data source options for this chat thread.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -198,23 +232,32 @@ public sealed record ChatThread
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.LogInformation(logMessage);
|
LOGGER.LogInformation(logMessage);
|
||||||
if(!this.IncludeDateTime)
|
if(this.IncludeDateTime)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Prepend the current date and time to the system prompt:
|
||||||
|
//
|
||||||
|
var nowUtc = DateTime.UtcNow;
|
||||||
|
var nowLocal = DateTime.Now;
|
||||||
|
var currentDateTime = string.Create(
|
||||||
|
new CultureInfo("en-US"),
|
||||||
|
$"Today is {nowUtc:dddd, MMMM d, yyyy h:mm tt} (UTC) and {nowLocal:dddd, MMMM d, yyyy h:mm tt} (local time)."
|
||||||
|
);
|
||||||
|
|
||||||
|
systemPromptText = $"""
|
||||||
|
{currentDateTime}
|
||||||
|
|
||||||
|
{systemPromptText}
|
||||||
|
""";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.AllowChartOutput)
|
||||||
return systemPromptText;
|
return systemPromptText;
|
||||||
|
|
||||||
//
|
|
||||||
// Prepend the current date and time to the system prompt:
|
|
||||||
//
|
|
||||||
var nowUtc = DateTime.UtcNow;
|
|
||||||
var nowLocal = DateTime.Now;
|
|
||||||
var currentDateTime = string.Create(
|
|
||||||
new CultureInfo("en-US"),
|
|
||||||
$"Today is {nowUtc:dddd, MMMM d, yyyy h:mm tt} (UTC) and {nowLocal:dddd, MMMM d, yyyy h:mm tt} (local time)."
|
|
||||||
);
|
|
||||||
|
|
||||||
return $"""
|
return $"""
|
||||||
{currentDateTime}
|
|
||||||
|
|
||||||
{systemPromptText}
|
{systemPromptText}
|
||||||
|
|
||||||
|
{CHART_OUTPUT_INSTRUCTIONS}
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,4 +357,4 @@ public sealed record ChatThread
|
|||||||
|
|
||||||
return new Tools.ERIClient.DataModel.ChatThread { ContentBlocks = contentBlocks };
|
return new Tools.ERIClient.DataModel.ChatThread { ContentBlocks = contentBlocks };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user