diff --git a/engine_llm.py b/engine_llm.py index b8b7eaf..4a8804b 100644 --- a/engine_llm.py +++ b/engine_llm.py @@ -16,6 +16,7 @@ import argparse import multiprocessing import os import re +import json import requests from collections import deque @@ -102,7 +103,13 @@ def run_llm_processor(in_queue, out_queue, args): headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}, timeout=getattr(args, "post_correct_llm_timeout", 8.0), ) - response.raise_for_status() + if response.status_code >= 400: + try: + payload = response.json() + detail = json.dumps(payload, ensure_ascii=True) + except Exception: + detail = response.text.strip() + raise RuntimeError(f"OpenAI API error {response.status_code}: {detail}") return response.json()["choices"][0]["message"]["content"].strip() def call_ollama(prompt, temperature):