Skip to content

Commit 0ba5127

Browse files
rajbosCopilot
andcommitted
fix: correct Python dict syntax in generate-names step
The {{ and }} brace-doubling was carried over from f-string escaping convention but applied to regular Python dict literals (not f-strings). In plain Python code, {{ is two separate { tokens, so payload = {{...}} creates a set containing a dict, crashing with: TypeError: unhashable type: 'dict' Fixes: - payload dict literal: {{ -> {, }} -> } - options sub-dict: same - headers dict: same - fallback empty dict {{}} -> {} - fallback JSON regex pattern corrected to match single braces - f-string variables now expand correctly (e.g. {k!r} not {{k!r}}) - error message f-string now expands {e} correctly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 521b349 commit 0ba5127

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

.github/workflows/check-toolnames.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,35 +341,35 @@ jobs:
341341
"OUTPUT: JSON object only, no explanation.",
342342
])
343343
344-
payload = {{
344+
payload = {
345345
"model": "qwen2.5:1.5b",
346346
"prompt": prompt,
347347
"format": "json",
348348
"stream": False,
349-
"options": {{"temperature": 0, "seed": 42}}
350-
}}
349+
"options": {"temperature": 0, "seed": 42}
350+
}
351351
352352
print("=== Calling Ollama API ===", file=sys.stderr)
353353
req = urllib.request.Request(
354354
"http://localhost:11434/api/generate",
355355
data=json.dumps(payload).encode(),
356-
headers={{"Content-Type": "application/json"}}
356+
headers={"Content-Type": "application/json"}
357357
)
358358
359359
try:
360360
with urllib.request.urlopen(req, timeout=180) as resp:
361361
data = json.loads(resp.read())
362-
raw_response = data.get("response", "{{}}")
363-
print(f"=== SLM response ===\n{{raw_response}}", file=sys.stderr)
362+
raw_response = data.get("response", "{}")
363+
print(f"=== SLM response ===\n{raw_response}", file=sys.stderr)
364364
365365
try:
366366
generated = json.loads(raw_response)
367367
except json.JSONDecodeError:
368-
m = re.search(r'\{{[^{{}}]*\}}', raw_response, re.DOTALL)
369-
generated = json.loads(m.group(0)) if m else {{}}
368+
m = re.search(r'\{[^{}]*\}', raw_response, re.DOTALL)
369+
generated = json.loads(m.group(0)) if m else {}
370370
371371
# Only keep entries for the tool IDs we asked about; sanitize values.
372-
validated = {{}}
372+
validated = {}
373373
for tool in missing_tools:
374374
friendly = str(generated.get(tool, "")).strip()
375375
if not friendly or len(friendly) > 200:
@@ -381,14 +381,14 @@ jobs:
381381
382382
print("=== Validated names ===", file=sys.stderr)
383383
for k, v in validated.items():
384-
print(f" {{k!r}} -> {{v!r}}", file=sys.stderr)
384+
print(f" {k!r} -> {v!r}", file=sys.stderr)
385385
386386
with open("/tmp/slm-names.json", "w") as f:
387387
json.dump(validated, f, indent=2)
388388
print("✅ SLM generation complete", file=sys.stderr)
389389
390390
except Exception as e:
391-
print(f"❌ SLM error: {{e}}", file=sys.stderr)
391+
print(f"❌ SLM error: {e}", file=sys.stderr)
392392
import traceback; traceback.print_exc(file=sys.stderr)
393393
sys.exit(1)
394394
PYEOF

0 commit comments

Comments
 (0)