fix: GLM-5 batch — response_format json_object + reasoning_content fallback
- 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) <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user