Update app.py
Browse files
app.py
CHANGED
|
@@ -158,7 +158,6 @@ def buscar_memoria_pinecone(query, or_key, pc_key, namespace):
|
|
| 158 |
def chamada_agente(sys_prompt, user_prompt, or_key, gr_key, mod_id):
|
| 159 |
"""Função dedicada para fazer as IAs conversarem entre si no Modo Agente."""
|
| 160 |
try:
|
| 161 |
-
# Força um modelo de lógica avançada se estiver no automático
|
| 162 |
if mod_id == "AUTO": mod_id = "deepseek/deepseek-v4-pro:online"
|
| 163 |
|
| 164 |
if "groq" in mod_id.lower() or "llama-3.3" in mod_id.lower():
|
|
@@ -169,7 +168,7 @@ def chamada_agente(sys_prompt, user_prompt, or_key, gr_key, mod_id):
|
|
| 169 |
res = client.chat.completions.create(
|
| 170 |
model=mod_id,
|
| 171 |
messages=[{"role": "system", "content": sys_prompt}, {"role": "user", "content": user_prompt}],
|
| 172 |
-
temperature=0.2
|
| 173 |
)
|
| 174 |
return res.choices[0].message.content
|
| 175 |
except Exception as e: return f"Falha na conexão do agente: {e}"
|
|
@@ -260,6 +259,20 @@ with st.sidebar:
|
|
| 260 |
with c_set:
|
| 261 |
with st.popover("⚙️"):
|
| 262 |
st.download_button("↓ Exportar", data=json.dumps(st.session_state.db, ensure_ascii=False, indent=4), file_name=f"yukina_backup_{USERNAME}.json", mime="application/json", use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
if st.button("🚪 Sair", use_container_width=True): st.session_state.logged_in = False; st.rerun()
|
| 264 |
|
| 265 |
st.markdown("<br>", unsafe_allow_html=True)
|
|
@@ -287,7 +300,6 @@ with st.sidebar:
|
|
| 287 |
st.session_state.modelo_selecionado = st.selectbox("Motor:", list(MODEL_IDS.keys()), index=list(MODEL_IDS.keys()).index(st.session_state.modelo_selecionado))
|
| 288 |
st.session_state.personalidade_ativa = st.selectbox("Alma:", list(PERSONALIDADES.keys()), index=list(PERSONALIDADES.keys()).index(st.session_state.personalidade_ativa))
|
| 289 |
|
| 290 |
-
# --- O BOTÃO DO MODO AGENTE ---
|
| 291 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 292 |
st.session_state.modo_agente = st.toggle("🛠️ Ativar Modo Agente", value=st.session_state.modo_agente, help="Ativa o Workflow Multi-Agente (Arquiteto > Engenheiro > Revisor).")
|
| 293 |
|
|
@@ -363,7 +375,6 @@ if prompt or st.session_state.regerar:
|
|
| 363 |
ws_key = os.getenv("YUKINA_CORE"); pc_key = os.getenv("PINECONE_API_KEY")
|
| 364 |
modelo_id = MODEL_IDS[st.session_state.modelo_selecionado]
|
| 365 |
|
| 366 |
-
# SE O BOTÃO DO AGENTE ESTIVER LIGADO
|
| 367 |
if st.session_state.modo_agente and not tem_imagem:
|
| 368 |
with st.chat_message("assistant"):
|
| 369 |
with st.status("🛠️ **Agente Yukina Trabalhando...**", expanded=True) as status:
|
|
@@ -388,7 +399,6 @@ if prompt or st.session_state.regerar:
|
|
| 388 |
st.session_state.db[st.session_state.current_chat]["messages"].append({"role": "assistant", "content": final})
|
| 389 |
salvar_pinecone(final, "Yukina (Agente)", or_key, pc_key, USERNAME)
|
| 390 |
|
| 391 |
-
# SE FOR UM PEDIDO NORMAL (MODO CHATBOT/GERENTE)
|
| 392 |
else:
|
| 393 |
with st.chat_message("assistant"):
|
| 394 |
prompt_sistema_atual = PERSONALIDADES.get(st.session_state.personalidade_ativa, PERSONALIDADES["🤖 Neutra (Padrão Gemini)"])
|
|
@@ -414,7 +424,6 @@ if prompt or st.session_state.regerar:
|
|
| 414 |
|
| 415 |
salvar_pinecone(prompt, "Usuário", or_key, pc_key, USERNAME); modelo_id = MODEL_IDS[motor_real]
|
| 416 |
|
| 417 |
-
# (A mesma lógica baseada no motor selecionado abaixo - Pesquisa, Visão, Imagem, Texto, etc)
|
| 418 |
if "Vídeo" in motor_real:
|
| 419 |
st.error("Geração de vídeo temporariamente desativada ou aguardando integração estável.")
|
| 420 |
|
|
|
|
| 158 |
def chamada_agente(sys_prompt, user_prompt, or_key, gr_key, mod_id):
|
| 159 |
"""Função dedicada para fazer as IAs conversarem entre si no Modo Agente."""
|
| 160 |
try:
|
|
|
|
| 161 |
if mod_id == "AUTO": mod_id = "deepseek/deepseek-v4-pro:online"
|
| 162 |
|
| 163 |
if "groq" in mod_id.lower() or "llama-3.3" in mod_id.lower():
|
|
|
|
| 168 |
res = client.chat.completions.create(
|
| 169 |
model=mod_id,
|
| 170 |
messages=[{"role": "system", "content": sys_prompt}, {"role": "user", "content": user_prompt}],
|
| 171 |
+
temperature=0.2
|
| 172 |
)
|
| 173 |
return res.choices[0].message.content
|
| 174 |
except Exception as e: return f"Falha na conexão do agente: {e}"
|
|
|
|
| 259 |
with c_set:
|
| 260 |
with st.popover("⚙️"):
|
| 261 |
st.download_button("↓ Exportar", data=json.dumps(st.session_state.db, ensure_ascii=False, indent=4), file_name=f"yukina_backup_{USERNAME}.json", mime="application/json", use_container_width=True)
|
| 262 |
+
|
| 263 |
+
# --- OPÇÃO DE IMPORTAR DE VOLTA AQUI ---
|
| 264 |
+
arquivo_import = st.file_uploader("Importar conversa:", type=["json"])
|
| 265 |
+
if arquivo_import:
|
| 266 |
+
try:
|
| 267 |
+
st.session_state.db.update(json.load(arquivo_import))
|
| 268 |
+
save_db(st.session_state.db, DB_FILE)
|
| 269 |
+
st.success("Sincronizado!")
|
| 270 |
+
time.sleep(1)
|
| 271 |
+
st.rerun()
|
| 272 |
+
except:
|
| 273 |
+
st.error("Erro no ficheiro.")
|
| 274 |
+
|
| 275 |
+
st.markdown("---")
|
| 276 |
if st.button("🚪 Sair", use_container_width=True): st.session_state.logged_in = False; st.rerun()
|
| 277 |
|
| 278 |
st.markdown("<br>", unsafe_allow_html=True)
|
|
|
|
| 300 |
st.session_state.modelo_selecionado = st.selectbox("Motor:", list(MODEL_IDS.keys()), index=list(MODEL_IDS.keys()).index(st.session_state.modelo_selecionado))
|
| 301 |
st.session_state.personalidade_ativa = st.selectbox("Alma:", list(PERSONALIDADES.keys()), index=list(PERSONALIDADES.keys()).index(st.session_state.personalidade_ativa))
|
| 302 |
|
|
|
|
| 303 |
st.markdown("<br>", unsafe_allow_html=True)
|
| 304 |
st.session_state.modo_agente = st.toggle("🛠️ Ativar Modo Agente", value=st.session_state.modo_agente, help="Ativa o Workflow Multi-Agente (Arquiteto > Engenheiro > Revisor).")
|
| 305 |
|
|
|
|
| 375 |
ws_key = os.getenv("YUKINA_CORE"); pc_key = os.getenv("PINECONE_API_KEY")
|
| 376 |
modelo_id = MODEL_IDS[st.session_state.modelo_selecionado]
|
| 377 |
|
|
|
|
| 378 |
if st.session_state.modo_agente and not tem_imagem:
|
| 379 |
with st.chat_message("assistant"):
|
| 380 |
with st.status("🛠️ **Agente Yukina Trabalhando...**", expanded=True) as status:
|
|
|
|
| 399 |
st.session_state.db[st.session_state.current_chat]["messages"].append({"role": "assistant", "content": final})
|
| 400 |
salvar_pinecone(final, "Yukina (Agente)", or_key, pc_key, USERNAME)
|
| 401 |
|
|
|
|
| 402 |
else:
|
| 403 |
with st.chat_message("assistant"):
|
| 404 |
prompt_sistema_atual = PERSONALIDADES.get(st.session_state.personalidade_ativa, PERSONALIDADES["🤖 Neutra (Padrão Gemini)"])
|
|
|
|
| 424 |
|
| 425 |
salvar_pinecone(prompt, "Usuário", or_key, pc_key, USERNAME); modelo_id = MODEL_IDS[motor_real]
|
| 426 |
|
|
|
|
| 427 |
if "Vídeo" in motor_real:
|
| 428 |
st.error("Geração de vídeo temporariamente desativada ou aguardando integração estável.")
|
| 429 |
|