Skip to content

Commit 1260b33

Browse files
committed
fix split chunks error on anthropic
1 parent a4b22e2 commit 1260b33

File tree

5 files changed

+9
-30
lines changed

5 files changed

+9
-30
lines changed

packages/client-direct/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Note that {{agentName}} is capable of reading/seeing/hearing various forms of me
4646
4747
{{actions}}
4848
49-
# Instructions: Write the next message for {{agentName}}. Ignore "action".
49+
# Instructions: Write the next message for {{agentName}}.
5050
` + messageCompletionFooter;
5151

5252
export interface SimliClientConfig {

packages/client-discord/src/actions/summarize_conversation.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,11 @@ const summarizeAction = {
233233
unique: false,
234234
});
235235

236-
console.log("memories", memories);
237-
238236
const actors = await getActorDetails({
239237
runtime: runtime as IAgentRuntime,
240238
roomId,
241239
});
242240

243-
console.log("actors", actors);
244-
245241
const actorMap = new Map(actors.map((actor) => [actor.id, actor]));
246242

247243
const formattedMemories = memories
@@ -261,21 +257,17 @@ const summarizeAction = {
261257
const chunkSize = model.settings.maxContextLength - 1000;
262258

263259
const chunks = await splitChunks(
264-
runtime,
265260
formattedMemories,
266261
chunkSize,
267-
0,
268-
"gpt-4o-mini"
262+
0
269263
);
270264

271-
console.log("chunks ", chunks.length);
272265
const datestr = new Date().toUTCString().replace(/:/g, "-");
273266

274267
state.memoriesWithAttachments = formattedMemories;
275268
state.objective = objective;
276269

277270
for (let i = 0; i < chunks.length; i++) {
278-
console.log("chunk", i);
279271
const chunk = chunks[i];
280272
state.currentSummary = currentSummary;
281273
state.currentChunk = chunk;

packages/core/src/generation.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -389,24 +389,14 @@ export async function generateShouldRespond({
389389
* @returns Promise resolving to array of text chunks with bleed sections
390390
*/
391391
export async function splitChunks(
392-
runtime,
393392
content: string,
394393
chunkSize: number,
395394
bleed: number = 100,
396-
modelClass: string
397395
): Promise<string[]> {
398-
const model = models[runtime.modelProvider];
399-
console.log("model", model);
400-
401-
console.log("model.model.embedding", model.model.embedding);
402-
403-
if (!model.model.embedding) {
404-
throw new Error("Model does not support embedding");
405-
}
406-
407396
const encoding = tiktoken.encoding_for_model(
408-
model.model.embedding as TiktokenModel
397+
"gpt-4o-mini"
409398
);
399+
410400
const tokens = encoding.encode(content);
411401
const chunks: string[] = [];
412402
const textDecoder = new TextDecoder();

packages/core/src/runtime.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,9 @@ export class AgentRuntime implements IAgentRuntime {
344344
},
345345
});
346346
const fragments = await splitChunks(
347-
this,
348347
knowledgeItem,
349348
1200,
350-
200,
351-
"fast"
349+
200
352350
);
353351
for (const fragment of fragments) {
354352
const embedding = await embed(this, fragment);
@@ -900,10 +898,9 @@ Text: ${attachment.text}
900898
const memories = await runtime.knowledgeManager.searchMemoriesByEmbedding(
901899
embedding,
902900
{
903-
roomId: message.roomId,
904-
agentId: runtime.agentId,
905-
match_threshold: 0.95,
906-
count: 1,
901+
roomId: message.agentId,
902+
agentId: message.agentId,
903+
count: 3,
907904
}
908905
);
909906

packages/plugin-bootstrap/src/actions/continue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Note that {{agentName}} is capable of reading/seeing/hearing various forms of me
4545
4646
{{actions}}
4747
48-
# Instructions: Write the next message for {{agentName}}. Ignore "action".
48+
# Instructions: Write the next message for {{agentName}}.
4949
` + messageCompletionFooter;
5050

5151
export const shouldContinueTemplate =

0 commit comments

Comments
 (0)