-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
export const memory = () => 'memory' | ||
import { openai } from '@ai-sdk/openai' | ||
import { generateObject } from 'ai' | ||
import { z } from 'zod' | ||
import { clean } from './utils/string' | ||
|
||
export class Memory { | ||
model: Parameters<typeof openai>[0] | ||
constructor({ | ||
model | ||
}: { | ||
model: Parameters<typeof openai>[0] | ||
}) { | ||
this.model = model | ||
} | ||
|
||
async extract({ content }: { content: string }) { | ||
const { | ||
object: { facts } | ||
} = await generateObject({ | ||
model: openai(this.model), | ||
schema: z.object({ | ||
facts: z.array( | ||
z.object({ | ||
subject: z.string(), | ||
relation: z.string().describe('a verb phrase'), | ||
object: z.string(), | ||
data: z.record(z.string(), z.string()).optional().describe('to capture any additional info') | ||
}) | ||
) | ||
}), | ||
prompt: clean`Please extract all probable and implicit facts from the following passage. | ||
Portray the first-person as "user". | ||
Capture new relationships. | ||
Try to capture the most up-to-date state of affairs in present tense. | ||
Passage: | ||
"${content}"` | ||
// messages: [ | ||
// { | ||
// role: 'system', | ||
// content: clean`Please extract all probable and implicit facts from the following passage. | ||
// Portray the first-person as "user". | ||
// Capture new relationships. | ||
// Try to capture the most up-to-date state of affairs in present tense.` | ||
// }, | ||
// { | ||
// role: 'user', | ||
// content: eg.content | ||
// } | ||
// ] | ||
}) | ||
|
||
return { facts } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters