Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Database
long-term-memory.db
2 changes: 1 addition & 1 deletion configs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*
!.gitignore
!*example
!*template
!*template
3 changes: 1 addition & 2 deletions configs/config.yaml-template
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ plugins:
vector_model: text-embedding-3-small
dimensions: 100
max_query_results: 3
persist_db: true
db_file: configs/long-term-memory.db
persist_db: false
discord:
bot_token: your-discord-bot-token
allowed_channel_ids:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scripts": {
"dev": "tsx watch --include ./src src/main.ts configs/config.yaml",
"start": "npm run build && npm run fast-start",
"fast-start": "node dist/main.js configs/config.yaml",
"fast-start": "node --experimental-sqlite dist/main.js configs/config.yaml",
"build": "npm run clean && npm run fast-build",
"fast-build": "swc src -d dist --strip-leading-paths",
"clean": "rm -rf dist",
Expand Down
171 changes: 100 additions & 71 deletions src/plugins/long-term-memory/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,52 @@
defaultHeaders: openaiDefaultHeaders,
});

athena.registerTool({
name: "ltm/store",
desc: "Store some data to your long-term memory.",
args: {
desc: {
type: "string",
desc: "A description of the data.",
required: true,
},
data: {
type: "object",
desc: "The data to store.",
required: true,
},
},
{

Check failure on line 65 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Property assignment expected.
fn: async (args: Dict<any>) => {
const embedding = await this.openai.embeddings.create({
model: this.config.vector_model,
dimensions: this.config.dimensions,
input: args.desc + JSON.stringify(args.new_data),
encoding_format: "float",
});
insertStmt.run(
Float32Array.from(embedding.data[0].embedding),
args.desc,
JSON.stringify(args.data),
);
return { status: "success" };
},
},
);

athena.registerTool(
{
name: "ltm/store",
desc: "Store some data to your long-term memory.",
name: "ltm/update",
desc: "Update existing data in your long-term memory.",
args: {
desc: {
type: "string",
desc: "A description of the data.",
desc: "The description of the data.",
required: true,
},
data: {
new_data: {
type: "object",
desc: "The data to store.",
desc: "The new data to update the existing data with.",
required: true,
},
},
Expand All @@ -73,21 +106,33 @@
},
{
fn: async (args: Dict<any>) => {
const embedding = await this.openai.embeddings.create({
const existingItem = this.db
.prepare("SELECT * FROM vec_items WHERE desc = ?")
.get(args.desc);
if (!existingItem) {
throw new Error("Item not found");
}
this.db
.prepare("DELETE FROM vec_items WHERE desc = ?")
.run(args.desc);

const new_embedding = await this.openai.embeddings.create({
model: this.config.vector_model,
dimensions: this.config.dimensions,
input: args.desc,
input: args.desc + JSON.stringify(args.new_data),
encoding_format: "float",
});

insertStmt.run(
Float32Array.from(embedding.data[0].embedding),
Float32Array.from(new_embedding.data[0].embedding),
args.desc,
JSON.stringify(args.data),
JSON.stringify(args.new_data),
);
return { status: "success" };
},
},
);

// TODO: Implement remove
athena.registerTool(
{
Expand All @@ -100,81 +145,64 @@
desc: "The list of metadata of the long-term memory.",
required: true,
of: {
type: "object",
desc: "The metadata of the long-term memory.",
required: false,
of: {
desc: {
type: "string",
desc: "The description of the data.",
required: true,
},
desc: {
type: "string",
desc: "The description of the data.",
required: true,
},
},
},
},
},
{
fn: async (args: Dict<any>) => {
const list = this.db
.prepare("SELECT desc, data FROM vec_items")
.all();
return {
list: list.map((item) => ({
desc: String(item.desc),
data: JSON.parse(String(item.data)),
})),
};
},
fn: async (args: Dict<any>) => {

Check failure on line 157 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

',' expected.
const list = this.db.prepare("SELECT desc, data FROM vec_items").all();
return { list: list };
},
);
athena.registerTool(
{
name: "ltm/retrieve",
desc: "Retrieve data from your long-term memory.",
args: {
query: {
type: "string",
desc: "The query to retrieve the data.",
required: true,
},
});

Check failure on line 161 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Unexpected token. A constructor, method, accessor, or property was expected.

Check failure on line 161 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Argument expression expected.
athena.registerTool({

Check failure on line 162 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Unexpected token. A constructor, method, accessor, or property was expected.

Check failure on line 162 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Unexpected keyword or identifier.
name: "ltm/retrieve",

Check failure on line 163 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

':' expected.

Check failure on line 163 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Identifier expected.
desc: "Retrieve data from your long-term memory.",

Check failure on line 164 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

':' expected.

Check failure on line 164 in src/plugins/long-term-memory/init.ts

View workflow job for this annotation

GitHub Actions / Typecheck

Identifier expected.
args: {
query: {
type: "string",
desc: "The query to retrieve the data.",
required: true,
},
retvals: {
list: {
type: "array",
desc: "Query results list of metadata of the long-term memory.",
required: true,
},
retvals: {
list: {
type: "array",
desc: "Query results list of metadata of the long-term memory.",
required: true,
of: {
type: "object",
desc: "The desc and data of the long-term memory.",
required: false,
of: {
type: "object",
desc: "The desc and data of the long-term memory.",
required: false,
of: {
desc: {
type: "string",
desc: "The description of the data.",
required: true,
},
data: {
type: "object",
desc: "The data.",
required: true,
},
desc: {
type: "string",
desc: "The description of the data.",
required: true,
},
data: {
type: "object",
desc: "The data.",
required: true,
},
},
},
},
},
{
fn: async (args) => {
const embedding = await this.openai.embeddings.create({
model: this.config.vector_model,
dimensions: this.config.dimensions,
input: args.query,
encoding_format: "float",
});
const results = this.db
.prepare(
`SELECT
fn: async (args: Dict<any>) => {
const embedding = await this.openai.embeddings.create({
model: this.config.vector_model,
dimensions: this.config.dimensions,
input: args.query,
encoding_format: "float",
});
const results = this.db
.prepare(
`SELECT
distance,
desc,
data
Expand Down Expand Up @@ -205,6 +233,7 @@

async unload(athena: Athena) {
athena.deregisterTool("ltm/store");
athena.deregisterTool("ltm/update");
athena.deregisterTool("ltm/list");
athena.deregisterTool("ltm/retrieve");
}
Expand Down
Loading