Skip to content

Commit 006dfe1

Browse files
πŸ‘ŒπŸ» IMPROVE: Config for memory (#64)
* πŸ“¦ NEW: snapshot release * πŸ“¦ NEW: Update config * πŸ‘Œ IMPROVE: update memory examples * πŸ› FIX: example config * πŸ‘Œ IMPROVE: revert lock file * πŸ“¦ NEW: add release snapshot script * WIP: updated config * πŸ“¦ NEW: update config * πŸ“¦ NEW: useGit config * πŸ“¦ NEW: Update config * πŸ› FIX: snapshot script --------- Co-authored-by: Ahmad Bilal <ahmadbilaldev@gmail.com>
1 parent 3034ff6 commit 006dfe1

File tree

21 files changed

+502
-403
lines changed

21 files changed

+502
-403
lines changed

β€Žexamples/agents/readme-writer-agent/baseai/memory/code-files/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {MemoryI} from '@baseai/core';
2-
import path from 'path';
32

43
const memoryCodeFiles = (): MemoryI => ({
54
name: 'code-files',
65
description: 'Memory that contains project files',
7-
config: {
8-
useGitRepo: false,
9-
dirToTrack: path.posix.join('.'),
10-
extToTrack: ['*'],
6+
git: {
7+
enabled: false,
8+
include: ['documents/**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
1112
},
1213
});
1314

β€Žexamples/astro/baseai/memory/chat-with-docs/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type {MemoryI} from '@baseai/core';
2-
import path from 'path';
32

43
const buidMemory = (): MemoryI => ({
54
name: 'chat-with-docs',
65
description: 'Chat with given docs',
7-
config: {
8-
useGitRepo: false,
9-
dirToTrack: path.posix.join(''),
10-
extToTrack: ['*'],
6+
git: {
7+
enabled: false,
8+
include: ['documents/**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
1112
},
1213
});
1314

β€Žexamples/nextjs/baseai/memory/chat-with-docs/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {MemoryI} from '@baseai/core';
2-
import path from 'path';
32

43
const buidMemory = (): MemoryI => ({
54
name: 'chat-with-docs',
65
description: 'Chat with given docs',
7-
config: {
8-
useGitRepo: false,
9-
dirToTrack: path.posix.join(''),
10-
extToTrack: ['*'],
6+
git: {
7+
enabled: false,
8+
include: ['documents/**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
1112
},
1213
});
1314

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {MemoryI} from '@baseai/core';
2+
3+
const memoryAiAgentMemory = (): MemoryI => ({
4+
name: 'ai-agent-memory',
5+
description: 'My list of docs as memory for an AI agent pipe',
6+
git: {
7+
enabled: true,
8+
include: ['**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
12+
},
13+
});
14+
15+
export default memoryAiAgentMemory;

β€Žexamples/nodejs/baseai/memory/chat-with-docs/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {MemoryI} from '@baseai/core';
2-
import path from 'path';
32

43
const buildMemory = (): MemoryI => ({
54
name: 'chat-with-docs',
65
description: 'Chat with docs',
7-
config: {
8-
useGitRepo: false,
9-
dirToTrack: path.posix.join(''),
10-
extToTrack: ['*'],
6+
git: {
7+
enabled: false,
8+
include: ['documents/**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
1112
},
1213
});
1314

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import { MemoryI } from '@baseai/core';
2-
import path from 'path';
1+
import {MemoryI} from '@baseai/core';
32

43
const memoryChatWithRepo = (): MemoryI => ({
5-
name: 'chat-with-repo',
6-
description: '',
7-
config: {
8-
useGitRepo: true,
9-
dirToTrack: path.posix.join('examples'),
10-
extToTrack: ["*"]
11-
}
4+
name: 'chat-with-repo',
5+
description: '',
6+
git: {
7+
enabled: true,
8+
include: ['examples/**/*'],
9+
gitignore: true,
10+
deployedAt: '',
11+
embeddedAt: '',
12+
},
1213
});
1314

1415
export default memoryChatWithRepo;
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
import {MemoryI} from '@baseai/core';
2-
import path from 'path';
32

43
const buidMemory = (): MemoryI => ({
54
name: 'chat-with-docs',
65
description: 'Chat with given docs',
7-
config: {
8-
useGitRepo: false,
9-
dirToTrack: path.posix.join(''),
10-
extToTrack: ['*'],
11-
},
6+
useGit: false,
7+
include: ['documents/**/*'],
128
});
139

1410
export default buidMemory;

β€Žpackages/baseai/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"cosmiconfig-typescript-loader": "^5.0.0",
6666
"dotenv": "^16.4.5",
6767
"execa": "^9.4.0",
68+
"fast-glob": "^3.3.2",
6869
"figures": "^6.1.0",
6970
"get-package-json-file": "^2.0.0",
7071
"hono": "^4.5.11",
@@ -113,4 +114,4 @@
113114
"langbase.com",
114115
"generative AI"
115116
]
116-
}
117+
}

β€Žpackages/baseai/src/deploy/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,14 @@ export async function deployMemory({
487487
let memoryDocs: MemoryDocumentI[] = [];
488488

489489
// Git sync memories
490-
if (memoryObject.config?.useGitRepo) {
490+
if (memoryObject.git.enabled) {
491491
// Get names of files to deploy, i.e., changed or new files
492492
const {
493493
filesToDeploy: gitFilesToDeploy,
494494
filesToDelete: gitFilesToDelete
495495
} = await handleGitSyncMemories({
496496
memoryName: memoryNameWithoutExt,
497-
config: memoryObject.config,
497+
config: memoryObject,
498498
account
499499
});
500500

@@ -530,7 +530,7 @@ export async function deployMemory({
530530
documents: memoryDocs,
531531
account,
532532
overwrite,
533-
isGitSync: memoryObject.config?.useGitRepo,
533+
isGitSync: memoryObject.git.enabled,
534534
docsToDelete: filesToDelete
535535
});
536536
spinner.stop(`Deployment finished memory: ${memoryObject.name}`);

β€Žpackages/baseai/src/memory/create.ts

Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const defaultConfig = {
2020
};
2121

2222
const MEMORY_CONSTANTS = {
23-
documentsDir: 'documents' // Path to store documents
23+
documentsDir: 'documents'
2424
};
2525

2626
export async function createMemory() {
@@ -48,7 +48,7 @@ export async function createMemory() {
4848
message: 'Description of the memory',
4949
placeholder: defaultConfig.description
5050
}),
51-
useGitRepo: () =>
51+
useGit: () =>
5252
p.confirm({
5353
message:
5454
'Do you want to create memory from current project git repository?',
@@ -63,115 +63,72 @@ export async function createMemory() {
6363
}
6464
);
6565

66-
let memoryFilesDir = '.';
67-
let fileExtensions: string[] = ['*'];
66+
const memoryNameSlugified = slugify(memoryInfo.name);
67+
const memoryNameCamelCase = camelCase('memory-' + memoryNameSlugified);
68+
const baseDir = path.join(process.cwd(), 'baseai', 'memory');
69+
const memoryDir = path.join(baseDir, memoryNameSlugified);
70+
const filePath = path.join(memoryDir, 'index.ts');
71+
const dbDir = path.join(process.cwd(), '.baseai', 'db');
6872

69-
if (memoryInfo.useGitRepo) {
70-
// Check if the current directory is a Git repository
73+
if (memoryInfo.useGit) {
7174
try {
7275
await execAsync('git rev-parse --is-inside-work-tree');
7376
} catch (error) {
7477
p.cancel('The current directory is not a Git repository.');
7578
process.exit(1);
7679
}
77-
78-
memoryFilesDir = (await p.text({
79-
message:
80-
'Enter the path to the directory to track (relative to current directory):',
81-
initialValue: '.',
82-
validate: value => {
83-
if (!value.trim()) {
84-
return 'The path cannot be empty.';
85-
}
86-
const fullPath = path.resolve(process.cwd(), value);
87-
if (!fs.existsSync(fullPath)) {
88-
return 'The specified path does not exist.';
89-
}
90-
if (!fs.lstatSync(fullPath).isDirectory()) {
91-
return 'The specified path is not a directory.';
92-
}
93-
return;
94-
}
95-
})) as string;
96-
97-
const extensionsInput = (await p.text({
98-
message:
99-
'Enter file extensions to track (use * for all, or comma-separated list, e.g., .md,.mdx):',
100-
validate: value => {
101-
if (value.trim() === '') {
102-
return 'Please enter at least one file extension or *';
103-
}
104-
if (value !== '*') {
105-
const extensions = value.split(',').map(ext => ext.trim());
106-
const invalidExtensions = extensions.filter(
107-
ext => !/^\.\w+$/.test(ext)
108-
);
109-
if (invalidExtensions.length > 0) {
110-
return `Invalid extension(s): ${invalidExtensions.join(', ')}. Extensions should start with a dot followed by alphanumeric characters.`;
111-
}
112-
}
113-
return;
114-
}
115-
})) as string;
116-
117-
fileExtensions =
118-
extensionsInput === '*'
119-
? ['*']
120-
: extensionsInput.split(',').map(ext => ext.trim());
12180
}
12281

123-
const memoryNameSlugified = slugify(memoryInfo.name);
124-
const memoryNameCamelCase = camelCase('memory-' + memoryNameSlugified);
125-
126-
const baseDir = path.join(process.cwd(), 'baseai', 'memory');
127-
const memoryDir = path.join(baseDir, memoryNameSlugified);
128-
const filePath = path.join(memoryDir, 'index.ts');
129-
const memoryDocumentsPath = path.join(
130-
memoryDir,
131-
MEMORY_CONSTANTS.documentsDir
132-
);
133-
const dbDir = path.join(process.cwd(), '.baseai', 'db');
134-
135-
const memoryContent = `import { MemoryI } from '@baseai/core';
136-
import path from 'path';
82+
const memoryContent = `import {MemoryI} from '@baseai/core';
13783
13884
const ${memoryNameCamelCase} = (): MemoryI => ({
139-
name: '${memoryNameSlugified}',
140-
description: ${JSON.stringify(memoryInfo.description) || ''},
141-
config: {
142-
useGitRepo: ${memoryInfo.useGitRepo},
143-
dirToTrack: path.posix.join(${memoryFilesDir
144-
.split(path.sep)
145-
.map(segment => `'${segment}'`)
146-
.join(', ')}),
147-
extToTrack: ${JSON.stringify(fileExtensions)}
148-
}
85+
name: '${memoryNameSlugified}',
86+
description: ${JSON.stringify(memoryInfo.description || '')},
87+
git: {
88+
enabled: ${memoryInfo.useGit},${
89+
memoryInfo.useGit
90+
? `
91+
include: ['**/*'],
92+
gitignore: true,`
93+
: `
94+
include: ['${MEMORY_CONSTANTS.documentsDir}/**/*'],
95+
gitignore: false,`
96+
}
97+
deployedAt: '',
98+
embeddedAt: ''
99+
}
149100
});
150101
151-
export default ${memoryNameCamelCase};
152-
`;
102+
export default ${memoryNameCamelCase};`;
153103

154104
try {
155105
await fs.promises.mkdir(baseDir, { recursive: true });
156106
await fs.promises.mkdir(memoryDir, { recursive: true });
157107
await fs.promises.writeFile(filePath, memoryContent);
158108
await fs.promises.mkdir(dbDir, { recursive: true });
159-
await createDb(memoryNameSlugified);
160109

161-
if (!memoryInfo.useGitRepo) {
110+
if (!memoryInfo.useGit) {
111+
const memoryDocumentsPath = path.join(
112+
memoryDir,
113+
MEMORY_CONSTANTS.documentsDir
114+
);
162115
await fs.promises.mkdir(memoryDocumentsPath, { recursive: true });
163116
p.note(
164117
`Add documents in baseai/memory/${memoryNameSlugified}/${cyan(`documents`)} to use them in the memory.`
165118
);
166119
} else {
167-
const extensionsMsg = fileExtensions.includes('*')
168-
? 'all file types'
169-
: `files with extensions: ${cyan(fileExtensions.join(', '))}`;
170120
p.note(
171-
`All ${extensionsMsg} under ${cyan(memoryFilesDir)} will be tracked and used in the memory.`
121+
[
122+
'All files in this Git repository will be tracked by default.',
123+
'',
124+
`To modify which files are being tracked, update the config at:`,
125+
cyan(filePath)
126+
].join('\n')
172127
);
173128
}
174129

130+
await createDb(memoryNameSlugified);
131+
175132
p.outro(
176133
heading({
177134
text: memoryNameCamelCase,

0 commit comments

Comments
Β (0)