Fix summary LLM call: use raw chat text, not classifier-JSON parsing
client._chat() JSON-parses every response (for the classifier), so the plain-text
summary was rejected ("model did not return JSON") even though the model returned
a perfect summary. Split out _raw_content() and add chat_text() for free-form
output; summaries use it. _chat keeps parsing for classification.
This commit is contained in:
+13
-3
@@ -206,7 +206,15 @@ class LocalModelClient:
|
||||
names.append(str(model["id"]))
|
||||
return names
|
||||
|
||||
def _chat(self, payload: dict) -> dict:
|
||||
def chat_text(self, messages: list[dict]) -> str:
|
||||
"""Plain chat completion → the raw message text (no JSON parsing).
|
||||
|
||||
Used for free-form output like summaries; classification uses _chat,
|
||||
which JSON-parses the same content.
|
||||
"""
|
||||
return self._raw_content(self._build_payload(messages, None))
|
||||
|
||||
def _raw_content(self, payload: dict) -> str:
|
||||
body = json.dumps(payload).encode("utf-8")
|
||||
headers = {"Content-Type": "application/json"}
|
||||
if self.api_key:
|
||||
@@ -227,10 +235,12 @@ class LocalModelClient:
|
||||
raise RuntimeError(f"could not reach local model at {self.base_url}: {exc.reason}") from exc
|
||||
|
||||
try:
|
||||
content = data["choices"][0]["message"]["content"]
|
||||
return data["choices"][0]["message"]["content"]
|
||||
except (KeyError, IndexError, TypeError) as exc:
|
||||
raise RuntimeError(f"unexpected local model response: {data}") from exc
|
||||
return parse_classifier_json(content)
|
||||
|
||||
def _chat(self, payload: dict) -> dict:
|
||||
return parse_classifier_json(self._raw_content(payload))
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
Reference in New Issue
Block a user