Add initial project setup with environment variables, server logic, and memory handling
This commit is contained in:
@@ -19,7 +19,17 @@ await load({ export: true, envPath: ".env" });
|
||||
let supabaseClient = null;
|
||||
|
||||
// Load and parse prompts.xml
|
||||
const xmlContent = await Deno.readTextFile(new URL('./prompts.xml', import.meta.url).pathname);
|
||||
// In production (Supabase Edge), load from Git; locally, load from file system
|
||||
const isProduction = Deno.env.get('DENO_DEPLOYMENT_ID') !== undefined;
|
||||
let xmlContent: string;
|
||||
|
||||
if (isProduction) {
|
||||
const response = await fetch('https://git.imbenji.dev/ImBenji/Mori/raw/branch/main/supabase/functions/llm-pipeline/prompts.xml');
|
||||
xmlContent = await response.text();
|
||||
} else {
|
||||
xmlContent = await Deno.readTextFile('./prompts.xml');
|
||||
}
|
||||
|
||||
const doc = new DOMParser().parseFromString(xmlContent, 'text/html');
|
||||
|
||||
const corsHeaders = {
|
||||
@@ -51,7 +61,7 @@ async function extractMemories(controller, messages, doc, user: User, allTags, r
|
||||
const response = await openai.chat.completions.create({
|
||||
model: 'gpt-4.1',
|
||||
temperature: 0.1,
|
||||
max_completion_tokens: 20000,
|
||||
max_completion_tokens: 50000,
|
||||
messages: [
|
||||
{ role: 'system', content: system_prompt },
|
||||
...messages,
|
||||
@@ -63,7 +73,7 @@ Available tags: ${JSON.stringify(allTags?.map(t => t.name) || [])}
|
||||
|
||||
Existing memories: ${JSON.stringify(relevantMemories || [])}
|
||||
|
||||
Now I will analyze the conversation above and extract memories.`
|
||||
Now I will analyze the conversation above and extract memories. I will extract EVERY SINGLE atomic fact from the user's messages. For detailed reports, I expect to extract 100-200+ separate memories. I will NOT summarize or limit myself. I will break down every detail into individual atomic facts.`
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -169,10 +179,17 @@ Now I will analyze the conversation above and extract memories.`
|
||||
|
||||
} else if (change.action === "DELETE") {
|
||||
deletedCount++;
|
||||
|
||||
// First, fetch the memory content before deleting
|
||||
const memoryToDelete = relevantMemories?.find(m => m.id === change.memory_id);
|
||||
|
||||
extractedMemories.push({
|
||||
action: 'DELETE',
|
||||
memory_id: change.memory_id
|
||||
memory_id: change.memory_id,
|
||||
content: memoryToDelete?.content || change.content,
|
||||
reason: change.reason
|
||||
});
|
||||
|
||||
// Delete memory (cascade should handle memory_tags)
|
||||
await supabaseClient
|
||||
.schema("mori")
|
||||
@@ -301,6 +318,8 @@ async function generateResponse(controller, messages, doc, user: User, pipelineC
|
||||
pipelineAwareness += `• Learned: ${mem.content}\n`;
|
||||
} else if (mem.action === 'UPDATE') {
|
||||
pipelineAwareness += `• Updated: ${mem.content}\n`;
|
||||
} else if (mem.action === 'DELETE') {
|
||||
pipelineAwareness += `• Forgot: ${mem.content || 'a previous memory'}\n`;
|
||||
}
|
||||
});
|
||||
pipelineAwareness += `\n`;
|
||||
@@ -310,6 +329,7 @@ async function generateResponse(controller, messages, doc, user: User, pipelineC
|
||||
pipelineAwareness += `- This awareness is internal. Don't report it.\n`;
|
||||
pipelineAwareness += `- Let it naturally inform your response\n`;
|
||||
pipelineAwareness += `- If the user explicitly asks you to remember something, you can acknowledge it naturally (e.g., "got it" or "I'll remember that")\n`;
|
||||
pipelineAwareness += `- If the user asks you to forget something and memories were deleted, acknowledge it naturally (e.g., "forgot it" or "done")\n`;
|
||||
pipelineAwareness += `- Reference past memories naturally without saying "I retrieved" or "according to my memory"\n`;
|
||||
pipelineAwareness += `- You're a companion who pays attention, not a system reporting operations\n`;
|
||||
|
||||
@@ -322,7 +342,7 @@ async function generateResponse(controller, messages, doc, user: User, pipelineC
|
||||
responseMessages.push(...messages);
|
||||
|
||||
const stream = await openai.chat.completions.create({
|
||||
model: 'gpt-4.1-mini',
|
||||
model: 'gpt-4.1',
|
||||
messages: responseMessages,
|
||||
stream: true
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user