feat: aprendizado contínuo, presets temperatura e tabs na configuração
- Sistema de aprendizado contínuo: [KNOWLEDGE: ...] no system prompt - 3 presets de temperatura: Técnico(0.2), Equilibrado(0.6), Detalhista(1.0) - Tabs na configuração: Identidade, Estilo, Conhecimento - CRUD de conhecimento adquirido (lista + adicionar manual) - knowledge_adquirido.json persistido no servidor - GET/POST/DELETE /api/conhecimento + POST /api/conhecimento/extrair - CSS: modal grande, tabs, opções temperatura, lista conhecimento
This commit is contained in:
+153
-2
@@ -107,13 +107,26 @@ const initApp = () => {
|
||||
const welcomeTitle = document.getElementById('welcomeTitle');
|
||||
const welcomeAvatarImg = document.getElementById('welcomeAvatarImg');
|
||||
const sidebarAvatarImg = document.getElementById('sidebarAvatarImg');
|
||||
const temperatureOptions = document.getElementById('temperatureOptions');
|
||||
const knowledgeList = document.getElementById('knowledgeList');
|
||||
const manualKnowledgeInput = document.getElementById('manualKnowledgeInput');
|
||||
const btnAddKnowledge = document.getElementById('btnAddKnowledge');
|
||||
|
||||
window.agentConfig = {
|
||||
agentName: "Kemily",
|
||||
kemilyAvatarUrl: "assets/kemily.png",
|
||||
camilaAvatarUrl: "assets/camila_prof.png"
|
||||
camilaAvatarUrl: "assets/camila_prof.png",
|
||||
temperaturePreset: 'equilibrado'
|
||||
};
|
||||
|
||||
window.temperaturePresets = {
|
||||
tecnico: { value: 0.2, label: 'Técnico e Direto', description: 'Respostas curtas, objetivas, sem rodeios. Ideal para quando precisa só do essencial.' },
|
||||
equilibrado: { value: 0.6, label: 'Equilibrado', description: 'Bom para uso geral — nem muito curto, nem muito longo.' },
|
||||
detalhista: { value: 1.0, label: 'Detalhista e Falante', description: 'Respostas extensas, explicações completas, contextualização máxima. Ideal para estudo e revisão.' }
|
||||
};
|
||||
|
||||
window.conhecimento = { facts: [], lastUpdated: null };
|
||||
|
||||
// Carrega as configurações do servidor
|
||||
const loadAgentConfig = async () => {
|
||||
try {
|
||||
@@ -146,6 +159,125 @@ const initApp = () => {
|
||||
if (previewCamilaAvatar) {
|
||||
previewCamilaAvatar.src = window.agentConfig.camilaAvatarUrl;
|
||||
}
|
||||
// Atualiza seleção de temperatura
|
||||
renderTemperatureOptions();
|
||||
};
|
||||
|
||||
// Carregar presets de temperatura do servidor
|
||||
const loadTemperaturePresets = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/temperature-presets');
|
||||
if (res.ok) {
|
||||
window.temperaturePresets = await res.json();
|
||||
renderTemperatureOptions();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao carregar presets de temperatura:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Renderizar opções de temperatura
|
||||
const renderTemperatureOptions = () => {
|
||||
if (!temperatureOptions) return;
|
||||
const preset = window.agentConfig.temperaturePreset || 'equilibrado';
|
||||
temperatureOptions.innerHTML = Object.entries(window.temperaturePresets).map(([key, t]) => `
|
||||
<label class="temperature-option ${preset === key ? 'selected' : ''}" data-preset="${key}">
|
||||
<input type="radio" name="temperature" value="${key}" ${preset === key ? 'checked' : ''}>
|
||||
<div class="temperature-option-content">
|
||||
<strong>${t.label}</strong>
|
||||
<span>${t.description}</span>
|
||||
</div>
|
||||
</label>
|
||||
`).join('');
|
||||
|
||||
// Event listeners para as opções
|
||||
temperatureOptions.querySelectorAll('.temperature-option').forEach(opt => {
|
||||
opt.addEventListener('click', () => {
|
||||
temperatureOptions.querySelectorAll('.temperature-option').forEach(o => o.classList.remove('selected'));
|
||||
opt.classList.add('selected');
|
||||
opt.querySelector('input').checked = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Carregar conhecimento do servidor
|
||||
const loadConhecimento = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/conhecimento');
|
||||
if (res.ok) {
|
||||
window.conhecimento = await res.json();
|
||||
renderKnowledgeList();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao carregar conhecimento:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Renderizar lista de conhecimento
|
||||
const renderKnowledgeList = () => {
|
||||
if (!knowledgeList) return;
|
||||
if (!window.conhecimento.facts || window.conhecimento.facts.length === 0) {
|
||||
knowledgeList.innerHTML = '<p style="color: var(--text-muted); text-align: center; padding: 20px;">Nenhum conhecimento aprendido ainda. A assistente aprende automaticamente quando você ensinar algo novo!</p>';
|
||||
return;
|
||||
}
|
||||
knowledgeList.innerHTML = window.conhecimento.facts.map(f => `
|
||||
<div class="knowledge-item" data-id="${f.id}">
|
||||
<div class="knowledge-item-content">
|
||||
<span class="knowledge-source">${f.source}</span>
|
||||
<p>${f.content}</p>
|
||||
<small>${new Date(f.addedAt).toLocaleDateString('pt-BR')}</small>
|
||||
</div>
|
||||
<button class="knowledge-delete-btn" onclick="deleteKnowledge(${f.id})">×</button>
|
||||
</div>
|
||||
`).join('');
|
||||
};
|
||||
|
||||
// Deletar item de conhecimento (função global para onclick)
|
||||
window.deleteKnowledge = async (id) => {
|
||||
try {
|
||||
const res = await fetch(`/api/conhecimento/${id}`, { method: 'DELETE' });
|
||||
if (res.ok) {
|
||||
window.conhecimento.facts = window.conhecimento.facts.filter(f => f.id !== id);
|
||||
renderKnowledgeList();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao deletar conhecimento:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Adicionar conhecimento manualmente
|
||||
if (btnAddKnowledge) {
|
||||
btnAddKnowledge.addEventListener('click', async () => {
|
||||
const input = manualKnowledgeInput?.value.trim();
|
||||
if (!input) return;
|
||||
try {
|
||||
const res = await fetch('/api/conhecimento', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ fact: input, source: 'manual' })
|
||||
});
|
||||
if (res.ok) {
|
||||
manualKnowledgeInput.value = '';
|
||||
await loadConhecimento();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao adicionar conhecimento:', e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Função para extrair knowledge tags da resposta da IA e enviar ao servidor
|
||||
window.extractAndSaveKnowledge = async (assistantMessage) => {
|
||||
if (!assistantMessage || !assistantMessage.includes('[KNOWLEDGE:')) return;
|
||||
try {
|
||||
await fetch('/api/conhecimento/extrair', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ message: assistantMessage })
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Erro ao extrair conhecimento:', e);
|
||||
}
|
||||
};
|
||||
|
||||
// Variáveis temporárias para avatares (em base64 ou URLs novas)
|
||||
@@ -160,6 +292,8 @@ const initApp = () => {
|
||||
if (settingAgentName) settingAgentName.value = window.agentConfig.agentName;
|
||||
if (previewKemilyAvatar) previewKemilyAvatar.src = window.agentConfig.kemilyAvatarUrl;
|
||||
if (previewCamilaAvatar) previewCamilaAvatar.src = window.agentConfig.camilaAvatarUrl;
|
||||
renderTemperatureOptions();
|
||||
loadConhecimento();
|
||||
settingsModal.style.display = 'flex';
|
||||
});
|
||||
}
|
||||
@@ -170,6 +304,18 @@ const initApp = () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Tab switching logic
|
||||
document.querySelectorAll('.settings-tab').forEach(tab => {
|
||||
tab.addEventListener('click', () => {
|
||||
document.querySelectorAll('.settings-tab').forEach(t => t.classList.remove('active'));
|
||||
document.querySelectorAll('.settings-tab-content').forEach(c => c.classList.remove('active'));
|
||||
tab.classList.add('active');
|
||||
const targetId = tab.dataset.tab;
|
||||
const targetContent = document.getElementById(targetId);
|
||||
if (targetContent) targetContent.classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
// Fechar clicando fora do modal-content
|
||||
if (settingsModal) {
|
||||
settingsModal.addEventListener('click', (e) => {
|
||||
@@ -244,13 +390,15 @@ const initApp = () => {
|
||||
}
|
||||
|
||||
// Envia as configurações gerais
|
||||
const selectedTempPreset = temperatureOptions?.querySelector('input[name="temperature"]:checked')?.value || 'equilibrado';
|
||||
const resConfig = await fetch('/api/agent-config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
agentName: settingAgentName.value,
|
||||
kemilyAvatarUrl: kemilyUrl,
|
||||
camilaAvatarUrl: camilaUrl
|
||||
camilaAvatarUrl: camilaUrl,
|
||||
temperaturePreset: selectedTempPreset
|
||||
})
|
||||
});
|
||||
|
||||
@@ -1646,6 +1794,9 @@ const initApp = () => {
|
||||
});
|
||||
}
|
||||
|
||||
// Extrair e salvar conhecimento aprendido (tags [KNOWLEDGE: ...])
|
||||
window.extractAndSaveKnowledge(assistantContent);
|
||||
|
||||
// Adicionar botões de ação (Copiar, Regenerar, Ouvir) após o streaming
|
||||
const escapedContent = escapeHtml(assistantContent).replace(/"/g, '"');
|
||||
const actionsDiv = document.createElement('div');
|
||||
|
||||
+43
-2
@@ -249,21 +249,32 @@
|
||||
|
||||
<!-- Modal de Configurações do Agente -->
|
||||
<div id="settingsModal" class="settings-modal" style="display: none;">
|
||||
<div class="settings-modal-content">
|
||||
<div class="settings-modal-content settings-modal-large">
|
||||
<div class="settings-modal-header">
|
||||
<h3>Configurações da Assistente</h3>
|
||||
<button id="closeSettingsModal" class="close-settings-btn">×</button>
|
||||
</div>
|
||||
|
||||
<!-- Tabs de navegação -->
|
||||
<div class="settings-tabs">
|
||||
<button class="settings-tab active" data-tab="tabIdentidade">👤 Identidade</button>
|
||||
<button class="settings-tab" data-tab="tabEstilo">🎯 Estilo</button>
|
||||
<button class="settings-tab" data-tab="tabConhecimento">📚 Conhecimento</button>
|
||||
</div>
|
||||
|
||||
<div class="settings-modal-body">
|
||||
<!-- Tab: Identidade -->
|
||||
<div id="tabIdentidade" class="settings-tab-content active">
|
||||
<div class="settings-group">
|
||||
<label for="settingAgentName">Nome da Assistente</label>
|
||||
<input type="text" id="settingAgentName" placeholder="Ex: Kemily">
|
||||
<small style="color: var(--text-muted); margin-top: 4px; display: block;">Nome que aparece para a Camila na conversa</small>
|
||||
</div>
|
||||
|
||||
<div class="settings-group">
|
||||
<label>Avatar da Assistente</label>
|
||||
<div class="avatar-preview-container">
|
||||
<img id="previewKemilyAvatar" src="assets/kemily.png" alt="Kemily Preview" class="preview-avatar-img">
|
||||
<img id="previewKemilyAvatar" src="assets/kemily.png" alt="Assistante Preview" class="preview-avatar-img">
|
||||
<input type="file" id="uploadKemilyAvatar" accept="image/*" style="display: none;">
|
||||
<button type="button" class="btn-change-avatar" onclick="document.getElementById('uploadKemilyAvatar').click()">Escolher Imagem</button>
|
||||
</div>
|
||||
@@ -278,6 +289,36 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab: Estilo -->
|
||||
<div id="tabEstilo" class="settings-tab-content">
|
||||
<div class="settings-group">
|
||||
<label>Modo de Resposta da IA</label>
|
||||
<p style="color: var(--text-muted); margin-bottom: 16px; font-size: 13px;">Controla como a assistente se comporta nas respostas — mais técnica ou mais detalhista</p>
|
||||
|
||||
<div class="temperature-options" id="temperatureOptions">
|
||||
<!-- Opções preenchidas via JS -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab: Conhecimento -->
|
||||
<div id="tabConhecimento" class="settings-tab-content">
|
||||
<div class="settings-group">
|
||||
<label>📖 Conhecimento Adquirido</label>
|
||||
<p style="color: var(--text-muted); margin-bottom: 16px; font-size: 13px;">Informações que a assistente aprendeu com você ao longo das conversas. Você pode revisar e remover o que não for mais válido.</p>
|
||||
|
||||
<div id="knowledgeList" class="knowledge-list" style="max-height: 300px; overflow-y: auto; margin-bottom: 16px;">
|
||||
<!-- Lista de fatos preenchida via JS -->
|
||||
</div>
|
||||
|
||||
<div style="display: flex; gap: 8px; align-items: center;">
|
||||
<input type="text" id="manualKnowledgeInput" placeholder="Adicionar conhecimento manualmente..." style="flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-input); color: var(--text);">
|
||||
<button type="button" id="btnAddKnowledge" class="btn-save-settings" style="padding: 10px 16px;">+ Adicionar</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-modal-footer">
|
||||
<button id="btnSaveSettings" class="btn-save-settings">Salvar Configurações</button>
|
||||
</div>
|
||||
|
||||
@@ -2377,6 +2377,162 @@ code {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* Modal de Configurações - Tamanho grande para abas */
|
||||
.settings-modal-large .settings-modal-content {
|
||||
max-width: 680px;
|
||||
max-height: 85vh;
|
||||
}
|
||||
|
||||
/* Tabs de navegação */
|
||||
.settings-tabs {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
padding: 12px 20px 0;
|
||||
border-bottom: 1px solid var(--border-light, #262626);
|
||||
}
|
||||
|
||||
.settings-tab {
|
||||
padding: 10px 16px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text-secondary, #a3a3a3);
|
||||
font-size: 0.9rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
border-radius: 8px 8px 0 0;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.settings-tab:hover {
|
||||
color: var(--text-primary, #ffffff);
|
||||
background: rgba(255,255,255,0.05);
|
||||
}
|
||||
|
||||
.settings-tab.active {
|
||||
color: var(--brand-green, #10a37f);
|
||||
background: rgba(16, 163, 127, 0.1);
|
||||
border-bottom: 2px solid var(--brand-green, #10a37f);
|
||||
}
|
||||
|
||||
/* Tab content */
|
||||
.settings-tab-content {
|
||||
display: none;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.settings-tab-content.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Opções de temperatura */
|
||||
.temperature-options {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.temperature-option {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 12px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--border-light, #262626);
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
background: var(--bg-secondary, #1a1a1a);
|
||||
}
|
||||
|
||||
.temperature-option:hover {
|
||||
border-color: var(--brand-green, #10a37f);
|
||||
background: rgba(16, 163, 127, 0.05);
|
||||
}
|
||||
|
||||
.temperature-option.selected {
|
||||
border-color: var(--brand-green, #10a37f);
|
||||
background: rgba(16, 163, 127, 0.1);
|
||||
}
|
||||
|
||||
.temperature-option input[type="radio"] {
|
||||
margin-top: 4px;
|
||||
accent-color: var(--brand-green, #10a37f);
|
||||
}
|
||||
|
||||
.temperature-option-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.temperature-option-content strong {
|
||||
color: var(--text-primary, #ffffff);
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
|
||||
.temperature-option-content span {
|
||||
color: var(--text-secondary, #a3a3a3);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
/* Lista de conhecimento */
|
||||
.knowledge-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.knowledge-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 10px;
|
||||
padding: 12px 14px;
|
||||
background: var(--bg-secondary, #1a1a1a);
|
||||
border: 1px solid var(--border-light, #262626);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
.knowledge-item-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.knowledge-source {
|
||||
font-size: 0.7rem;
|
||||
text-transform: uppercase;
|
||||
color: var(--brand-green, #10a37f);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
|
||||
.knowledge-item-content p {
|
||||
margin: 0;
|
||||
color: var(--text-primary, #ffffff);
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.knowledge-item-content small {
|
||||
color: var(--text-muted, #666);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.knowledge-delete-btn {
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--text-muted, #666);
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
padding: 0 4px;
|
||||
line-height: 1;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.knowledge-delete-btn:hover {
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from { opacity: 0; }
|
||||
to { opacity: 1; }
|
||||
|
||||
@@ -28,6 +28,12 @@ const requireAuth = (req, res, next) => {
|
||||
const fs = require('fs');
|
||||
|
||||
const CONFIG_FILE_PATH = path.join(__dirname, 'agent_config.json');
|
||||
const KNOWLEDGE_FILE_PATH = path.join(__dirname, 'conhecimento_adquirido.json');
|
||||
const TEMPERATURE_PRESETS = {
|
||||
tecnico: { value: 0.2, label: 'Técnico e Direto', description: 'Respostas curtas, objetivas, sem rodeios. Ideal para quando precisa só do essencial.' },
|
||||
equilibrado: { value: 0.6, label: 'Equilibrado', description: 'Bom para uso geral — nem muito curto, nem muito longo.' },
|
||||
detalhista: { value: 1.0, label: 'Detalhista e Falante', description: 'Respostas extensas, explicações completas,contextualização máxima. Ideal para estudo e revisão.' }
|
||||
};
|
||||
|
||||
function readAgentConfig() {
|
||||
try {
|
||||
@@ -57,6 +63,60 @@ function writeAgentConfig(config) {
|
||||
}
|
||||
}
|
||||
|
||||
// Leitura/escrita do conhecimento adquirido
|
||||
function readConhecimento() {
|
||||
try {
|
||||
if (fs.existsSync(KNOWLEDGE_FILE_PATH)) {
|
||||
return JSON.parse(fs.readFileSync(KNOWLEDGE_FILE_PATH, 'utf8'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Erro ao ler conhecimento_adquirido.json:', e);
|
||||
}
|
||||
return { facts: [], lastUpdated: null };
|
||||
}
|
||||
|
||||
function writeConhecimento(data) {
|
||||
try {
|
||||
data.lastUpdated = new Date().toISOString();
|
||||
fs.writeFileSync(KNOWLEDGE_FILE_PATH, JSON.stringify(data, null, 2), 'utf8');
|
||||
} catch (e) {
|
||||
console.error('Erro ao salvar conhecimento_adquirido.json:', e);
|
||||
}
|
||||
}
|
||||
|
||||
function addKnowledgeFact(fact, source = 'conversa') {
|
||||
const knowledge = readConhecimento();
|
||||
// Evitar duplicatas por similaridade simples
|
||||
const exists = knowledge.facts.some(f =>
|
||||
f.content.toLowerCase().includes(fact.toLowerCase()) ||
|
||||
fact.toLowerCase().includes(f.content.toLowerCase())
|
||||
);
|
||||
if (!exists) {
|
||||
knowledge.facts.push({
|
||||
id: Date.now(),
|
||||
content: fact,
|
||||
source,
|
||||
addedAt: new Date().toISOString()
|
||||
});
|
||||
writeConhecimento(knowledge);
|
||||
}
|
||||
return !exists;
|
||||
}
|
||||
|
||||
function removeKnowledgeFact(id) {
|
||||
const knowledge = readConhecimento();
|
||||
knowledge.facts = knowledge.facts.filter(f => f.id !== id);
|
||||
writeConhecimento(knowledge);
|
||||
}
|
||||
|
||||
function getKnowledgeAsText() {
|
||||
const knowledge = readConhecimento();
|
||||
if (!knowledge.facts.length) return '';
|
||||
return '\n\n════════════════════════════════════════\nCONHECIMENTO ADQUIRIDO (Aprendido com a Camila):\n════════════════════════════════════════\n' +
|
||||
knowledge.facts.map(f => `[${f.source}] ${f.content}`).join('\n') +
|
||||
'\n════════════════════════════════════════\n';
|
||||
}
|
||||
|
||||
// Rota GET para obter configurações do agente
|
||||
app.get('/api/agent-config', requireAuth, (req, res) => {
|
||||
const config = readAgentConfig();
|
||||
@@ -65,19 +125,61 @@ app.get('/api/agent-config', requireAuth, (req, res) => {
|
||||
|
||||
// Rota POST para atualizar configurações do agente
|
||||
app.post('/api/agent-config', requireAuth, (req, res) => {
|
||||
const { agentName, kemilyAvatarUrl, camilaAvatarUrl } = req.body;
|
||||
const { agentName, kemilyAvatarUrl, camilaAvatarUrl, temperaturePreset } = req.body;
|
||||
if (!agentName) {
|
||||
return res.status(400).json({ error: 'Nome do agente é obrigatório' });
|
||||
}
|
||||
const config = {
|
||||
agentName: agentName.trim(),
|
||||
kemilyAvatarUrl: kemilyAvatarUrl || "assets/kemily.png",
|
||||
camilaAvatarUrl: camilaAvatarUrl || "assets/camila_prof.png"
|
||||
camilaAvatarUrl: camilaAvatarUrl || "assets/camila_prof.png",
|
||||
temperaturePreset: temperaturePreset || 'equilibrado'
|
||||
};
|
||||
writeAgentConfig(config);
|
||||
res.json({ success: true, config });
|
||||
});
|
||||
|
||||
// Rotas de conhecimento adquirido
|
||||
app.get('/api/conhecimento', requireAuth, (req, res) => {
|
||||
res.json(readConhecimento());
|
||||
});
|
||||
|
||||
app.post('/api/conhecimento', requireAuth, (req, res) => {
|
||||
const { fact, source } = req.body;
|
||||
if (!fact) return res.status(400).json({ error: 'Fato é obrigatório' });
|
||||
const added = addKnowledgeFact(fact, source || 'conversa');
|
||||
res.json({ success: true, added });
|
||||
});
|
||||
|
||||
app.delete('/api/conhecimento/:id', requireAuth, (req, res) => {
|
||||
removeKnowledgeFact(parseInt(req.params.id));
|
||||
res.json({ success: true });
|
||||
});
|
||||
|
||||
// Analisar mensagem final e extrair conhecimento aprendido (chamado pelo frontend)
|
||||
app.post('/api/conhecimento/extrair', requireAuth, (req, res) => {
|
||||
const { message } = req.body;
|
||||
if (!message) return res.status(400).json({ error: 'Mensagem é obrigatória' });
|
||||
|
||||
// Procura por padrão [KNOWLEDGE: ...] na mensagem
|
||||
const knowledgeRegex = /\[KNOWLEDGE:\s*([^\]]+)\]/g;
|
||||
const facts = [];
|
||||
let match;
|
||||
while ((match = knowledgeRegex.exec(message)) !== null) {
|
||||
const fact = match[1].trim();
|
||||
if (fact && fact.length > 3) {
|
||||
const added = addKnowledgeFact(fact, 'conversa');
|
||||
if (added) facts.push(fact);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({ success: true, factsFound: facts.length, facts });
|
||||
});
|
||||
|
||||
app.get('/api/temperature-presets', requireAuth, (req, res) => {
|
||||
res.json(TEMPERATURE_PRESETS);
|
||||
});
|
||||
|
||||
// Rota POST para upload de imagem em base64
|
||||
app.post('/api/upload-avatar', requireAuth, (req, res) => {
|
||||
const { avatarType, base64Data } = req.body;
|
||||
@@ -227,6 +329,37 @@ PERFIL DA PROFESSORA
|
||||
SUA MISSÃO:
|
||||
Ajudar a Camila na criação de relatórios HTPC, planejamentos quinzenais/mensais, resumos de livros infantis, registros de formação, estudos de caso e documentos pedagógicos diversos.
|
||||
|
||||
═══════════════════════════════════════════════════
|
||||
APRENDIZADO CONTÍNUO — Aprendendo com a Camila
|
||||
═══════════════════════════════════════════════════
|
||||
|
||||
Você pode e DEVE aprender novas informações com a Camila durante nossas conversas.
|
||||
|
||||
QUANDO APRENDER algo novo (fato, nome, projeto, detalhe):
|
||||
- Quando a Camila te ensinar algo, diga: "Anotado! Vou lembrar disso." ou similar
|
||||
- Em seguida, chame a função para salvar esse conhecimento: o sistema gravará automaticamente
|
||||
|
||||
QUANDO NÃO SOUBER algo ou tiver DÚVIDA:
|
||||
- Pergunte diretamente à Camila: "Camila, pode me ajudar a entender [assunto]? Quem é [pessoa]? O que é [projeto]?"
|
||||
- Nunca finja que sabe — seja transparente e peça ajuda
|
||||
- Após a resposta da Camila, o sistema salvará essa informação para consultas futuras
|
||||
|
||||
FONTES DE CONHECIMENTO VÁLIDAS:
|
||||
- Conversas com a Camila (ela te ensina diretamente)
|
||||
- Documentos que ela compartilhar (enviados por ela ou mencionados)
|
||||
- Informações da pasta /Agente (dossiers, estilos, projetos)
|
||||
- NÃO invente informações — se não aprendeu, pergunte
|
||||
|
||||
MANEIRA DE PEDIR ESCLARECIMENTO à Camila:
|
||||
"Percebi que não tenho essa informação nos meus documentos. Você poderia me ensinar sobre [assunto]? Assim consigo te ajudar melhor da próxima vez."
|
||||
|
||||
QUANDO APRENDER algo novo da Camila:
|
||||
Quando ela te ensinar um fato, nome, projeto ou detalhe novo, inclua NO FINAL da sua resposta a tag:
|
||||
[KNOWLEDGE: o que você aprendeu]
|
||||
|
||||
Exemplo: se a Camila disser "a coordenação deste ano está sob responsabilidade da profª Ana", você responde normal e inclui:
|
||||
[KNOWLEDGE: Coordenação 2025 está sob responsabilidade da profª Ana]
|
||||
|
||||
═══════════════════════════════════════════════════
|
||||
ESTILO DE ESCRITA DA CAMILA — REGRAS RIGOROSAS
|
||||
═══════════════════════════════════════════════════
|
||||
@@ -873,10 +1006,16 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
||||
// ==========================================================================
|
||||
const agentConfig = readAgentConfig();
|
||||
const agentName = agentConfig.agentName || "Kemily";
|
||||
const temperaturePreset = agentConfig.temperaturePreset || 'equilibrado';
|
||||
const temperature = TEMPERATURE_PRESETS[temperaturePreset]?.value || 0.6;
|
||||
|
||||
const knowledgeText = getKnowledgeAsText();
|
||||
|
||||
const dynamicSystemPrompt = {
|
||||
role: "system",
|
||||
content: KEMILY_SYSTEM_PROMPT.content.replace(/Você é a Kemily/g, `Você é a ${agentName}`)
|
||||
content: KEMILY_SYSTEM_PROMPT.content
|
||||
.replace(/Você é a Kemily/g, `Você é a ${agentName}`)
|
||||
.replace('INFORMAÇÕES PESSOAIS:', `${knowledgeText}INFORMAÇÕES PESSOAIS:`)
|
||||
};
|
||||
|
||||
const enrichedMessages = [dynamicSystemPrompt, ...messages];
|
||||
@@ -897,7 +1036,8 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
||||
body: JSON.stringify({
|
||||
model: process.env.OPENROUTER_MODEL || 'openai/gpt-4.1-nano',
|
||||
messages: enrichedMessages,
|
||||
stream: true
|
||||
stream: true,
|
||||
temperature
|
||||
})
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -918,7 +1058,8 @@ app.post('/api/chat', requireAuth, async (req, res) => {
|
||||
body: JSON.stringify({
|
||||
model: process.env.GROQ_MODEL || 'llama-3.3-70b-versatile',
|
||||
messages: enrichedMessages,
|
||||
stream: true
|
||||
stream: true,
|
||||
temperature
|
||||
})
|
||||
});
|
||||
} catch (groqErr) {
|
||||
|
||||
Reference in New Issue
Block a user