luanpoppe commited on
Commit
7eb86f7
·
1 Parent(s): 7fa7a9c

feat: adicionando opção de enviar o PDF próprio para gerar documento para testes

Browse files
gerar_documento/serializer.py CHANGED
@@ -14,7 +14,7 @@ class FileInfoSerializer(serializers.Serializer):
14
  link_arquivo = serializers.URLField()
15
 
16
 
17
- class ResumoCursorCompeltoSerializer(ResumoCursorSerializer):
18
  system_prompt = None
19
 
20
  files = serializers.ListField(child=FileInfoSerializer(), required=True)
@@ -45,3 +45,30 @@ class ResumoCursorCompeltoSerializer(ResumoCursorSerializer):
45
  gpt_temperature = serializers.FloatField(default=0)
46
  id_modelo_do_usuario = serializers.IntegerField(required=False)
47
  should_have_contextual_chunks = serializers.BooleanField(default=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  link_arquivo = serializers.URLField()
15
 
16
 
17
+ class GerarDocumentoSerializer(ResumoCursorSerializer):
18
  system_prompt = None
19
 
20
  files = serializers.ListField(child=FileInfoSerializer(), required=True)
 
45
  gpt_temperature = serializers.FloatField(default=0)
46
  id_modelo_do_usuario = serializers.IntegerField(required=False)
47
  should_have_contextual_chunks = serializers.BooleanField(default=False)
48
+
49
+
50
+ class GerarDocumentoComPDFProprioSerializer(ResumoCursorSerializer):
51
+ system_prompt = None
52
+ prompt_auxiliar = serializers.CharField(
53
+ required=False, default=prompt_auxiliar_padrao
54
+ )
55
+ prompt_gerar_documento = serializers.CharField(
56
+ required=False, default=prompt_gerar_documento
57
+ )
58
+ user_message = serializers.CharField(required=False, default=user_message)
59
+ num_chunks_retrieval = serializers.IntegerField(default=5)
60
+ embedding_weight = serializers.FloatField(default=0.5)
61
+ bm25_weight = serializers.FloatField(default=0.5)
62
+ context_window = serializers.IntegerField(default=3)
63
+ chunk_overlap = serializers.IntegerField(default=200)
64
+ num_k_rerank = serializers.IntegerField(default=5)
65
+ model_cohere_rerank = serializers.CharField(
66
+ required=False, default="rerank-english-v2.0"
67
+ )
68
+ more_initial_chunks_for_reranking = serializers.IntegerField(default=20)
69
+ claude_context_model = serializers.CharField(
70
+ required=False, default="claude-3-haiku-20240307"
71
+ )
72
+ gpt_temperature = serializers.FloatField(default=0)
73
+ id_modelo_do_usuario = serializers.IntegerField(required=False, default=11)
74
+ should_have_contextual_chunks = serializers.BooleanField(default=False)
gerar_documento/urls.py CHANGED
@@ -1,11 +1,19 @@
1
  from django.urls import path
2
 
3
- from gerar_documento.views import ResumoSimplesCursorCompletoView
 
 
 
4
 
5
  urlpatterns = [
6
  path(
7
  "gerar-documento",
8
- ResumoSimplesCursorCompletoView.as_view(),
9
  name="summary-cursor-completo-pdf",
10
  ),
 
 
 
 
 
11
  ]
 
1
  from django.urls import path
2
 
3
+ from gerar_documento.views import (
4
+ GerarDocumentoView,
5
+ GerarDocumentoComPDFProprioView,
6
+ )
7
 
8
  urlpatterns = [
9
  path(
10
  "gerar-documento",
11
+ GerarDocumentoView.as_view(),
12
  name="summary-cursor-completo-pdf",
13
  ),
14
+ path(
15
+ "gerar-documento/pdf",
16
+ GerarDocumentoComPDFProprioView.as_view(),
17
+ name="generate-document-with-own-pdf",
18
+ ),
19
  ]
gerar_documento/views.py CHANGED
@@ -12,19 +12,20 @@ from _utils.resumo_completo_cursor import (
12
  )
13
  from _utils.gerar_relatorio_modelo_usuario.prompts import prompt_auxiliar_inicio
14
  from .serializer import (
15
- ResumoCursorCompeltoSerializer,
 
16
  )
17
 
18
 
19
- class ResumoSimplesCursorCompletoView(AsyncAPIView):
20
  # parser_classes = [MultiPartParser]
21
 
22
  @extend_schema(
23
- request=ResumoCursorCompeltoSerializer,
24
  )
25
  async def post(self, request):
26
  print(f"\n\nDATA E HORA DA REQUISIÇÃO: {datetime.now()}")
27
- serializer = ResumoCursorCompeltoSerializer(data=request.data)
28
  if serializer.is_valid(raise_exception=True):
29
  data = serializer.validated_data
30
  print("\n\ndata: ", data)
@@ -46,3 +47,28 @@ class ResumoSimplesCursorCompletoView(AsyncAPIView):
46
  # remove_pdf_temp_files(listaPDFs)
47
 
48
  return Response({"resposta": resposta_llm})
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  )
13
  from _utils.gerar_relatorio_modelo_usuario.prompts import prompt_auxiliar_inicio
