From 7aff3baf89fa9eb982fc4424db898d6d11873cee Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 25 Mar 2026 19:37:45 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20GLM-5=20batch=20=E2=80=94=20response=5Ff?= =?UTF-8?q?ormat=20json=5Fobject=20+=20reasoning=5Fcontent=20fallback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - response_format: {"type": "json_object"} для строгого JSON - system prompt: "только валидный JSON" - fallback на reasoning_content (GLM-5 может вернуть туда ответ) - timeout 300с для batch-анализа Sources: docs.z.ai/guides/capabilities/struct-output Co-Authored-By: Claude Opus 4.6 (1M context) --- batch.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/batch.py b/batch.py index fc54c68..7229ba9 100644 --- a/batch.py +++ b/batch.py @@ -144,19 +144,24 @@ async def analyze_structure(sample_files: list[str], target_file: str, task_desc }}""" proxy = os.environ.get("HTTPS_PROXY") or os.environ.get("HTTP_PROXY") - async with httpx.AsyncClient(timeout=120, proxy=proxy) as client: + async with httpx.AsyncClient(timeout=300, proxy=proxy) as client: resp = await client.post( f"{ZAI_BASE_URL}/chat/completions", headers={"Authorization": f"Bearer {ZAI_API_KEY}"}, json={ "model": ZAI_MODEL, - "messages": [{"role": "user", "content": prompt}], + "messages": [ + {"role": "system", "content": "Ты генерируешь ТОЛЬКО валидный JSON. Никакого текста вне JSON."}, + {"role": "user", "content": prompt}, + ], "temperature": 0.1, "max_tokens": 4000, + "response_format": {"type": "json_object"}, }, ) resp.raise_for_status() - content = resp.json()["choices"][0]["message"]["content"] + msg = resp.json()["choices"][0]["message"] + content = msg.get("content") or msg.get("reasoning_content") or "" # Parse JSON from response try: