UPDATE
This commit is contained in:
@@ -13,6 +13,7 @@ from farm_data.models import SensorData
|
||||
from farm_data.services import get_farm_details
|
||||
from location_data.models import NdviObservation, SoilLocation
|
||||
|
||||
from rag.failure_contract import RAGServiceError
|
||||
from rag.services.yield_harvest import YieldHarvestRAGService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -119,13 +120,17 @@ class YieldHarvestSummaryService:
|
||||
try:
|
||||
rag_service = YieldHarvestRAGService()
|
||||
narrative_data = rag_service.generate_narrative(context_payload)
|
||||
except Exception as exc:
|
||||
except RAGServiceError as exc:
|
||||
logger.warning(
|
||||
"Yield harvest narrative generation failed for farm_uuid=%s: %s",
|
||||
farm_uuid,
|
||||
exc,
|
||||
)
|
||||
narrative_data = {}
|
||||
narrative_data = {
|
||||
"status": "error",
|
||||
"source": "llm",
|
||||
"narrative_error": exc.to_dict(),
|
||||
}
|
||||
return self._merge_narrative(deterministic_payload, narrative_data)
|
||||
|
||||
def _build_yield_prediction(
|
||||
@@ -703,7 +708,7 @@ class YieldHarvestSummaryService:
|
||||
) -> dict[str, Any]:
|
||||
farm = (
|
||||
SensorData.objects.select_related("center_location", "weather_forecast")
|
||||
.prefetch_related("center_location__depths", "plants")
|
||||
.prefetch_related("center_location__depths", "plant_assignments__plant")
|
||||
.filter(farm_uuid=farm_uuid)
|
||||
.first()
|
||||
)
|
||||
@@ -949,6 +954,11 @@ class YieldHarvestSummaryService:
|
||||
fallback_note,
|
||||
)
|
||||
|
||||
merged["narrative_status"] = narratives.get("status", "success")
|
||||
merged["narrative_source"] = narratives.get("source", "deterministic")
|
||||
if isinstance(narratives.get("narrative_error"), dict):
|
||||
merged["narrative_error"] = narratives["narrative_error"]
|
||||
|
||||
return merged
|
||||
|
||||
def _coalesce_text(self, *values: Any) -> str:
|
||||
|
||||
Reference in New Issue
Block a user