14
  from .serializer import (
15
+ GerarDocumentoComPDFProprioSerializer,
16
+ GerarDocumentoSerializer,
17
  )
18
 
19
 
20
+ class GerarDocumentoView(AsyncAPIView):
21
  # parser_classes = [MultiPartParser]
22
 
23
  @extend_schema(
24
+ request=GerarDocumentoSerializer,
25
  )
26
  async def post(self, request):
27
  print(f"\n\nDATA E HORA DA REQUISIÇÃO: {datetime.now()}")
28
+ serializer = GerarDocumentoSerializer(data=request.data)
29
  if serializer.is_valid(raise_exception=True):
30
  data = serializer.validated_data
31
  print("\n\ndata: ", data)
 
47
  # remove_pdf_temp_files(listaPDFs)
48
 
49
  return Response({"resposta": resposta_llm})
50
+
51
+
52
+ class GerarDocumentoComPDFProprioView(AsyncAPIView):
53
+ parser_classes = [MultiPartParser]
54
+
55
+ @extend_schema(
56
+ request=GerarDocumentoComPDFProprioSerializer,
57
+ )
58
+ async def post(self, request):
59
+ print(f"\n\nDATA E HORA DA REQUISIÇÃO: {datetime.now()}")
60
+ serializer = GerarDocumentoComPDFProprioSerializer(data=request.data)
61
+ if serializer.is_valid(raise_exception=True):
62
+ data = serializer.validated_data
63
+ print("\n\ndata: ", data)
64
+
65
+ listaPDFs = handle_pdf_files_from_serializer(data["files"])
66
+
67
+ resposta_llm = await get_llm_summary_answer_by_cursor_complete(
68
+ data, listaPDFs
69
+ )
70
+ print("\n\nresposta_llm: ", resposta_llm)
71
+
72
+ remove_pdf_temp_files(listaPDFs)
73
+
74
+ return Response({"resposta": resposta_llm})
ragas_api/serializer.py CHANGED
@@ -1,14 +1,14 @@
1
  from rest_framework import serializers
2
- from gerar_documento.serializer import ResumoCursorCompeltoSerializer
3
 
4
 
5
- class RagasSerializer(ResumoCursorCompeltoSerializer):
6
  files = serializers.ListField(child=serializers.FileField(), required=True)
7
  id_modelo_do_usuario = serializers.IntegerField(required=False)
8
  hf_embedding = serializers.CharField(required=False, default="all-MiniLM-L6-v2")
9
 
10
 
11
- class RagasFromTextSerializer(ResumoCursorCompeltoSerializer):
12
  files = None
13
  id_modelo_do_usuario = serializers.IntegerField(required=False, default=9)
14
  user_message = serializers.CharField(required=True)
 
1
  from rest_framework import serializers
2
+ from gerar_documento.serializer import GerarDocumentoSerializer
3
 
4
 
5
+ class RagasSerializer(GerarDocumentoSerializer):
6
  files = serializers.ListField(child=serializers.FileField(), required=True)
7
  id_modelo_do_usuario = serializers.IntegerField(required=False)
8
  hf_embedding = serializers.CharField(required=False, default="all-MiniLM-L6-v2")
9
 
10
 
11
+ class RagasFromTextSerializer(GerarDocumentoSerializer):
12
  files = None
13
  id_modelo_do_usuario = serializers.IntegerField(required=False, default=9)
14
  user_message = serializers.CharField(required=True)