Fix: Unified Context Memory between Web and Telegram
This commit is contained in:
@@ -48,7 +48,7 @@ Você tem acesso root completo à VPS e deve agir de forma profissional e precis
|
||||
2. Se o usuário pedir o status da VPS, SEMPRE use a ferramenta 'get_system_health'.
|
||||
3. Se o usuário pedir algo sobre containers, use 'get_docker_stats'.
|
||||
4. Antes de decidir que um arquivo não existe, use 'run_bash_command' com 'ls' para verificar o diretório.
|
||||
5. NUCA invente que buscou por arquivos (como syslog.conf) se o usuário não pediu especificamente por eles.
|
||||
5. NUNCA invente que buscou por arquivos (como syslog.conf) se o usuário não pediu especificamente por eles.
|
||||
6. A seção <REFINED> deve conter apenas as informações solicitadas. Se não houver imagem relevante, não inclua tags de imagem.
|
||||
7. O disco da VPS está montado em `/host_root`. Os arquivos do Marcos ficam principalmente em `/host_root/root/VPS_Sync`. Use este caminho como ponto de partida se o `find` na raiz falhar ou demorar demais.
|
||||
|
||||
|
||||
7
main.py
7
main.py
@@ -104,12 +104,15 @@ async def execute_smart_action(action: dict, is_auth: bool = Depends(verify_pass
|
||||
|
||||
@app.post("/api/chat")
|
||||
async def web_chat(message: dict, is_auth: bool = Depends(verify_password)):
|
||||
"""Endpoint para interagir com a IA via Web UI."""
|
||||
"""Endpoint para interagir com a IA via Web UI com suporte a histórico."""
|
||||
user_text = message.get("text", "")
|
||||
history = message.get("history", []) # Recebe o histórico do navegador
|
||||
|
||||
if not user_text:
|
||||
return JSONResponse(content={"reply": "Por favor, digite um comando válido."})
|
||||
|
||||
reply = await run_in_threadpool(query_agent, prompt=user_text)
|
||||
# Passa o histórico para o query_agent manter o contexto
|
||||
reply = await run_in_threadpool(query_agent, prompt=user_text, chat_history=history)
|
||||
return JSONResponse(content={"reply": reply})
|
||||
|
||||
@app.post("/api/chat-audio")
|
||||
|
||||
@@ -853,6 +853,7 @@
|
||||
|
||||
<script>
|
||||
let webPassword = localStorage.getItem('vps_web_password') || '';
|
||||
let chatHistory = []; // Memória da conversa na Web
|
||||
|
||||
// Helper para chamadas de API com autenticação
|
||||
async function apiFetch(url, options = {}) {
|
||||
@@ -1011,7 +1012,7 @@
|
||||
const res = await apiFetch('/api/chat', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ text })
|
||||
body: JSON.stringify({ text, history: chatHistory })
|
||||
});
|
||||
const data = await res.json();
|
||||
processAIReply(data.reply);
|
||||
@@ -1059,6 +1060,14 @@
|
||||
div.textContent = text;
|
||||
box.appendChild(div);
|
||||
box.scrollTop = box.scrollHeight;
|
||||
|
||||
// Atualiza o histórico local (limita a 10 mensagens)
|
||||
if (sender === 'user') {
|
||||
chatHistory.push({ user: text, bot: "" });
|
||||
} else if (chatHistory.length > 0) {
|
||||
chatHistory[chatHistory.length - 1].bot = text;
|
||||
}
|
||||
if (chatHistory.length > 10) chatHistory.shift();
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
|
||||
Reference in New Issue
Block a user