Skip to content

Commit 8e14c96

Browse files
committed
feat: add validation to trimTokens
1 parent 4d52b9f commit 8e14c96

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

packages/core/src/generation.ts

+3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ export async function trimTokens(
7272
maxTokens: number,
7373
runtime: IAgentRuntime
7474
) {
75+
if (!context) return "";
76+
if (maxTokens <= 0) throw new Error("maxTokens must be positive");
77+
7578
const tokenizerModel = runtime.getSetting("TOKENIZER_MODEL");
7679
const tokenizerType = runtime.getSetting("TOKENIZER_TYPE");
7780

0 commit comments

Comments
 (0)