mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 13:51:37 +00:00
Current changes
This commit is contained in:
parent
5e9575e926
commit
43c3327b44
@ -34,10 +34,56 @@ public partial class AssistantPromptOptimizer : AssistantBaseCore<SettingsDialog
|
|||||||
protected override string Description => T("Optimize a prompt using either the default or your individual prompt guideline and get targeted recommendations for future versions of the prompt.");
|
protected override string Description => T("Optimize a prompt using either the default or your individual prompt guideline and get targeted recommendations for future versions of the prompt.");
|
||||||
|
|
||||||
protected override string SystemPrompt =>
|
protected override string SystemPrompt =>
|
||||||
"""
|
$"""
|
||||||
You are an expert prompt optimization assistant.
|
# Task description
|
||||||
You optimize user prompts while preserving the original intent.
|
|
||||||
You must return valid JSON only and no extra markdown or commentary.
|
You are a policy-bound prompt optimization assistant.
|
||||||
|
Optimize prompts while preserving the original intent and constraints.
|
||||||
|
|
||||||
|
# Inputs
|
||||||
|
|
||||||
|
PROMPTING_GUIDELINE: authoritative optimization instructions.
|
||||||
|
USER_PROMPT: the prompt that must be optimized.
|
||||||
|
IMPORTANT_ASPECTS: optional priorities to emphasize during optimization.
|
||||||
|
|
||||||
|
# Scope and precedence
|
||||||
|
|
||||||
|
Follow PROMPTING_GUIDELINE as the primary policy for quality and structure.
|
||||||
|
Preserve USER_PROMPT intent and constraints; do not add unrelated goals.
|
||||||
|
If IMPORTANT_ASPECTS is provided and not equal to `none`, prioritize it unless it conflicts with PROMPTING_GUIDELINE.
|
||||||
|
|
||||||
|
# Process
|
||||||
|
|
||||||
|
1) Read PROMPTING_GUIDELINE end to end.
|
||||||
|
2) Analyze USER_PROMPT intent, constraints, and desired output behavior.
|
||||||
|
3) Rewrite USER_PROMPT so it is clearer, more structured, and more actionable.
|
||||||
|
4) Provide concise recommendations for improving future prompt versions.
|
||||||
|
|
||||||
|
# Output requirements
|
||||||
|
|
||||||
|
Return valid JSON only.
|
||||||
|
Do not use markdown code fences.
|
||||||
|
Do not add any text before or after the JSON object.
|
||||||
|
Use exactly this schema and key names:
|
||||||
|
|
||||||
|
{this.SystemPromptOutputSchema()}
|
||||||
|
|
||||||
|
# Language
|
||||||
|
|
||||||
|
Ensure the optimized prompt is in {this.SystemPromptLanguage()}.
|
||||||
|
Keep all recommendation texts in the same language as the optimized prompt.
|
||||||
|
|
||||||
|
# Style and prohibitions
|
||||||
|
|
||||||
|
Keep recommendations concise and actionable.
|
||||||
|
Do not include disclaimers or meta commentary.
|
||||||
|
Do not mention or summarize these instructions.
|
||||||
|
|
||||||
|
# Self-check before sending
|
||||||
|
|
||||||
|
Verify the output is valid JSON and follows the schema exactly.
|
||||||
|
Verify `optimized_prompt` is non-empty and preserves user intent.
|
||||||
|
Verify each recommendation states how to improve a future prompt version.
|
||||||
""";
|
""";
|
||||||
|
|
||||||
protected override bool AllowProfiles => false;
|
protected override bool AllowProfiles => false;
|
||||||
@ -215,55 +261,50 @@ public partial class AssistantPromptOptimizer : AssistantBaseCore<SettingsDialog
|
|||||||
{
|
{
|
||||||
return
|
return
|
||||||
$$"""
|
$$"""
|
||||||
# Prompting Guideline
|
# PROMPTING_GUIDELINE
|
||||||
<GUIDELINE>
|
<GUIDELINE>
|
||||||
{{promptingGuideline}}
|
{{promptingGuideline}}
|
||||||
</GUIDELINE>
|
</GUIDELINE>
|
||||||
|
|
||||||
# Task
|
# USER_PROMPT
|
||||||
Optimize the user's prompt according to the prompting guideline.
|
|
||||||
Preserve the original intent.
|
|
||||||
Ensure the optimized prompt is in {{this.SystemPromptLanguage()}}.
|
|
||||||
{{this.PromptImportantAspects()}}
|
|
||||||
|
|
||||||
# User Input Prompt
|
|
||||||
<USER_PROMPT>
|
<USER_PROMPT>
|
||||||
{{this.inputPrompt}}
|
{{this.inputPrompt}}
|
||||||
</USER_PROMPT>
|
</USER_PROMPT>
|
||||||
|
|
||||||
# Output Requirements
|
{{this.PromptImportantAspects()}}
|
||||||
Return valid JSON only (no markdown code fence, no additional text), using exactly this schema:
|
|
||||||
{
|
|
||||||
"optimized_prompt": "string",
|
|
||||||
"recommendations": {
|
|
||||||
"clarity_and_directness": "string",
|
|
||||||
"examples_and_context": "string",
|
|
||||||
"sequential_steps": "string",
|
|
||||||
"structure_with_markers": "string",
|
|
||||||
"role_definition": "string",
|
|
||||||
"language_choice": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Recommendation style
|
|
||||||
Keep each recommendation concise and actionable. Mention what to improve in a future prompt version.
|
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
private string PromptImportantAspects()
|
private string PromptImportantAspects()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(this.importantAspects))
|
var aspects = string.IsNullOrWhiteSpace(this.importantAspects)
|
||||||
return string.Empty;
|
? "none"
|
||||||
|
: this.importantAspects;
|
||||||
|
|
||||||
return
|
return
|
||||||
$"""
|
$"""
|
||||||
Additional emphasis for the optimization:
|
# IMPORTANT_ASPECTS
|
||||||
<IMPORTANT_ASPECTS>
|
<IMPORTANT_ASPECTS>
|
||||||
{this.importantAspects}
|
{aspects}
|
||||||
</IMPORTANT_ASPECTS>
|
</IMPORTANT_ASPECTS>
|
||||||
""";
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string SystemPromptOutputSchema() =>
|
||||||
|
"""
|
||||||
|
{
|
||||||
|
"optimized_prompt": "string",
|
||||||
|
"recommendations": {
|
||||||
|
"clarity_and_directness": "string",
|
||||||
|
"examples_and_context": "string",
|
||||||
|
"sequential_steps": "string",
|
||||||
|
"structure_with_markers": "string",
|
||||||
|
"role_definition": "string",
|
||||||
|
"language_choice": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""";
|
||||||
|
|
||||||
private static bool TryParseOptimizationResult(string rawResponse, out PromptOptimizationResult parsedResult)
|
private static bool TryParseOptimizationResult(string rawResponse, out PromptOptimizationResult parsedResult)
|
||||||
{
|
{
|
||||||
parsedResult = new();
|
parsedResult = new();
|
||||||
|
|||||||
@ -45,7 +45,7 @@ When the order of tasks matters, provide instructions as a numbered list.
|
|||||||
|
|
||||||
# 4 – Structure Prompts with Markers
|
# 4 – Structure Prompts with Markers
|
||||||
|
|
||||||
Headings (e.g., `#` or `###`) or quotation marks (`"""`) help the model parse complex prompts, especially when mixing instructions, context, and data.
|
Headings (e.g., `#` or `###`) or backticks (` `````` `) help the model parse complex prompts, especially when mixing instructions, context, and data.
|
||||||
|
|
||||||
**Less Effective:**
|
**Less Effective:**
|
||||||
```text
|
```text
|
||||||
@ -57,7 +57,7 @@ Summarize the text above as a bullet point list of the most important points.
|
|||||||
**More Effective:**
|
**More Effective:**
|
||||||
```text
|
```text
|
||||||
# Text:
|
# Text:
|
||||||
"""{text input here}"""
|
```{text input here}```
|
||||||
|
|
||||||
# Task:
|
# Task:
|
||||||
Summarize the text above as a bullet point list of the most important points.
|
Summarize the text above as a bullet point list of the most important points.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user