Skip to content

Commit d273fdd

Browse files
committed
fix the bugz
1 parent 3259d99 commit d273fdd

File tree

4 files changed

+93
-109
lines changed

4 files changed

+93
-109
lines changed

packages/core/src/embedding.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ export async function retrieveCachedEmbedding(
142142
return null;
143143
}
144144

145-
const similaritySearchResult =
146-
await runtime.messageManager.getCachedEmbeddings(input);
145+
const similaritySearchResult = [];
146+
// await runtime.messageManager.getCachedEmbeddings(input);
147147
if (similaritySearchResult.length > 0) {
148148
return similaritySearchResult[0].embedding;
149149
}

packages/core/src/generation.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,15 @@ export async function splitChunks(
392392
bleed: number = 100,
393393
modelClass: string
394394
): Promise<string[]> {
395-
const model = runtime.model[modelClass];
395+
const model = models[runtime.modelProvider];
396+
console.log("model", model);
397+
398+
console.log("model.model.embedding", model.model.embedding);
399+
400+
if(!model.model.embedding) {
401+
throw new Error("Model does not support embedding");
402+
}
403+
396404
const encoding = tiktoken.encoding_for_model(
397405
model.model.embedding as TiktokenModel
398406
);

packages/core/src/runtime.ts

+60-59
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import {
1414
} from "./evaluators.ts";
1515
import { generateText } from "./generation.ts";
1616
import { formatGoalsAsString, getGoals } from "./goals.ts";
17-
import { elizaLogger } from "./index.ts";
18-
import { MemoryManager } from "./memory.ts";
17+
import { elizaLogger, embed, splitChunks } from "./index.ts";
18+
import { embeddingZeroVector, MemoryManager } from "./memory.ts";
1919
import { formatActors, formatMessages, getActorDetails } from "./messages.ts";
2020
import { parseJsonArrayFromText } from "./parsing.ts";
2121
import { formatPosts } from "./posts.ts";
@@ -301,7 +301,7 @@ export class AgentRuntime implements IAgentRuntime {
301301
opts.character.knowledge &&
302302
opts.character.knowledge.length > 0
303303
) {
304-
// this.processCharacterKnowledge(opts.character.knowledge);
304+
this.processCharacterKnowledge(opts.character.knowledge);
305305
}
306306
}
307307

