Spaces:
Running
Running
Commit ·
5f66427
1
Parent(s): 0a9f3b7
Fixed context bleeding and revised system prompt.
Browse files
app.py
CHANGED
|
@@ -53,7 +53,7 @@ def generate_flowchart(src_code: str) -> str:
|
|
| 53 |
1. OUTPUT FORMAT: Output ONLY valid, raw Mermaid.js syntax.
|
| 54 |
2. NO MARKDOWN FENCING: Do not wrap the output in ```mermaid or ``` blocks. Start directly with the Mermaid graph definition, for example: graph TD.
|
| 55 |
3. NO PROSE: Do not include introductory text, explanations, or concluding remarks. If the code cannot be parsed, output an isolated error node.
|
| 56 |
-
4. NODE NAMING:
|
| 57 |
</constraints>
|
| 58 |
|
| 59 |
<banned_vocabulary>
|
|
@@ -94,6 +94,9 @@ def generate_flowchart(src_code: str) -> str:
|
|
| 94 |
B -- False --> D[Return 'Inactive']
|
| 95 |
""").strip()
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
# Casting else PyLance gets mad
|
| 98 |
response = cast(Any, llm.create_chat_completion(
|
| 99 |
messages=[
|
|
@@ -109,9 +112,12 @@ def generate_flowchart(src_code: str) -> str:
|
|
| 109 |
|
| 110 |
# remove the thinking tags from the response
|
| 111 |
cleaned = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
|
| 112 |
-
|
| 113 |
-
#
|
| 114 |
cleaned = cleaned.replace('"', "'")
|
|
|
|
|
|
|
|
|
|
| 115 |
return cleaned.strip() # and remove excess whitespace
|
| 116 |
|
| 117 |
# ----- Custom Frontend ----- #
|
|
|
|
| 53 |
1. OUTPUT FORMAT: Output ONLY valid, raw Mermaid.js syntax.
|
| 54 |
2. NO MARKDOWN FENCING: Do not wrap the output in ```mermaid or ``` blocks. Start directly with the Mermaid graph definition, for example: graph TD.
|
| 55 |
3. NO PROSE: Do not include introductory text, explanations, or concluding remarks. If the code cannot be parsed, output an isolated error node.
|
| 56 |
+
4. NODE NAMING: Paraphrase conditions into plain words — never put raw code, operators, quotes, or parentheses inside labels (write Index in bounds?, not i < len(nums))
|
| 57 |
</constraints>
|
| 58 |
|
| 59 |
<banned_vocabulary>
|
|
|
|
| 94 |
B -- False --> D[Return 'Inactive']
|
| 95 |
""").strip()
|
| 96 |
|
| 97 |
+
# Reset the cache per request so no cross-request bleeding
|
| 98 |
+
llm.reset()
|
| 99 |
+
|
| 100 |
# Casting else PyLance gets mad
|
| 101 |
response = cast(Any, llm.create_chat_completion(
|
| 102 |
messages=[
|
|
|
|
| 112 |
|
| 113 |
# remove the thinking tags from the response
|
| 114 |
cleaned = re.sub(r'<thinking>.*?</thinking>', '', content, flags=re.DOTALL)
|
| 115 |
+
|
| 116 |
+
# Remove raw quotes on both parentheses and non-parentheses
|
| 117 |
cleaned = cleaned.replace('"', "'")
|
| 118 |
+
cleaned = re.sub(r'\[([^\[\]]+)\]', r'["\g<1>"]', cleaned)
|
| 119 |
+
cleaned = re.sub(r'\{([^{}]+)\}', r'{"\g<1>"}', cleaned)
|
| 120 |
+
|
| 121 |
return cleaned.strip() # and remove excess whitespace
|
| 122 |
|
| 123 |
# ----- Custom Frontend ----- #
|