gpaasch commited on
Commit
0272a23
Β·
1 Parent(s): 1058d65

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
Files changed (1) hide show
  1. app.py +5 -16
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
- # Use constrained decoding to enforce JSON-only output
110
- response = llm.complete(prompt, stop=["}"]) # stop after closing brace
111
  raw = getattr(response, 'text', str(response))
112
- # Truncate extra content after the final JSON object
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, parsed, "\n".join(log)
133
 
134
  # Final assistant message
135
- assistant_msg = format_response_for_user(parsed)
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, parsed, "\n".join(log)
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: