From ef41b6b30ab3e160a30fd4308af5c4fb97f61e04 Mon Sep 17 00:00:00 2001 From: Ethan J Lewis Date: Sun, 19 Apr 2026 22:18:10 -0500 Subject: [PATCH] enhancements --- tag-notes.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tag-notes.py b/tag-notes.py index 698be6d..8e65116 100755 --- a/tag-notes.py +++ b/tag-notes.py @@ -89,7 +89,7 @@ def parse_json_response(content): return None -def call_llm_json(system_prompt, user_prompt, max_tokens=900): +def call_llm_json(system_prompt, user_prompt, max_tokens=4000): payload = { "model": MODEL_NAME, "messages": [ @@ -101,14 +101,22 @@ def call_llm_json(system_prompt, user_prompt, max_tokens=900): "response_format": {"type": "text"}, } try: - response = requests.post(LM_STUDIO_URL, json=payload, timeout=120) + response = requests.post(LM_STUDIO_URL, json=payload, timeout=600) if not response.ok: print(f" ! LLM error: {response.status_code} {response.reason}") print(f" body: {response.text[:500]}") return None result = response.json() - content = result['choices'][0]['message']['content'] - return parse_json_response(content) + choice = result['choices'][0] + content = choice['message'].get('content') or '' + parsed = parse_json_response(content) + if parsed is None: + finish = choice.get('finish_reason') + print(f" ! LLM returned no parseable JSON (finish_reason={finish})") + if finish == 'length': + print(" Hit max_tokens — reasoning model burned the budget before emitting output.") + print(f" content: {content[:500]!r}") + return parsed except Exception as e: print(f" ! LLM error: {e}") return None @@ -161,7 +169,7 @@ Your previous description was {len(previous_desc)} characters, outside the allow "{previous_desc}" Rewrite it to fit strictly within {SEO_DESC_MIN}-{SEO_DESC_MAX} characters.""" - result = call_llm_json(system_prompt, user_prompt, max_tokens=400) + result = call_llm_json(system_prompt, user_prompt) if result: return (result.get('seo_description') or '').strip() return ''