Spaces:
Sleeping
Sleeping
Commit
·
ddfc76d
1
Parent(s):
381d58a
criação do campo de contexto
Browse files- app.py +6 -5
- config.py +40 -28
- templates/index.html +6 -0
app.py
CHANGED
|
@@ -160,6 +160,7 @@ def process():
|
|
| 160 |
|
| 161 |
form_data = request.form
|
| 162 |
files = request.files.getlist('files')
|
|
|
|
| 163 |
mode = form_data.get('mode', 'real')
|
| 164 |
processing_mode = form_data.get('processing_mode', 'hierarchical')
|
| 165 |
|
|
@@ -248,7 +249,7 @@ def process():
|
|
| 248 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 249 |
).replace(
|
| 250 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 251 |
-
)
|
| 252 |
|
| 253 |
prompt = PromptTemplate(template=updated_prompt_template, input_variables=["solicitacao_usuario", "rag_context"])
|
| 254 |
json_data = safe_json_dumps({'progress': 15, 'message': 'Iniciando processamento paralelo...'})
|
|
@@ -312,19 +313,19 @@ def process():
|
|
| 312 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 313 |
).replace(
|
| 314 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 315 |
-
)
|
| 316 |
|
| 317 |
updated_sonnet_template = PROMPT_HIERARQUICO_SONNET.replace(
|
| 318 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 319 |
).replace(
|
| 320 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 321 |
-
)
|
| 322 |
|
| 323 |
updated_gemini_template = PROMPT_HIERARQUICO_GEMINI.replace(
|
| 324 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 325 |
).replace(
|
| 326 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 327 |
-
)
|
| 328 |
|
| 329 |
json_data = safe_json_dumps({'progress': 15, 'message': 'O GROK está processando sua solicitação...'})
|
| 330 |
yield f"data: {json_data}\n\n"
|
|
@@ -452,7 +453,7 @@ def merge():
|
|
| 452 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 453 |
).replace(
|
| 454 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 455 |
-
)
|
| 456 |
|
| 457 |
prompt_merge = PromptTemplate(template=updated_merge_template, input_variables=["solicitacao_usuario", "texto_para_analise_grok", "texto_para_analise_sonnet", "texto_para_analise_gemini"])
|
| 458 |
|
|
|
|
| 160 |
|
| 161 |
form_data = request.form
|
| 162 |
files = request.files.getlist('files')
|
| 163 |
+
contexto = form_data.get('contexto', '').strip()
|
| 164 |
mode = form_data.get('mode', 'real')
|
| 165 |
processing_mode = form_data.get('processing_mode', 'hierarchical')
|
| 166 |
|
|
|
|
| 249 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 250 |
).replace(
|
| 251 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 252 |
+
).replace("<role>", f"<role>\n {contexto}") #injeta contexto
|
| 253 |
|
| 254 |
prompt = PromptTemplate(template=updated_prompt_template, input_variables=["solicitacao_usuario", "rag_context"])
|
| 255 |
json_data = safe_json_dumps({'progress': 15, 'message': 'Iniciando processamento paralelo...'})
|
|
|
|
| 313 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 314 |
).replace(
|
| 315 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 316 |
+
).replace("<role>", f"<role>\n {contexto}") # injeta contexto
|
| 317 |
|
| 318 |
updated_sonnet_template = PROMPT_HIERARQUICO_SONNET.replace(
|
| 319 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 320 |
).replace(
|
| 321 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 322 |
+
).replace("<role>", f"<role>\n {contexto}") # injeta contexto
|
| 323 |
|
| 324 |
updated_gemini_template = PROMPT_HIERARQUICO_GEMINI.replace(
|
| 325 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 326 |
).replace(
|
| 327 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 328 |
+
).replace("<role>", f"<role>\n {contexto}") # injeta contexto
|
| 329 |
|
| 330 |
json_data = safe_json_dumps({'progress': 15, 'message': 'O GROK está processando sua solicitação...'})
|
| 331 |
yield f"data: {json_data}\n\n"
|
|
|
|
| 453 |
"MIN_CHARS_PLACEHOLDER", str(min_chars)
|
| 454 |
).replace(
|
| 455 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 456 |
+
).replace("<role>", f"<role>\n {contexto}") # injeta contexto
|
| 457 |
|
| 458 |
prompt_merge = PromptTemplate(template=updated_merge_template, input_variables=["solicitacao_usuario", "texto_para_analise_grok", "texto_para_analise_sonnet", "texto_para_analise_gemini"])
|
| 459 |
|
config.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
PROMPT_HIERARQUICO_GROK = """
|
| 6 |
<prompt>
|
| 7 |
<role>
|
| 8 |
-
|
| 9 |
</role>
|
| 10 |
|
| 11 |
<requirements>
|
|
@@ -55,6 +55,10 @@ PROMPT_HIERARQUICO_GROK = """
|
|
| 55 |
|
| 56 |
PROMPT_HIERARQUICO_SONNET = """
|
| 57 |
<tarefa>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
<objetivo>Analisar criticamente e aprimorar texto gerado por primeiro especialista</objetivo>
|
| 59 |
|
| 60 |
<entrada>
|
|
@@ -118,6 +122,10 @@ PROMPT_HIERARQUICO_SONNET = """
|
|
| 118 |
|
| 119 |
PROMPT_HIERARQUICO_GEMINI = """
|
| 120 |
<tarefa>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
<objetivo>Você é o revisor final. Sua função é polir e aperfeiçoar o texto que já passou por uma primeira rodada de escrita e uma segunda de revisão e aprofundamento. Não faça reduções e nem resumos. Se conseguir aprofundar e detalhar melhor o texto, adicionar novas referência de novos autores, faça. Se não conseguir, não faça nada.</objetivo>
|
| 122 |
|
| 123 |
<entrada>
|
|
@@ -189,7 +197,7 @@ PROMPT_HIERARQUICO_GEMINI = """
|
|
| 189 |
PROMPT_ATOMICO_INICIAL = """
|
| 190 |
<prompt>
|
| 191 |
<role>
|
| 192 |
-
|
| 193 |
</role>
|
| 194 |
<requirements>
|
| 195 |
<caracters_count>
|
|
@@ -235,35 +243,39 @@ PROMPT_ATOMICO_INICIAL = """
|
|
| 235 |
|
| 236 |
PROMPT_ATOMICO_MERGE = """
|
| 237 |
<prompt>
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
Com base na solicitação original do usuário e nos textos-base fornecidos, sua tarefa é analisar criticamente os textos e elaborar uma versão consolidada, unindo o que há de melhor em cada um deles.
|
| 240 |
-
|
| 241 |
|
| 242 |
-
|
| 243 |
<user_request>
|
| 244 |
-
|
| 245 |
-
|
| 246 |
</user_request>
|
| 247 |
|
| 248 |
<text_grok>
|
| 249 |
-
|
| 250 |
-
|
| 251 |
</text_grok>
|
| 252 |
|
| 253 |
<text_sonnet>
|
| 254 |
-
|
| 255 |
-
|
| 256 |
</text_sonnet>
|
| 257 |
|
| 258 |
<text_gemini>
|
| 259 |
-
|
| 260 |
-
|
| 261 |
</text_gemini>
|
| 262 |
-
|
| 263 |
|
| 264 |
-
|
| 265 |
<structure>
|
| 266 |
-
|
| 267 |
</structure>
|
| 268 |
|
| 269 |
<caracters_count>
|
|
@@ -272,40 +284,40 @@ PROMPT_ATOMICO_MERGE = """
|
|
| 272 |
</caracters_count>
|
| 273 |
|
| 274 |
<analysis>
|
| 275 |
-
|
| 276 |
</analysis>
|
| 277 |
|
| 278 |
<consolidation>
|
| 279 |
-
|
| 280 |
</consolidation>
|
| 281 |
|
| 282 |
<corrections>
|
| 283 |
-
|
| 284 |
</corrections>
|
| 285 |
|
| 286 |
<expansion>
|
| 287 |
-
|
| 288 |
</expansion>
|
| 289 |
|
| 290 |
<style>
|
| 291 |
-
|
| 292 |
</style>
|
| 293 |
|
| 294 |
<writing_style>
|
| 295 |
-
|
| 296 |
-
|
| 297 |
</writing_style>
|
| 298 |
|
| 299 |
<language>
|
| 300 |
-
|
| 301 |
</language>
|
| 302 |
|
| 303 |
<forbidden>Que o texto tenha menos de MIN_CHARS_PLACEHOLDER caracteres.</forbidden>
|
| 304 |
<forbidden>Que o texto tenha mais de MAX_CHARS_PLACEHOLDER caracteres.</forbidden>
|
| 305 |
-
|
| 306 |
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
</prompt>
|
| 311 |
"""
|
|
|
|
| 5 |
PROMPT_HIERARQUICO_GROK = """
|
| 6 |
<prompt>
|
| 7 |
<role>
|
| 8 |
+
{contexto}
|
| 9 |
</role>
|
| 10 |
|
| 11 |
<requirements>
|
|
|
|
| 55 |
|
| 56 |
PROMPT_HIERARQUICO_SONNET = """
|
| 57 |
<tarefa>
|
| 58 |
+
<role>
|
| 59 |
+
{contexto}
|
| 60 |
+
</role>
|
| 61 |
+
|
| 62 |
<objetivo>Analisar criticamente e aprimorar texto gerado por primeiro especialista</objetivo>
|
| 63 |
|
| 64 |
<entrada>
|
|
|
|
| 122 |
|
| 123 |
PROMPT_HIERARQUICO_GEMINI = """
|
| 124 |
<tarefa>
|
| 125 |
+
<role>
|
| 126 |
+
{contexto}
|
| 127 |
+
</role>
|
| 128 |
+
|
| 129 |
<objetivo>Você é o revisor final. Sua função é polir e aperfeiçoar o texto que já passou por uma primeira rodada de escrita e uma segunda de revisão e aprofundamento. Não faça reduções e nem resumos. Se conseguir aprofundar e detalhar melhor o texto, adicionar novas referência de novos autores, faça. Se não conseguir, não faça nada.</objetivo>
|
| 130 |
|
| 131 |
<entrada>
|
|
|
|
| 197 |
PROMPT_ATOMICO_INICIAL = """
|
| 198 |
<prompt>
|
| 199 |
<role>
|
| 200 |
+
{contexto}
|
| 201 |
</role>
|
| 202 |
<requirements>
|
| 203 |
<caracters_count>
|
|
|
|
| 243 |
|
| 244 |
PROMPT_ATOMICO_MERGE = """
|
| 245 |
<prompt>
|
| 246 |
+
<role>
|
| 247 |
+
{contexto}
|
| 248 |
+
</role>
|
| 249 |
+
|
| 250 |
+
<task>
|
| 251 |
Com base na solicitação original do usuário e nos textos-base fornecidos, sua tarefa é analisar criticamente os textos e elaborar uma versão consolidada, unindo o que há de melhor em cada um deles.
|
| 252 |
+
</task>
|
| 253 |
|
| 254 |
+
<inputs>
|
| 255 |
<user_request>
|
| 256 |
+
<title>Solicitação Original do Usuário:</title>
|
| 257 |
+
<content>{solicitacao_usuario}</content>
|
| 258 |
</user_request>
|
| 259 |
|
| 260 |
<text_grok>
|
| 261 |
+
<title>Texto Gerado pelo GROK:</title>
|
| 262 |
+
<content>{texto_para_analise_grok}</content>
|
| 263 |
</text_grok>
|
| 264 |
|
| 265 |
<text_sonnet>
|
| 266 |
+
<title>Texto Gerado pelo Sonnet:</title>
|
| 267 |
+
<content>{texto_para_analise_sonnet}</content>
|
| 268 |
</text_sonnet>
|
| 269 |
|
| 270 |
<text_gemini>
|
| 271 |
+
<title>Texto Gerado pelo Gemini:</title>
|
| 272 |
+
<content>{texto_para_analise_gemini}</content>
|
| 273 |
</text_gemini>
|
| 274 |
+
</inputs>
|
| 275 |
|
| 276 |
+
<instructions>
|
| 277 |
<structure>
|
| 278 |
+
Analise e escolha a melhor estrutura de seções entre os 3 textos e aplique no texto consolidado. A melhor estrutura de seções é aquela que melhor entendeu o objetivo da solicitação do usuário e que mais conseguir se aprofundar na abordagem do tema.
|
| 279 |
</structure>
|
| 280 |
|
| 281 |
<caracters_count>
|
|
|
|
| 284 |
</caracters_count>
|
| 285 |
|
| 286 |
<analysis>
|
| 287 |
+
Verifique a coesão, coerência e profundidade dos argumentos.
|
| 288 |
</analysis>
|
| 289 |
|
| 290 |
<consolidation>
|
| 291 |
+
Identifique os pontos fortes de cada texto e gere um texto final consolidado. Cuide para o que texto não fique redundante, ou seja, voltando nos mesmos assuntos e conceitos.
|
| 292 |
</consolidation>
|
| 293 |
|
| 294 |
<corrections>
|
| 295 |
+
Corrija eventuais imprecisões conceituais ou argumentativas. Corrija eventuais citações a livros ou autores que não existem. Todos as obras e autores devem ser reais.
|
| 296 |
</corrections>
|
| 297 |
|
| 298 |
<expansion>
|
| 299 |
+
Não resuma ou reduza o texto: Seu objetivo é consolidar, expandir e aprofundar, nunca encurtar o texto. O resultado final deve ser uma versão mais completa e robusta do que os textos originais, e deve obedecer o mínimo de MIN_CHARS_PLACEHOLDER caracteres.
|
| 300 |
</expansion>
|
| 301 |
|
| 302 |
<style>
|
| 303 |
+
Mantenha o estilo: Respeite o estilo de linguagem e o tom do texto original.
|
| 304 |
</style>
|
| 305 |
|
| 306 |
<writing_style>
|
| 307 |
+
Evite usar um estilo de escrita muito característico de textos gerados com IA, como por exemplo: "Não é mera..., mas é...". Coisas assim. Seja mais direto.
|
| 308 |
+
Tente usar um estilo de escrita parecida com a de Gilbert K. Chesterton.
|
| 309 |
</writing_style>
|
| 310 |
|
| 311 |
<language>
|
| 312 |
+
Verificar se todo o texto, incluindo citações, estão na lingua Português do Brasil. Traduza as que não estiverem.
|
| 313 |
</language>
|
| 314 |
|
| 315 |
<forbidden>Que o texto tenha menos de MIN_CHARS_PLACEHOLDER caracteres.</forbidden>
|
| 316 |
<forbidden>Que o texto tenha mais de MAX_CHARS_PLACEHOLDER caracteres.</forbidden>
|
| 317 |
+
</instructions>
|
| 318 |
|
| 319 |
+
<output>
|
| 320 |
+
Texto consolidado, melhorado e corrigido.
|
| 321 |
+
</output>
|
| 322 |
</prompt>
|
| 323 |
"""
|
templates/index.html
CHANGED
|
@@ -488,6 +488,10 @@
|
|
| 488 |
<div id="error-box-container"></div>
|
| 489 |
<div id="real-form-container">
|
| 490 |
<form id="request-form-real">
|
|
|
|
|
|
|
|
|
|
|
|
|
| 491 |
<label for="solicitacao_usuario">Digite sua solicitação (ou arraste arquivos aqui):</label>
|
| 492 |
<textarea name="solicitacao_usuario" id="solicitacao_usuario" rows="8" required></textarea>
|
| 493 |
<div id="file-list-container"><p>Arquivos Anexados:</p><ul id="file-list"></ul></div>
|
|
@@ -583,6 +587,7 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
|
|
| 583 |
const progressBar = document.getElementById('progress-bar');
|
| 584 |
const resultsContainer = document.getElementById('results-container');
|
| 585 |
const errorContainer = document.getElementById('error-box-container');
|
|
|
|
| 586 |
const textarea = document.getElementById('solicitacao_usuario');
|
| 587 |
const fileList = document.getElementById('file-list');
|
| 588 |
const mergeBtn = document.getElementById('merge-btn');
|
|
@@ -721,6 +726,7 @@ Use o botão `Converter para MD` para ver a mágica.</textarea>
|
|
| 721 |
debugLog("Loader iniciado");
|
| 722 |
|
| 723 |
const formData = new FormData();
|
|
|
|
| 724 |
formData.append('processing_mode', processingModeSwitch.checked ? 'atomic' : 'hierarchical');
|
| 725 |
|
| 726 |
// Adicionar parâmetros de tamanho
|
|
|
|
| 488 |
<div id="error-box-container"></div>
|
| 489 |
<div id="real-form-container">
|
| 490 |
<form id="request-form-real">
|
| 491 |
+
<div class="text-size-field">
|
| 492 |
+
<label for="contexto_usuario">Contexto:</label>
|
| 493 |
+
<textarea id="contexto_usuario" name="contexto" rows="3" value="Você é um filósofo e teólogo católico, especialista em redigir textos profundos e detalhados sobre assuntos diversos da filosofia, teologia, política, antropologia, educação, psicologia etc."></textarea>
|
| 494 |
+
</div>
|
| 495 |
<label for="solicitacao_usuario">Digite sua solicitação (ou arraste arquivos aqui):</label>
|
| 496 |
<textarea name="solicitacao_usuario" id="solicitacao_usuario" rows="8" required></textarea>
|
| 497 |
<div id="file-list-container"><p>Arquivos Anexados:</p><ul id="file-list"></ul></div>
|
|
|
|
| 587 |
const progressBar = document.getElementById('progress-bar');
|
| 588 |
const resultsContainer = document.getElementById('results-container');
|
| 589 |
const errorContainer = document.getElementById('error-box-container');
|
| 590 |
+
const contextoField = document.getElementById('contexto_usuario');
|
| 591 |
const textarea = document.getElementById('solicitacao_usuario');
|
| 592 |
const fileList = document.getElementById('file-list');
|
| 593 |
const mergeBtn = document.getElementById('merge-btn');
|
|
|
|
| 726 |
debugLog("Loader iniciado");
|
| 727 |
|
| 728 |
const formData = new FormData();
|
| 729 |
+
formData.append('contexto', contextoField.value.trim());
|
| 730 |
formData.append('processing_mode', processingModeSwitch.checked ? 'atomic' : 'hierarchical');
|
| 731 |
|
| 732 |
// Adicionar parâmetros de tamanho
|