Spaces:
Sleeping
Sleeping
Commit ·
b39d4f9
1
Parent(s): 10d85d6
Fix parse_action: use brace-depth JSON extraction, raise max_tokens to 1500
Browse filesOld regex [^{}]* failed to capture multiline script payloads, causing
edit_script actions to arrive with empty payload — no actual edit happened.
New parser tracks brace depth to correctly extract the full JSON object.
Also raise max_tokens 800→1500 so full script replacements fit in one reply.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- gradio_app.py +20 -10
gradio_app.py
CHANGED
|
@@ -640,15 +640,25 @@ CRITICAL RULES:
|
|
| 640 |
- Stage 4: add class_weight='balanced' to LogisticRegression"""
|
| 641 |
|
| 642 |
def parse_action(raw_text):
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
for atype in ["edit_script", "run_script", "submit", "inspect_data", "query_actor"]:
|
| 653 |
if atype in raw_text:
|
| 654 |
return {"action_type": atype, "payload": {}}
|
|
@@ -693,7 +703,7 @@ CRITICAL RULES:
|
|
| 693 |
response = client.chat.completions.create(
|
| 694 |
model="llama-3.1-8b-instant",
|
| 695 |
messages=trimmed,
|
| 696 |
-
max_tokens=
|
| 697 |
temperature=0.2,
|
| 698 |
)
|
| 699 |
raw = response.choices[0].message.content.strip()
|
|
|
|
| 640 |
- Stage 4: add class_weight='balanced' to LogisticRegression"""
|
| 641 |
|
| 642 |
def parse_action(raw_text):
|
| 643 |
+
# Find the outermost JSON object by tracking brace depth
|
| 644 |
+
start = raw_text.find('{')
|
| 645 |
+
if start != -1:
|
| 646 |
+
depth = 0
|
| 647 |
+
for i, ch in enumerate(raw_text[start:], start):
|
| 648 |
+
if ch == '{':
|
| 649 |
+
depth += 1
|
| 650 |
+
elif ch == '}':
|
| 651 |
+
depth -= 1
|
| 652 |
+
if depth == 0:
|
| 653 |
+
candidate = raw_text[start:i+1]
|
| 654 |
+
try:
|
| 655 |
+
action = json.loads(candidate)
|
| 656 |
+
if "action_type" in action:
|
| 657 |
+
action.setdefault("payload", {})
|
| 658 |
+
return action
|
| 659 |
+
except json.JSONDecodeError:
|
| 660 |
+
pass
|
| 661 |
+
break
|
| 662 |
for atype in ["edit_script", "run_script", "submit", "inspect_data", "query_actor"]:
|
| 663 |
if atype in raw_text:
|
| 664 |
return {"action_type": atype, "payload": {}}
|
|
|
|
| 703 |
response = client.chat.completions.create(
|
| 704 |
model="llama-3.1-8b-instant",
|
| 705 |
messages=trimmed,
|
| 706 |
+
max_tokens=1500,
|
| 707 |
temperature=0.2,
|
| 708 |
)
|
| 709 |
raw = response.choices[0].message.content.strip()
|