Spaces:
Sleeping
Sleeping
Commit
·
7e3649a
1
Parent(s):
0cdbf35
evoluções do campo de contexto
Browse files
app.py
CHANGED
|
@@ -187,6 +187,7 @@ def process():
|
|
| 187 |
log_print(f"=== GENERATE_STREAM INICIADO - Mode: {current_mode} ===")
|
| 188 |
|
| 189 |
solicitacao_usuario = form_data.get('solicitacao', '')
|
|
|
|
| 190 |
|
| 191 |
if current_mode == 'test':
|
| 192 |
log_print("=== MODO TESTE EXECUTADO ===")
|
|
@@ -209,7 +210,7 @@ def process():
|
|
| 209 |
log_print("=== INICIANDO PROCESSAMENTO REAL ===")
|
| 210 |
json_data = safe_json_dumps({'progress': 0, 'message': 'Processando arquivos e extraindo contexto...'})
|
| 211 |
yield f"data: {json_data}\n\n"
|
| 212 |
-
rag_context = get_relevant_context(file_paths, solicitacao_usuario)
|
| 213 |
log_print(f"=== RAG CONTEXT OBTIDO: {len(rag_context)} chars ===")
|
| 214 |
|
| 215 |
output_parser = StrOutputParser()
|
|
@@ -251,7 +252,7 @@ def process():
|
|
| 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...'})
|
| 256 |
yield f"data: {json_data}\n\n"
|
| 257 |
|
|
@@ -262,7 +263,7 @@ def process():
|
|
| 262 |
return
|
| 263 |
|
| 264 |
chain = prompt | llm | output_parser
|
| 265 |
-
thread = threading.Thread(target=run_chain_with_timeout, args=(chain, {"solicitacao_usuario": solicitacao_usuario, "rag_context": rag_context}, name))
|
| 266 |
threads.append(thread)
|
| 267 |
thread.start()
|
| 268 |
|
|
@@ -336,9 +337,9 @@ def process():
|
|
| 336 |
return
|
| 337 |
|
| 338 |
log_print("=== PROCESSANDO GROK ===")
|
| 339 |
-
prompt_grok = PromptTemplate(template=updated_grok_template, input_variables=["solicitacao_usuario", "rag_context"])
|
| 340 |
chain_grok = prompt_grok | grok_llm | output_parser
|
| 341 |
-
resposta_grok = chain_grok.invoke({"solicitacao_usuario": solicitacao_usuario, "rag_context": rag_context})
|
| 342 |
|
| 343 |
log_print(f"=== GROK TERMINOU: {len(resposta_grok)} chars ===")
|
| 344 |
|
|
@@ -363,10 +364,10 @@ def process():
|
|
| 363 |
return
|
| 364 |
|
| 365 |
log_print("=== PROCESSANDO SONNET ===")
|
| 366 |
-
prompt_sonnet = PromptTemplate(template=updated_sonnet_template, input_variables=["solicitacao_usuario", "texto_para_analise"])
|
| 367 |
claude_with_max_tokens = claude_llm.bind(max_tokens=20000)
|
| 368 |
chain_sonnet = prompt_sonnet | claude_with_max_tokens | output_parser
|
| 369 |
-
resposta_sonnet = chain_sonnet.invoke({"solicitacao_usuario": solicitacao_usuario, "texto_para_analise": resposta_grok})
|
| 370 |
|
| 371 |
log_print(f"=== SONNET TERMINOU: {len(resposta_sonnet)} chars ===")
|
| 372 |
|
|
@@ -391,9 +392,9 @@ def process():
|
|
| 391 |
return
|
| 392 |
|
| 393 |
log_print("=== PROCESSANDO GEMINI ===")
|
| 394 |
-
prompt_gemini = PromptTemplate(template=updated_gemini_template, input_variables=["solicitacao_usuario", "texto_para_analise"])
|
| 395 |
chain_gemini = prompt_gemini | gemini_llm | output_parser
|
| 396 |
-
resposta_gemini = chain_gemini.invoke({"solicitacao_usuario": solicitacao_usuario, "texto_para_analise": resposta_sonnet})
|
| 397 |
|
| 398 |
log_print(f"=== GEMINI TERMINOU: {len(resposta_gemini)} chars ===")
|
| 399 |
|
|
@@ -455,7 +456,7 @@ def merge():
|
|
| 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 |
|
| 460 |
# MUDANÇA: Usar Claude Sonnet para o merge
|
| 461 |
claude_with_max_tokens = claude_llm.bind(max_tokens=64000)
|
|
@@ -471,6 +472,7 @@ def merge():
|
|
| 471 |
return
|
| 472 |
|
| 473 |
resposta_merge = chain_merge.invoke({
|
|
|
|
| 474 |
"solicitacao_usuario": data.get('solicitacao_usuario'),
|
| 475 |
"texto_para_analise_grok": data.get('grok_text'),
|
| 476 |
"texto_para_analise_sonnet": data.get('sonnet_text'),
|
|
|
|
| 187 |
log_print(f"=== GENERATE_STREAM INICIADO - Mode: {current_mode} ===")
|
| 188 |
|
| 189 |
solicitacao_usuario = form_data.get('solicitacao', '')
|
| 190 |
+
contexto = form_data.get('contexto', '')
|
| 191 |
|
| 192 |
if current_mode == 'test':
|
| 193 |
log_print("=== MODO TESTE EXECUTADO ===")
|
|
|
|
| 210 |
log_print("=== INICIANDO PROCESSAMENTO REAL ===")
|
| 211 |
json_data = safe_json_dumps({'progress': 0, 'message': 'Processando arquivos e extraindo contexto...'})
|
| 212 |
yield f"data: {json_data}\n\n"
|
| 213 |
+
rag_context = get_relevant_context(file_paths, solicitacao_usuario, contexto)
|
| 214 |
log_print(f"=== RAG CONTEXT OBTIDO: {len(rag_context)} chars ===")
|
| 215 |
|
| 216 |
output_parser = StrOutputParser()
|
|
|
|
| 252 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 253 |
).replace("<role>", f"<role>\n {contexto}") #injeta contexto
|
| 254 |
|
| 255 |
+
prompt = PromptTemplate(template=updated_prompt_template, input_variables=["contexto", "solicitacao_usuario", "rag_context"])
|
| 256 |
json_data = safe_json_dumps({'progress': 15, 'message': 'Iniciando processamento paralelo...'})
|
| 257 |
yield f"data: {json_data}\n\n"
|
| 258 |
|
|
|
|
| 263 |
return
|
| 264 |
|
| 265 |
chain = prompt | llm | output_parser
|
| 266 |
+
thread = threading.Thread(target=run_chain_with_timeout, args=(chain, {"contexto": contexto, "solicitacao_usuario": solicitacao_usuario, "rag_context": rag_context}, name))
|
| 267 |
threads.append(thread)
|
| 268 |
thread.start()
|
| 269 |
|
|
|
|
| 337 |
return
|
| 338 |
|
| 339 |
log_print("=== PROCESSANDO GROK ===")
|
| 340 |
+
prompt_grok = PromptTemplate(template=updated_grok_template, input_variables=["contexto", "solicitacao_usuario", "rag_context"])
|
| 341 |
chain_grok = prompt_grok | grok_llm | output_parser
|
| 342 |
+
resposta_grok = chain_grok.invoke({"contexto": contexto, "solicitacao_usuario": solicitacao_usuario, "rag_context": rag_context})
|
| 343 |
|
| 344 |
log_print(f"=== GROK TERMINOU: {len(resposta_grok)} chars ===")
|
| 345 |
|
|
|
|
| 364 |
return
|
| 365 |
|
| 366 |
log_print("=== PROCESSANDO SONNET ===")
|
| 367 |
+
prompt_sonnet = PromptTemplate(template=updated_sonnet_template, input_variables=["contexto", "solicitacao_usuario", "texto_para_analise"])
|
| 368 |
claude_with_max_tokens = claude_llm.bind(max_tokens=20000)
|
| 369 |
chain_sonnet = prompt_sonnet | claude_with_max_tokens | output_parser
|
| 370 |
+
resposta_sonnet = chain_sonnet.invoke({"contexto": contexto, "solicitacao_usuario": solicitacao_usuario, "texto_para_analise": resposta_grok})
|
| 371 |
|
| 372 |
log_print(f"=== SONNET TERMINOU: {len(resposta_sonnet)} chars ===")
|
| 373 |
|
|
|
|
| 392 |
return
|
| 393 |
|
| 394 |
log_print("=== PROCESSANDO GEMINI ===")
|
| 395 |
+
prompt_gemini = PromptTemplate(template=updated_gemini_template, input_variables=["contexto", "solicitacao_usuario", "texto_para_analise"])
|
| 396 |
chain_gemini = prompt_gemini | gemini_llm | output_parser
|
| 397 |
+
resposta_gemini = chain_gemini.invoke({"contexto": contexto, "solicitacao_usuario": solicitacao_usuario, "texto_para_analise": resposta_sonnet})
|
| 398 |
|
| 399 |
log_print(f"=== GEMINI TERMINOU: {len(resposta_gemini)} chars ===")
|
| 400 |
|
|
|
|
| 456 |
"MAX_CHARS_PLACEHOLDER", str(max_chars)
|
| 457 |
).replace("<role>", f"<role>\n {contexto}") # injeta contexto
|
| 458 |
|
| 459 |
+
prompt_merge = PromptTemplate(template=updated_merge_template, input_variables=["contexto", "solicitacao_usuario", "texto_para_analise_grok", "texto_para_analise_sonnet", "texto_para_analise_gemini"])
|
| 460 |
|
| 461 |
# MUDANÇA: Usar Claude Sonnet para o merge
|
| 462 |
claude_with_max_tokens = claude_llm.bind(max_tokens=64000)
|
|
|
|
| 472 |
return
|
| 473 |
|
| 474 |
resposta_merge = chain_merge.invoke({
|
| 475 |
+
"contexto": data.get('contexto'),
|
| 476 |
"solicitacao_usuario": data.get('solicitacao_usuario'),
|
| 477 |
"texto_para_analise_grok": data.get('grok_text'),
|
| 478 |
"texto_para_analise_sonnet": data.get('sonnet_text'),
|