Skip to content

Commit

Permalink
use tokenization service to trim token
Browse files Browse the repository at this point in the history
  • Loading branch information
tcm390 committed Dec 31, 2024
1 parent b74194c commit fc638e8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/plugin-node/src/services/browser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { generateText, IBrowserService, trimTokens } from "@elizaos/core";
import {
generateText,
IBrowserService,
ITokenizationService,
models,
} from "@elizaos/core";
import { parseJSONObjectFromText } from "@elizaos/core";
import { Service } from "@elizaos/core";
import { settings } from "@elizaos/core";
Expand All @@ -12,8 +17,16 @@ async function generateSummary(
runtime: IAgentRuntime,
text: string
): Promise<{ title: string; description: string }> {
const tokenizationService = runtime.getService<ITokenizationService>(
ServiceType.TOKENIZATION
);
const model = models[runtime.character.modelProvider];
// make sure text is under 128k characters
text = trimTokens(text, 100000, "gpt-4o-mini"); // TODO: clean this up
text = await tokenizationService.trimTokens(
text,
100000,
model.model[ModelClass.SMALL] || "gpt-4o-mini"
);

const prompt = `Please generate a concise summary for the following text:
Expand Down

0 comments on commit fc638e8

Please sign in to comment.