@@ -311,62 +311,63 @@ export class AgentRuntime implements IAgentRuntime {
311311
* then chunks the content into fragments, embeds each fragment, and creates fragment memories.
312312
* @param knowledge An array of knowledge items containing id, path, and content.
313313
*/
314-
// private async processCharacterKnowledge(knowledge: string[]) {
315-
// // ensure the room exists and the agent exists in the room
316-
// this.ensureRoomExists(this.agentId);
317-
// this.ensureUserExists(
318-
// this.agentId,
319-
// this.character.name,
320-
// this.character.name
321-
// );
322-
// this.ensureParticipantExists(this.agentId, this.agentId);
323-
324-
// for (const knowledgeItem of knowledge) {
325-
// const knowledgeId = stringToUuid(knowledgeItem);
326-
// const existingDocument =
327-
// await this.documentsManager.getMemoryById(knowledgeId);
328-
// if (!existingDocument) {
329-
// console.log(
330-
// "Processing knowledge for ",
331-
// this.character.name,
332-
// " - ",
333-
// knowledgeItem.slice(0, 100)
334-
// );
335-
// await this.documentsManager.createMemory({
336-
// embedding: embeddingZeroVector,
337-
// id: knowledgeId,
338-
// agentId: this.agentId,
339-
// roomId: this.agentId,
340-
// userId: this.agentId,
341-
// createdAt: Date.now(),
342-
// content: {
343-
// text: knowledgeItem,
344-
// },
345-
// });
346-
// const fragments = await splitChunks(
347-
// this,
348-
// knowledgeItem,
349-
// 1200,
350-
// 200,
351-
// "fast"
352-
// );
353-
// for (const fragment of fragments) {
354-
// const embedding = await embed(this, fragment);
355-
// await this.fragmentsManager.createMemory({
356-
// id: stringToUuid(fragment),
357-
// roomId: this.agentId,
358-
// userId: this.agentId,
359-
// createdAt: Date.now(),
360-
// content: {
361-
// source: knowledgeId,
362-
// text: fragment,
363-
// },
364-
// embedding,
365-
// });
366-
// }
367-
// }
368-
// }
369-
// }
314+
private async processCharacterKnowledge(knowledge: string[]) {
315+
// ensure the room exists and the agent exists in the room
316+
this.ensureRoomExists(this.agentId);
317+
this.ensureUserExists(
318+
this.agentId,
319+
this.character.name,
320+
this.character.name
321+
);
322+
this.ensureParticipantExists(this.agentId, this.agentId);
323+
324+
for (const knowledgeItem of knowledge) {
325+
const knowledgeId = stringToUuid(knowledgeItem);
326+
const existingDocument =
327+
await this.documentsManager.getMemoryById(knowledgeId);
328+
if (!existingDocument) {
329+
console.log(
330+
"Processing knowledge for ",
331+
this.character.name,
332+
" - ",
333+
knowledgeItem.slice(0, 100)
334+
);
335+
await this.documentsManager.createMemory({
336+
embedding: embeddingZeroVector,
337+
id: knowledgeId,
338+
agentId: this.agentId,
339+
roomId: this.agentId,
340+
userId: this.agentId,
341+
createdAt: Date.now(),
342+
content: {
343+
text: knowledgeItem,
344+
},
345+
});
346+
const fragments = await splitChunks(
347+
this,
348+
knowledgeItem,
349+
1200,
350+
200,
351+
"fast"
352+
);
353+
for (const fragment of fragments) {
354+
const embedding = await embed(this, fragment);
355+
await this.fragmentsManager.createMemory({
356+
id: stringToUuid(fragment),
357+
roomId: this.agentId,
358+
agentId: this.agentId,
359+
userId: this.agentId,
360+
createdAt: Date.now(),
361+
content: {
362+
source: knowledgeId,
363+
text: fragment,
364+
},
365+
embedding,
366+
});
367+
}
368+
}
369+
}
370+
}
370371

371372
getSetting(key: string) {
372373
// check if the key is in the character.settings.secrets object

tsconfig.json

+22-47
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,24 @@
11
{
2-
"plugins": [
3-
[
4-
"docusaurus-plugin-typedoc",
5-
{
6-
"entryPoints": ["../packages/core/src/index.ts"],
7-
"tsconfig": "../tsconfig.json",
8-
"out": "./api",
9-
"skipErrorChecking": true,
10-
"readme": "none",
11-
"sidebar": {
12-
"categoryLabel": "API Reference",
13-
"position": 3,
14-
"fullNames": true
15-
},
16-
"includeVersion": true,
17-
"disableSources": false,
18-
"searchInComments": true,
19-
"navigationLinks": {
20-
"GitHub": "https://github.com/ai16z/eliza",
21-
"Documentation": "/docs/intro"
22-
},
23-
"categorizeByGroup": true,
24-
"categoryOrder": [
25-
"Core",
26-
"Clients",
27-
"Services",
28-
"Database",
29-
"Providers",
30-
"Utils",
31-
"*"
32-
],
33-
"includeExample": true,
34-
"validation": {
35-
"invalidLink": true,
36-
"notExported": true,
37-
"notDocumented": true
38-
},
39-
"cleanOutputDir": true,
40-
"hideGenerator": true,
41-
"frontmatter": {
42-
"pagination_prev": null,
43-
"pagination_next": null
44-
},
45-
"watch": "process.env.TYPEDOC_WATCH"
46-
}
47-
]
48-
]
2+
"compilerOptions": {
3+
"target": "ESNext",
4+
"module": "ESNext",
5+
"lib": ["ESNext", "dom"],
6+
"moduleResolution": "Bundler",
7+
"outDir": "./dist",
8+
"rootDir": ".",
9+
"strict": false,
10+
"esModuleInterop": true,
11+
"skipLibCheck": true,
12+
"forceConsistentCasingInFileNames": false,
13+
"allowImportingTsExtensions": true,
14+
"declaration": true,
15+
"emitDeclarationOnly": true,
16+
"resolveJsonModule": true,
17+
"noImplicitAny": false,
18+
"allowJs": true,
19+
"checkJs": false,
20+
"noEmitOnError": false,
21+
"moduleDetection": "force",
22+
"allowArbitraryExtensions": true
23+
}
4924
}

0 commit comments

Comments
 (0)