Spaces:
Running on Zero
Running on Zero
atakan commited on
Commit ·
a5c67b7
1
Parent(s): 9b35e00
fix: Enforce Python tool execution for plots and sanitize raw LaTeX figure tags in Web UI
Browse files- controlai_agent/prompts.py +6 -4
- web/app.js +21 -0
- web/index.html +1 -1
controlai_agent/prompts.py
CHANGED
|
@@ -14,8 +14,10 @@ When answering theoretical principles, derivations, proofs, comparisons, or limi
|
|
| 14 |
|
| 15 |
### Strict Negative & Formatting Constraints:
|
| 16 |
1. **ZERO EMOJIS**: NEVER use any emojis anywhere in your response (absolutely NO checkmarks, NO pins, NO graphs, NO rockets, NO lightbulbs).
|
| 17 |
-
2. **
|
| 18 |
-
3. **
|
| 19 |
-
4. **
|
| 20 |
-
5. **
|
|
|
|
|
|
|
| 21 |
"""
|
|
|
|
| 14 |
|
| 15 |
### Strict Negative & Formatting Constraints:
|
| 16 |
1. **ZERO EMOJIS**: NEVER use any emojis anywhere in your response (absolutely NO checkmarks, NO pins, NO graphs, NO rockets, NO lightbulbs).
|
| 17 |
+
2. **NO RAW LATEX DOCUMENT TAGS**: NEVER output `\begin{figure}`, `\includegraphics`, `\caption`, `\centering`, `\section*`, or `\end{figure}`. You are generating web markdown, not a PDF compilation. Use standard markdown headers (e.g. `### Section Title`).
|
| 18 |
+
3. **MANDATORY TOOL CALL FOR PLOTS**: When asked to plot, visualize, or simulate (Nyquist plot, Bode diagram, Root Locus, Step Response, Phase Portrait), NEVER hallucinate a fake image filename. You MUST explicitly call `execute_python_code` (using `control as ct` or `matplotlib.pyplot`) or `simulate_step_response` to generate and display the real plot!
|
| 19 |
+
4. **Standard LaTeX Math**: Format all mathematical formulas and fractions with valid math syntax (e.g. `$\frac{\omega_n^2}{s^2 + 2\zeta\omega_n s + \omega_n^2}$`).
|
| 20 |
+
5. **Deterministic Grounding**: When a tool executes successfully, present the exact numerical results and generated plot.
|
| 21 |
+
6. **No Infinite Retries**: If a tool returns an error, correct the parameters or synthesize the analytical answer directly.
|
| 22 |
+
7. **No Forced Citations**: Do NOT cite arbitrary random file paths unless the user explicitly requests literature references.
|
| 23 |
"""
|
web/app.js
CHANGED
|
@@ -145,6 +145,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 145 |
const mathPlaceholders = [];
|
| 146 |
let text = rawText;
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
// 1. Extract Display Math: $$ ... $$
|
| 149 |
text = text.replace(/\$\$([\s\S]*?)\$\$/g, (match, formula) => {
|
| 150 |
const ph = `@@MATH_BLOCK_${mathPlaceholders.length}@@`;
|
|
|
|
| 145 |
const mathPlaceholders = [];
|
| 146 |
let text = rawText;
|
| 147 |
|
| 148 |
+
// Clean up any raw LaTeX document structure artifacts
|
| 149 |
+
text = text.replace(/\\section\*?\{([\s\S]*?)\}/g, '### $1\n\n');
|
| 150 |
+
text = text.replace(/\\subsection\*?\{([\s\S]*?)\}/g, '#### $1\n\n');
|
| 151 |
+
text = text.replace(/\\subsubsection\*?\{([\s\S]*?)\}/g, '##### $1\n\n');
|
| 152 |
+
text = text.replace(/\\begin\{figure\}[\s\S]*?\\end\{figure\}/g, (match) => {
|
| 153 |
+
const capMatch = match.match(/\\caption\{([\s\S]*?)\}/);
|
| 154 |
+
const imgMatch = match.match(/\\includegraphics.*?\{([^\}]+)\}/);
|
| 155 |
+
let out = '';
|
| 156 |
+
if (imgMatch) {
|
| 157 |
+
const fname = imgMatch[1].trim();
|
| 158 |
+
out += `\n\n![${capMatch ? capMatch[1] : 'Simulation Plot'}](/plots/${fname})\n\n`;
|
| 159 |
+
}
|
| 160 |
+
if (capMatch && !imgMatch) {
|
| 161 |
+
out += `\n\n*${capMatch[1]}*\n\n`;
|
| 162 |
+
}
|
| 163 |
+
return out;
|
| 164 |
+
});
|
| 165 |
+
text = text.replace(/\\(centering|begin\{center\}|end\{center\})/g, '');
|
| 166 |
+
text = text.replace(/\\includegraphics.*?\{([^\}]+)\}/g, '');
|
| 167 |
+
text = text.replace(/\\caption\{([\s\S]*?)\}/g, '*$1*');
|
| 168 |
+
|
| 169 |
// 1. Extract Display Math: $$ ... $$
|
| 170 |
text = text.replace(/\$\$([\s\S]*?)\$\$/g, (match, formula) => {
|
| 171 |
const ph = `@@MATH_BLOCK_${mathPlaceholders.length}@@`;
|
web/index.html
CHANGED
|
@@ -226,6 +226,6 @@
|
|
| 226 |
</div>
|
| 227 |
</div>
|
| 228 |
|
| 229 |
-
<script src="/static/app.js?v=
|
| 230 |
</body>
|
| 231 |
</html>
|
|
|
|
| 226 |
</div>
|
| 227 |
</div>
|
| 228 |
|
| 229 |
+
<script src="/static/app.js?v=20260819_figure_sanitize"></script>
|
| 230 |
</body>
|
| 231 |
</html>
|