from rest_framework.views import APIView from adrf.views import APIView as AsyncAPIView from rest_framework.response import Response from _utils.handle_files import handle_pdf_files_from_serializer, remove_pdf_temp_files from _utils.resumo_completo_cursor import ( get_llm_summary_answer_by_cursor_complete, ) from .serializer import ( ResumoCursorCompeltoSerializer, ) from rest_framework.parsers import MultiPartParser from drf_spectacular.utils import extend_schema from datetime import datetime class ResumoSimplesCursorCompletoView(AsyncAPIView): parser_classes = [MultiPartParser] @extend_schema( request=ResumoCursorCompeltoSerializer, ) async def post(self, request): print(f"\n\nDATA E HORA DA REQUISIÇÃO: {datetime.now()}") serializer = ResumoCursorCompeltoSerializer(data=request.data) if serializer.is_valid(raise_exception=True): data = serializer.validated_data print("\n\ndata: ", data) listaPDFs = handle_pdf_files_from_serializer(data["files"]) resposta_llm = await get_llm_summary_answer_by_cursor_complete( data, listaPDFs ) print("\n\nresposta_llm: ", resposta_llm) remove_pdf_temp_files(listaPDFs) return Response({"resposta": resposta_llm})