Spaces:
Running
Running
luanpoppe
commited on
Commit
·
4dcf767
1
Parent(s):
1fb35a2
feat: adicionando system prompt hard coded
Browse files- langchain_backend/utils.py +49 -1
- resumos/serializer.py +1 -1
- resumos/views.py +3 -2
langchain_backend/utils.py
CHANGED
@@ -75,4 +75,52 @@ def create_llm(modelParam):
|
|
75 |
# max_new_tokens=100,
|
76 |
do_sample=False,
|
77 |
huggingfacehub_api_token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
78 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
# max_new_tokens=100,
|
76 |
do_sample=False,
|
77 |
huggingfacehub_api_token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")
|
78 |
+
)
|
79 |
+
|
80 |
+
|
81 |
+
DEFAULT_SYSTEM_PROMPT = """
|
82 |
+
|
83 |
+
You are a highly knowledgeable legal assistant specializing in case summarization. Your task is to provide comprehensive and accurate summaries of legal cases while maintaining a professional and objective demeanor. Always approach each case with careful consideration and analytical rigor.
|
84 |
+
|
85 |
+
First, you will be given a document to analyze:
|
86 |
+
|
87 |
+
Next, you will receive a specific request for summarization:
|
88 |
+
|
89 |
+
<summary_request>
|
90 |
+
{{resuma esse memorial}}
|
91 |
+
</summary_request>
|
92 |
+
|
93 |
+
Before providing your summary, follow these steps:
|
94 |
+
|
95 |
+
1. Argumentation Mining: Conduct a cross-Document Argument Analysis to identify the main arguments, claims, and supporting evidence within the document. Focus on extracting the most relevant information related to the summary request.
|
96 |
+
|
97 |
+
2. Socratic Questioning: Reflect on your initial findings using the Socratic method. Ask yourself probing questions to challenge your assumptions and deepen your understanding of the document's content. For example:
|
98 |
+
- What are the key points I've identified?
|
99 |
+
- Are there any counterarguments or alternative perspectives I've overlooked?
|
100 |
+
- How does this information relate to the specific summary request?
|
101 |
+
- What additional context might be necessary to fully understand these points?
|
102 |
+
|
103 |
+
3. Maximal Marginal Relevance: Apply the principles of Maximal Marginal Relevance to ensure your summary includes diverse, relevant information while avoiding redundancy. Prioritize information that is both relevant to the summary request and adds new insights not already covered.
|
104 |
+
|
105 |
+
After completing these steps, provide your summary in the following format:
|
106 |
+
|
107 |
+
<summary>
|
108 |
+
{
|
109 |
+
"nome_do_memorial": "",
|
110 |
+
"argumentos": "",
|
111 |
+
"jurisprudencia": "",
|
112 |
+
"doutrina": "",
|
113 |
+
"palavras_chave": [
|
114 |
+
]
|
115 |
+
}
|
116 |
+
</summary>
|
117 |
+
|
118 |
+
Remember:
|
119 |
+
- Always prioritize relevance to the summary request.
|
120 |
+
- Be concise and avoid unnecessary verbosity.
|
121 |
+
- Ensure your summary is well-structured and easy to understand.
|
122 |
+
- Do not include any personal opinions or information not present in the original document.
|
123 |
+
- If the summary request asks for a specific focus or perspective, make sure to address it directly.
|
124 |
+
|
125 |
+
Your goal is to provide a comprehensive yet concise summary that accurately represents the document's content while meeting the specific needs outlined in the summary request.
|
126 |
+
"""
|
resumos/serializer.py
CHANGED
@@ -19,7 +19,7 @@ from rest_framework import serializers
|
|
19 |
|
20 |
class ResumoPDFSerializer(serializers.Serializer):
|
21 |
files = serializers.ListField(child=serializers.FileField(), required=True)
|
22 |
-
system_prompt = serializers.CharField(required=
|
23 |
user_message = serializers.CharField(required=False, default="")
|
24 |
model = serializers.CharField(required=False)
|
25 |
iterative_refinement = serializers.BooleanField(required=False, default=False)
|
|
|
19 |
|
20 |
class ResumoPDFSerializer(serializers.Serializer):
|
21 |
files = serializers.ListField(child=serializers.FileField(), required=True)
|
22 |
+
system_prompt = serializers.CharField(required=False)
|
23 |
user_message = serializers.CharField(required=False, default="")
|
24 |
model = serializers.CharField(required=False)
|
25 |
iterative_refinement = serializers.BooleanField(required=False, default=False)
|
resumos/views.py
CHANGED
@@ -32,9 +32,10 @@ class ResumoView(APIView):
|
|
32 |
listaPDFs.append(temp_file_path)
|
33 |
# print('listaPDFs: ', listaPDFs)
|
34 |
|
35 |
-
|
|
|
36 |
|
37 |
for file in listaPDFs:
|
38 |
os.remove(file)
|
39 |
|
40 |
-
return Response(resposta_llm)
|
|
|
32 |
listaPDFs.append(temp_file_path)
|
33 |
# print('listaPDFs: ', listaPDFs)
|
34 |
|
35 |
+
system_prompt = data.get("system_prompt", )
|
36 |
+
resposta_llm = get_llm_answer_summary(system_prompt, data["user_message"], listaPDFs, model=model, isIterativeRefinement=data["iterative_refinement"])
|
37 |
|
38 |
for file in listaPDFs:
|
39 |
os.remove(file)
|
40 |
|
41 |
+
return Response({"resposta": resposta_llm})
|