Memory prompt refinement
This commit is contained in:
@@ -61,6 +61,10 @@ function cosineSearch(query: number[], memories: Memory[], limit: number): Memor
|
||||
.map(s => s.ref);
|
||||
}
|
||||
|
||||
export function stripHeader(content: string): string {
|
||||
return content.replace(/^---[\s\S]*?\n---\n?/, '').trimStart();
|
||||
}
|
||||
|
||||
export class MemoryCache {
|
||||
private tree!: KDTree<MemoryRef>;
|
||||
public memories: Memory[];
|
||||
@@ -249,7 +253,7 @@ ${m.content}
|
||||
|
||||
private appendFacts(node: Memory, facts: string[]): void {
|
||||
this.ensureDoc(node);
|
||||
const body = this.stripHeader(node.content);
|
||||
const body = stripHeader(node.content);
|
||||
const bullets = facts.map(f => `- ${f}`).join('\n');
|
||||
const idx = body.indexOf(FACTS_HEADING);
|
||||
const newBody = idx === -1
|
||||
@@ -355,7 +359,7 @@ ${ghosts.length ? `${ghosts.map(g => `- ${g}: (Ghost)`).join('\n')}` : ''}`,
|
||||
}
|
||||
|
||||
private async docAgent(node: Memory, memories: Memory[], options: LLMRequest, entry: {request: {abort?: () => void} | null}): Promise<void> {
|
||||
const currentBody = this.stripHeader(node.content);
|
||||
const currentBody = stripHeader(node.content);
|
||||
let update;
|
||||
try {
|
||||
for (let i = 0; i < 2 && !update?.content; i++) {
|
||||
@@ -420,10 +424,6 @@ ${currentBody}
|
||||
return {fm, body: match[2]};
|
||||
}
|
||||
|
||||
private stripHeader(content: string): string {
|
||||
return content.replace(/^---[\s\S]*?\n---\n?/, '').trimStart();
|
||||
}
|
||||
|
||||
private touchHeader(node: Memory, body: string): string {
|
||||
const {fm} = this.parseFrontmatter(node.content);
|
||||
fm.set('name', node.name);
|
||||
|
||||
Reference in New Issue
Block a user