Harden AI writer response handling

This commit is contained in:
Your Name
2026-06-17 13:44:25 +05:00
parent 969ee11eed
commit 86ff75adbd
2 changed files with 23 additions and 1 deletions
+4 -1
View File
@@ -41,6 +41,7 @@ Rules:
- Pick exactly one category from the categories list in input and return its numeric id as category_id.
- Do not add links or hashtags to rewritten text.
- Return JSON only. No markdown. No text outside JSON.
- Never return an empty object. Never omit the "rewrites" key.
- Return one rewrite for every input post id.
- The "text" field must be a ready-to-publish Russian post with normal paragraph line breaks encoded as JSON string newlines.
- The "notes" field must be a short editor note in Russian or null.
@@ -434,6 +435,8 @@ class AIWriterWorker:
for p in posts
}
batch_id = await self.create_batch(provider, model, prompt, payload)
response = None
usage = None
try:
response, usage = await self.call_ai(provider, model, api_key, api_base, prompt, payload, temperature, timeout)
rewrites = validate_rewrites(response, set(post_ids), categories, source_tags_by_id)
@@ -443,7 +446,7 @@ class AIWriterWorker:
return True
except Exception as exc:
await self.mark_posts_failed(post_ids, str(exc))
await self.finish_batch(batch_id, "failed", error=str(exc))
await self.finish_batch(batch_id, "failed", response=response, error=str(exc), usage=usage)
logger.exception("AI writer batch failed: id={} error={}", batch_id, exc)
return True