Spaces:
Running
Running
luanpoppe
commited on
Commit
·
e2aa91f
1
Parent(s):
1de075a
fix: limite de gemini 2.5 pro
Browse files
_utils/gerar_documento.py
CHANGED
@@ -96,9 +96,11 @@ async def gerar_documento(
|
|
96 |
axiom_instance.send_axiom(
|
97 |
"COMEÇANDO REQUISIÇÃO PARA GERAR O QUERY DINAMICAMENTE DO VECTOR STORE"
|
98 |
)
|
99 |
-
query_gerado_dinamicamente_para_o_vector_store =
|
100 |
-
|
101 |
-
|
|
|
|
|
102 |
|
103 |
axiom_instance.send_axiom(
|
104 |
f"query_gerado_dinamicamente_para_o_vector_store: {query_gerado_dinamicamente_para_o_vector_store.content}",
|
@@ -111,9 +113,6 @@ async def gerar_documento(
|
|
111 |
)
|
112 |
)
|
113 |
|
114 |
-
if isinstance(query_gerado_dinamicamente_para_o_vector_store.content, list):
|
115 |
-
query_gerado_dinamicamente_para_o_vector_store.content = "\n".join(query_gerado_dinamicamente_para_o_vector_store.content) # type: ignore
|
116 |
-
|
117 |
llm_ultimas_requests = serializer.llm_ultimas_requests
|
118 |
axiom_instance.send_axiom("COMEÇANDO A FAZER ÚLTIMA REQUISIÇÃO")
|
119 |
structured_summaries = await summarizer.gerar_documento_final(
|
|
|
96 |
axiom_instance.send_axiom(
|
97 |
"COMEÇANDO REQUISIÇÃO PARA GERAR O QUERY DINAMICAMENTE DO VECTOR STORE"
|
98 |
)
|
99 |
+
query_gerado_dinamicamente_para_o_vector_store = (
|
100 |
+
await llm.google_gemini_ainvoke(
|
101 |
+
prompt_para_gerar_query_dinamico, "gemini-2.0-flash"
|
102 |
+
)
|
103 |
+
)
|
104 |
|
105 |
axiom_instance.send_axiom(
|
106 |
f"query_gerado_dinamicamente_para_o_vector_store: {query_gerado_dinamicamente_para_o_vector_store.content}",
|
|
|
113 |
)
|
114 |
)
|
115 |
|
|
|
|
|
|
|
116 |
llm_ultimas_requests = serializer.llm_ultimas_requests
|
117 |
axiom_instance.send_axiom("COMEÇANDO A FAZER ÚLTIMA REQUISIÇÃO")
|
118 |
structured_summaries = await summarizer.gerar_documento_final(
|
_utils/gerar_documento_utils/GerarDocumento.py
CHANGED
@@ -313,20 +313,29 @@ class GerarDocumento:
|
|
313 |
|
314 |
while tentativas < 5 and not documento_gerado:
|
315 |
tentativas += 1
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
|
|
|
|
|
|
|
|
322 |
|
323 |
if not documento_gerado:
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
|
|
|
|
|
|
|
|
|
|
330 |
|
331 |
return documento_gerado
|
332 |
|
|
|
313 |
|
314 |
while tentativas < 5 and not documento_gerado:
|
315 |
tentativas += 1
|
316 |
+
try:
|
317 |
+
resposta = llm.invoke(prompt)
|
318 |
+
if hasattr(resposta, "content") and resposta.content.strip(): # type: ignore
|
319 |
+
documento_gerado = resposta.content.strip() # type: ignore
|
320 |
+
else:
|
321 |
+
print(f"Tentativa {tentativas}: resposta vazia ou inexistente.")
|
322 |
+
except Exception as e:
|
323 |
+
llm = self.select_model_for_last_requests("gemini-2.0-flash")
|
324 |
+
print(f"Tentativa {tentativas}: erro ao invocar o modelo: {e}")
|
325 |
+
time.sleep(5)
|
326 |
|
327 |
if not documento_gerado:
|
328 |
+
try:
|
329 |
+
self.axiom_instance.send_axiom(
|
330 |
+
"TENTANDO GERAR DOCUMENTO FINAL COM GPT 4o-mini COMO ÚLTIMA TENTATIVA"
|
331 |
+
)
|
332 |
+
documento_gerado = (
|
333 |
+
self.gerar_documento_utils.ultima_tentativa_requisicao(prompt)
|
334 |
+
)
|
335 |
+
except Exception as e:
|
336 |
+
raise Exception(
|
337 |
+
"Falha ao gerar o documento final na última tentativa."
|
338 |
+
) from e
|
339 |
|
340 |
return documento_gerado
|
341 |
|
_utils/langchain_utils/LLM_class.py
CHANGED
@@ -45,26 +45,30 @@ class LLM:
|
|
45 |
self,
|
46 |
prompt: str,
|
47 |
model: Google_llms = "gemini-2.0-flash",
|
|
|
48 |
):
|
49 |
-
|
50 |
-
response = await self.google_gemini(model).ainvoke(
|
51 |
-
[HumanMessage(content=prompt)]
|
52 |
-
)
|
53 |
-
return response
|
54 |
-
except:
|
55 |
try:
|
56 |
-
response = await self.google_gemini(
|
57 |
[HumanMessage(content=prompt)]
|
58 |
)
|
|
|
|
|
|
|
|
|
59 |
return response
|
60 |
-
except:
|
61 |
-
|
62 |
-
|
63 |
-
[HumanMessage(content=prompt)]
|
64 |
-
)
|
65 |
-
return response
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
self,
|
46 |
prompt: str,
|
47 |
model: Google_llms = "gemini-2.0-flash",
|
48 |
+
max_retries: int = 3,
|
49 |
):
|
50 |
+
for attempt in range(max_retries):
|
|
|
|
|
|
|
|
|
|
|
51 |
try:
|
52 |
+
response = await self.google_gemini(model).ainvoke(
|
53 |
[HumanMessage(content=prompt)]
|
54 |
)
|
55 |
+
|
56 |
+
if isinstance(response.content, list):
|
57 |
+
response.content = "\n".join(response.content) # type: ignore
|
58 |
+
|
59 |
return response
|
60 |
+
except Exception as e:
|
61 |
+
model = "gemini-2.0-flash"
|
62 |
+
print(f"Attempt {attempt + 1} failed with error: {e}")
|
|
|
|
|
|
|
63 |
|
64 |
+
# Final attempt fallback logic (optional)
|
65 |
+
try:
|
66 |
+
print("Final attempt with fallback model...")
|
67 |
+
response = await self.open_ai("chat-gpt-4o-mini").ainvoke(
|
68 |
+
[HumanMessage(content=prompt)]
|
69 |
+
)
|
70 |
+
return response
|
71 |
+
except Exception as e:
|
72 |
+
raise Exception(
|
73 |
+
"Failed to generate the final document after 5 retries and the fallback attempt with chat-gpt-4o-mini."
|
74 |
+
) from e
|