Skip to content

Commit

Permalink
fix relationships and elaborate
Browse files Browse the repository at this point in the history
  • Loading branch information
lalalune committed Mar 19, 2024
1 parent cfdb49c commit 712abd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
1 change: 0 additions & 1 deletion src/lib/actions/__tests__/elaborate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ describe("User Profile", () => {

// Check if the agent used the ELABORATE action for each part
const usedElaborateAction = elaborateMessages.length === 3;
console.log("**** agentMessages are ", agentMessages);
// Check if the agent's responses are not empty
const responsesNotEmpty = agentMessages.every(
(m) => (m.content as Content).content !== "",
Expand Down
42 changes: 16 additions & 26 deletions src/lib/adapters/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
sql += " AND `unique` = 1";
}

console.log("***** sql", sql);
console.log("***** queryParams", queryParams);

return this.db.prepare(sql).all(...queryParams) as Memory[];
}

Expand Down Expand Up @@ -141,8 +138,6 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
unique?: boolean;
tableName: string;
}): Promise<Memory[]> {
console.log("***** params", params);

if (!params.tableName) {
throw new Error("tableName is required");
}
Expand All @@ -162,10 +157,11 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
queryParams.push(params.count.toString());
}

console.log("***** sql", sql);
console.log("***** queryParams", queryParams);

return this.db.prepare(sql).all(...queryParams) as Memory[];
const memories = this.db.prepare(sql).all(...queryParams) as Memory[];
return memories.map((memory) => ({
...memory,
content: JSON.parse(memory.content as unknown as string),
}));
}

async searchMemoriesByEmbedding(
Expand Down Expand Up @@ -204,9 +200,6 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
queryParams.push(params.count.toString());
}

console.log("***** sql", sql);
console.log("***** queryParams", queryParams);

return this.db.prepare(sql).all(...queryParams) as Memory[];
}

Expand All @@ -216,18 +209,16 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
unique = false,
): Promise<void> {
const sql = `INSERT INTO memories (id, type, created_at, content, embedding, user_id, room_id, \`unique\`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)`;
this.db
.prepare(sql)
.run(
memory.id,
tableName,
memory.created_at,
JSON.stringify(memory.content),
JSON.stringify(memory.embedding),
memory.user_id,
memory.room_id,
unique ? 1 : 0,
);
this.db.prepare(sql).run(
memory.id,
tableName,
memory.created_at,
JSON.stringify(memory.content), // stringify the content field
JSON.stringify(memory.embedding),
memory.user_id,
memory.room_id,
unique ? 1 : 0,
);
}

async removeMemory(memoryId: UUID, tableName: string): Promise<void> {
Expand Down Expand Up @@ -393,8 +384,7 @@ export class SqliteDatabaseAdapter extends DatabaseAdapter {
}

async getRelationships(params: { userId: UUID }): Promise<Relationship[]> {
const sql =
"SELECT * FROM relationships WHERE (user_a = ? OR user_b = ?) AND status = 'FRIENDS'";
const sql = "SELECT * FROM relationships WHERE (user_a = ? OR user_b = ?)";
return this.db
.prepare(sql)
.all(params.userId, params.userId) as Relationship[];
Expand Down

0 comments on commit 712abd7

Please sign in to comment.