UPDATE
This commit is contained in:
@@ -7,6 +7,7 @@ from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from config.openapi import build_envelope_serializer, build_response
|
||||
from rag.failure_contract import RAGServiceError
|
||||
from rag.chat import encode_uploaded_image
|
||||
from rag.services import get_pest_disease_detection, get_pest_disease_risk
|
||||
|
||||
@@ -100,6 +101,11 @@ class PestDiseaseDetectionView(_ImageMixin, APIView):
|
||||
query=validated.get("query"),
|
||||
images=images,
|
||||
)
|
||||
except RAGServiceError as exc:
|
||||
return Response(
|
||||
{"code": exc.http_status, "msg": exc.contract.message, "data": exc.to_dict()},
|
||||
status=exc.http_status,
|
||||
)
|
||||
except Exception as exc:
|
||||
return Response(
|
||||
{"code": 500, "msg": f"خطا در تحلیل تصویر گیاه: {exc}", "data": None},
|
||||
@@ -146,6 +152,11 @@ class PestDiseaseRiskView(APIView):
|
||||
growth_stage=validated.get("growth_stage"),
|
||||
query=validated.get("query"),
|
||||
)
|
||||
except RAGServiceError as exc:
|
||||
return Response(
|
||||
{"code": exc.http_status, "msg": exc.contract.message, "data": exc.to_dict()},
|
||||
status=exc.http_status,
|
||||
)
|
||||
except Exception as exc:
|
||||
return Response(
|
||||
{"code": 500, "msg": f"خطا در پیش بینی ریسک آفات و بیماری: {exc}", "data": None},
|
||||
|
||||
Reference in New Issue
Block a user