enhancements
This commit is contained in:
+13
-5
@@ -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 ''
|
||||
|
||||
Reference in New Issue
Block a user