Skip to content

Commit

Permalink
Improve editing ability
Browse files Browse the repository at this point in the history
  • Loading branch information
tedspare committed Oct 15, 2024
1 parent 5de169f commit 0641164
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- [2024-10-15] [Improve editing ability](https://github.com/RubricLab/memory/commit/c4e105be1a85152af88e77c9b41ef061660e7138)
- [2024-10-15] [Trigger release](https://github.com/RubricLab/memory/commit/cb0a86ef9092c626da76b2aa74fd497afaeb7601)
- [2024-10-15] [Prompt eng and handle errors](https://github.com/RubricLab/memory/commit/fd5267164d4af76b0ec26846cb0f54f906825f82)
- [2024-10-15] [Remove user filter](https://github.com/RubricLab/memory/commit/a879c56559e8cbbd82b317ed53d8c49cf0aab98d)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@rubriclab/memory",
"module": "src/index.ts",
"main": "src/index.ts",
"version": "0.0.28",
"version": "0.0.29",
"private": false,
"type": "module",
"devDependencies": {
Expand Down
31 changes: 12 additions & 19 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,50 +239,43 @@ export class Memory {
console.log('relatedFacts', relatedFacts)

const {
object: { corrections }
object: { toDelete }
} = await generateObject({
model: openai('gpt-4o-2024-08-06'),
model: openai(this.model),
schema: z.object({
corrections: z
toDelete: z
.array(
z.object({
index: z.number(),
newStatement: z.string()
index: z.number()
})
)
.optional()
}),
prompt: clean`Given the following statements and some new information, please identify any statements which have been strictly falsified.
prompt: clean`Given the following facts and some new information, please identify any statements which have been proven wrong.
Prior statements:
"""
Prior knowledge:
${relatedFacts.map((r, i) => `${i}. ${r.body}`).join('\n')}
"""
New information:
"""
${facts.map(f => `- ${f}`).join('\n')}
"""
New information will be appended by default.
Chosen statements will be deleted permanently. Only pick them if certain!
Let's do it. You've got this! 🦾
`
})

console.log('corrections', corrections)
console.log(`made corrections: ${(performance.now() - start).toFixed(2)}ms`)
console.log('toDelete', toDelete)
console.log(`identified deletions: ${(performance.now() - start).toFixed(2)}ms`)

const updates =
corrections?.flatMap(({ index, newStatement }) => {
toDelete?.flatMap(({ index }) => {
const outdated = relatedFacts[index]

if (!outdated) return []

return this.db.fact.update({
return this.db.fact.delete({
where: {
id: outdated.id
},
data: {
body: newStatement
}
})
}) || []
Expand Down

0 comments on commit 0641164

Please sign in to comment.