Update app.py
Browse files
app.py
CHANGED
|
@@ -20,29 +20,24 @@ llm = ChatOpenAI(
|
|
| 20 |
temperature=0.3
|
| 21 |
)
|
| 22 |
|
| 23 |
-
# Função com histórico
|
| 24 |
def responder(mensagem, histórico):
|
| 25 |
try:
|
| 26 |
resposta = llm.invoke(mensagem)
|
| 27 |
-
histórico.append(
|
| 28 |
-
histórico.append(
|
| 29 |
return histórico, ""
|
| 30 |
except Exception as e:
|
| 31 |
import traceback
|
| 32 |
-
histórico.append(
|
| 33 |
return histórico, ""
|
| 34 |
|
| 35 |
-
# Interface estilo ChatGPT
|
| 36 |
app = gr.ChatInterface(
|
| 37 |
fn=responder,
|
| 38 |
-
chatbot=gr.Chatbot(label="ChAIt", bubble_full_width=False),
|
| 39 |
-
textbox=gr.Textbox(placeholder="Digite sua pergunta aqui...", label="Mensagem"),
|
| 40 |
title="ChAIt 🤖",
|
| 41 |
theme=gr.themes.Soft(primary_hue="blue"),
|
| 42 |
description="Teste do modelo DeepSeek via OpenRouter com histórico de conversa.",
|
| 43 |
-
retry_btn="🔁 Refazer",
|
| 44 |
-
undo_btn="↩️ Desfazer",
|
| 45 |
-
clear_btn="🧹 Limpar",
|
| 46 |
)
|
| 47 |
|
| 48 |
app.launch(share=True)
|
|
|
|
| 20 |
temperature=0.3
|
| 21 |
)
|
| 22 |
|
| 23 |
+
# Função com histórico no novo formato
|
| 24 |
def responder(mensagem, histórico):
|
| 25 |
try:
|
| 26 |
resposta = llm.invoke(mensagem)
|
| 27 |
+
histórico.append({"role": "user", "content": mensagem})
|
| 28 |
+
histórico.append({"role": "assistant", "content": resposta.content})
|
| 29 |
return histórico, ""
|
| 30 |
except Exception as e:
|
| 31 |
import traceback
|
| 32 |
+
histórico.append({"role": "assistant", "content": f"❌ Erro:\n{traceback.format_exc()}"})
|
| 33 |
return histórico, ""
|
| 34 |
|
| 35 |
+
# Interface estilo ChatGPT com histórico moderno
|
| 36 |
app = gr.ChatInterface(
|
| 37 |
fn=responder,
|
|
|
|
|
|
|
| 38 |
title="ChAIt 🤖",
|
| 39 |
theme=gr.themes.Soft(primary_hue="blue"),
|
| 40 |
description="Teste do modelo DeepSeek via OpenRouter com histórico de conversa.",
|
|
|
|
|
|
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
app.launch(share=True)
|