Spaces:
Build error
Build error
vibe coding lead to a very lazy and wrong application of constrained decoding - simply cutting off the llm after a closing brace, bad bad bad - also I'm not sure why it was trying to deliver json at all, this plays to all of the weaknesses of gen ai, bad llm bad
Browse files
app.py
CHANGED
@@ -106,14 +106,9 @@ def on_submit(symptoms_text, history):
|
|
106 |
yield history, None, "\n".join(log)
|
107 |
|
108 |
# Call LLM
|
109 |
-
|
110 |
-
response = llm.complete(prompt, stop=["}"]) # stop after closing brace
|
111 |
raw = getattr(response, 'text', str(response))
|
112 |
-
|
113 |
-
if not raw.strip().endswith('}'):
|
114 |
-
end_idx = raw.rfind('}')
|
115 |
-
if end_idx != -1:
|
116 |
-
raw = raw[:end_idx+1]
|
117 |
msg = "π‘ Raw LLM response received"
|
118 |
log.append(msg)
|
119 |
print(msg, flush=True)
|
@@ -121,23 +116,17 @@ def on_submit(symptoms_text, history):
|
|
121 |
|
122 |
# Parse JSON
|
123 |
cleaned_raw = re.sub(r",\s*([}\]])", r"\1", raw)
|
124 |
-
try:
|
125 |
-
parsed = json.loads(cleaned_raw)
|
126 |
-
msg = "β
JSON parsed"
|
127 |
-
except Exception as e:
|
128 |
-
msg = f"β JSON parse error: {e}"
|
129 |
-
parsed = {"error": str(e), "raw": raw}
|
130 |
log.append(msg)
|
131 |
print(msg, flush=True)
|
132 |
-
yield history,
|
133 |
|
134 |
# Final assistant message
|
135 |
-
assistant_msg = format_response_for_user(
|
136 |
history = history + [{"role": "assistant", "content": assistant_msg}]
|
137 |
msg = "β
Final response appended"
|
138 |
log.append(msg)
|
139 |
print(msg, flush=True)
|
140 |
-
yield history,
|
141 |
|
142 |
# ========== Gradio UI ==========
|
143 |
with gr.Blocks(theme="default") as demo:
|
|
|
106 |
yield history, None, "\n".join(log)
|
107 |
|
108 |
# Call LLM
|
109 |
+
response = llm.complete(prompt)
|
|
|
110 |
raw = getattr(response, 'text', str(response))
|
111 |
+
|
|
|
|
|
|
|
|
|
112 |
msg = "π‘ Raw LLM response received"
|
113 |
log.append(msg)
|
114 |
print(msg, flush=True)
|
|
|
116 |
|
117 |
# Parse JSON
|
118 |
cleaned_raw = re.sub(r",\s*([}\]])", r"\1", raw)
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
log.append(msg)
|
120 |
print(msg, flush=True)
|
121 |
+
yield history, raw, "\n".join(log)
|
122 |
|
123 |
# Final assistant message
|
124 |
+
assistant_msg = format_response_for_user(raw)
|
125 |
history = history + [{"role": "assistant", "content": assistant_msg}]
|
126 |
msg = "β
Final response appended"
|
127 |
log.append(msg)
|
128 |
print(msg, flush=True)
|
129 |
+
yield history, raw, "\n".join(log)
|
130 |
|
131 |
# ========== Gradio UI ==========
|
132 |
with gr.Blocks(theme="default") as demo:
|