fix weight ai insight target weight data using mr. mike instead of cp707
This commit is contained in:
1 parent
bc2b260065
commit
05465b0382
5 files changed
+83
-11
No files matched your search
@@ -776,6 +776,36 @@ def enforce_mortality_wording(
|
||||
return out
|
||||
|
||||
|
||||
def enforce_bw_wording(
|
||||
parsed: dict[str, Any],
|
||||
graded: dict[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
"""Ensure body weight status and narrative match graded facts."""
|
||||
bw = ((graded or {}).get("analyses") or {}).get("bw") or {}
|
||||
status = str(bw.get("status") or "").lower()
|
||||
if not status:
|
||||
return parsed
|
||||
|
||||
message = str(bw.get("message") or "").strip()
|
||||
actual = bw.get("actual")
|
||||
std = bw.get("standard")
|
||||
|
||||
out = dict(parsed)
|
||||
kesimpulan = str(out.get("kesimpulan") or "")
|
||||
|
||||
# If graded status is OK, but summary claims it is below standard / critical:
|
||||
if status == "ok" and any(
|
||||
w in kesimpulan.lower()
|
||||
for w in ("di bawah standar", "sangat rendah", "critical", "kritis", "jauh di bawah")
|
||||
):
|
||||
if message:
|
||||
out["kesimpulan"] = message
|
||||
elif actual is not None and std is not None:
|
||||
out["kesimpulan"] = f"Bobot badan ayam ({actual:g}g) sesuai dengan target standar ({std:g}g)."
|
||||
|
||||
return out
|
||||
|
||||
|
||||
_DUP_KANDANG = re.compile(r"\b[Kk]andang(?:\s+[Kk]andang)+\b")
|
||||
|
||||
|
||||
@@ -1111,6 +1141,7 @@ def generate_insight(
|
||||
"insight": str(parsed_raw.get("insight") or ""),
|
||||
}
|
||||
soft = enforce_mortality_wording(soft, graded)
|
||||
soft = enforce_bw_wording(soft, graded)
|
||||
soft = sanitize_insight_narrative(soft)
|
||||
parsed_raw["kesimpulan"] = soft.get("kesimpulan")
|
||||
parsed_raw["insight"] = soft.get("insight")
|
||||
@@ -1143,6 +1174,7 @@ def generate_insight(
|
||||
"Output LLM tidak sesuai format JSON yang diminta: " + repr(str(raw)[:200])
|
||||
)
|
||||
parsed = enforce_mortality_wording(parsed, graded)
|
||||
parsed = enforce_bw_wording(parsed, graded)
|
||||
parsed = sanitize_insight_narrative(parsed)
|
||||
insight_text = parsed["insight"]
|
||||
summary = parsed["kesimpulan"]
|
||||
|
||||
Reference in new issue
Block a user