Skip to content

Commit

Permalink
Merge pull request elizaOS#682 from cygaar/fix_builds
Browse files Browse the repository at this point in the history
fix: getEmbeddingZeroVector calls
  • Loading branch information
lalalune authored Nov 29, 2024
2 parents 72d4cd1 + a336029 commit 9e638d6
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 24 deletions.
10 changes: 4 additions & 6 deletions packages/adapter-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { v4 } from "uuid";
// Import the entire module as default
import pg from "pg";
const { Pool } = pg;
type Pool = pg.Pool;
type PoolType = pg.Pool;

import {
QueryConfig,
Expand All @@ -29,16 +29,14 @@ import fs from "fs";
import { fileURLToPath } from "url";
import path from "path";

const { DatabaseError } = pg;

const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

export class PostgresDatabaseAdapter
extends DatabaseAdapter<Pool>
extends DatabaseAdapter<PoolType>
implements IDatabaseCacheAdapter
{
private pool: Pool;
private pool: PoolType;
private readonly maxRetries: number = 3;
private readonly baseDelay: number = 1000; // 1 second
private readonly maxDelay: number = 10000; // 10 seconds
Expand Down Expand Up @@ -758,7 +756,7 @@ export class PostgresDatabaseAdapter
return this.withRetry(async () => {
try {
const relationshipId = v4();
const result = await this.pool.query(
await this.pool.query(
`INSERT INTO relationships (id, "userA", "userB", "userId")
VALUES ($1, $2, $3, $4)
RETURNING id`,
Expand Down
6 changes: 3 additions & 3 deletions packages/client-discord/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export class DiscordClient extends EventEmitter {
},
roomId,
createdAt: timestamp,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
};

try {
Expand Down Expand Up @@ -348,7 +348,7 @@ export class DiscordClient extends EventEmitter {
},
roomId,
createdAt: Date.now(),
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
});
} catch (error) {
console.error("Error creating reaction removal message:", error);
Expand Down Expand Up @@ -391,4 +391,4 @@ export const DiscordClientInterface: ElizaClient = {
stop: async (_runtime: IAgentRuntime) => {
console.warn("Discord client does not support stopping yet");
},
};
};
2 changes: 1 addition & 1 deletion packages/client-discord/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class MessageManager {
url: m.url,
},
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: m.createdTimestamp,
};
memories.push(memory);
Expand Down
4 changes: 2 additions & 2 deletions packages/client-discord/src/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ export class VoiceManager extends EventEmitter {
},
userId: userIdUUID,
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: Date.now(),
};

Expand Down Expand Up @@ -670,7 +670,7 @@ export class VoiceManager extends EventEmitter {
inReplyTo: memory.id,
},
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
};

if (responseMemory.content.text?.trim()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/client-farcaster/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function createCastMemory({
hash: cast.id,
},
roomId,
embedding: getEmbeddingZeroVector(runtime),
embedding: getEmbeddingZeroVector(),
createdAt: cast.message.data.timestamp * 1000,
};
}
Expand Down
4 changes: 2 additions & 2 deletions packages/client-telegram/src/messageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class MessageManager {
roomId,
content,
createdAt: message.date * 1000,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
};

// Create memory
Expand Down Expand Up @@ -468,7 +468,7 @@ export class MessageManager {
inReplyTo: messageId,
},
createdAt: sentMessage.date * 1000,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
};

// Set action to CONTINUE for all messages except the last one
Expand Down
6 changes: 3 additions & 3 deletions packages/client-twitter/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ export class ClientBase extends EventEmitter {
content: content,
agentId: this.runtime.agentId,
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: tweet.timestamp * 1000,
});

Expand Down Expand Up @@ -533,7 +533,7 @@ export class ClientBase extends EventEmitter {
content: content,
agentId: this.runtime.agentId,
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: tweet.timestamp * 1000,
});

Expand Down Expand Up @@ -575,7 +575,7 @@ export class ClientBase extends EventEmitter {
} else {
await this.runtime.messageManager.createMemory({
...message,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export class TwitterInteractionClient {
currentTweet.userId === this.twitterUserId
? this.runtime.agentId
: stringToUuid(currentTweet.userId),
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class TwitterPostClient {
source: "twitter",
},
roomId,
embedding: getEmbeddingZeroVector(this.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: tweet.timestamp * 1000,
});
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions packages/client-twitter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function buildConversationThread(
currentTweet.userId === client.profile.id
? client.runtime.agentId
: stringToUuid(currentTweet.userId),
embedding: getEmbeddingZeroVector(client.runtime),
embedding: getEmbeddingZeroVector(),
});
}

Expand Down Expand Up @@ -229,7 +229,7 @@ export async function sendTweet(
: undefined,
},
roomId,
embedding: getEmbeddingZeroVector(client.runtime),
embedding: getEmbeddingZeroVector(),
createdAt: tweet.timestamp * 1000,
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function set(
userId: runtime.agentId,
createdAt: Date.now(),
content: item.content,
embedding: getEmbeddingZeroVector(runtime),
embedding: getEmbeddingZeroVector(),
});

const preprocessed = preprocess(item.content.text);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class MemoryManager implements IMemoryManager {
} catch (error) {
elizaLogger.error("Failed to generate embedding:", error);
// Fallback to zero vector if embedding fails
memory.embedding = getEmbeddingZeroVector(this.runtime).slice();
memory.embedding = getEmbeddingZeroVector().slice();
}

return memory;
Expand Down

0 comments on commit 9e638d6

Please sign in to comment.