11import { expect } from "chai"
2- import {
3- estimateContentSize ,
4- estimateFileSize ,
5- estimateTokens ,
6- calculateMaxAllowedSize ,
7- wouldExceedSizeLimit ,
8- } from "./content-size"
2+ import { estimateContentSize , estimateFileSize , estimateTokens , wouldExceedSizeLimit } from "./content-size"
93import fs from "fs/promises"
104import path from "path"
115import os from "os"
126
13- const CONTEXT_LIMIT = 1000
7+ const CONTEXT_LIMIT = 1000 // Context limit of 1000 tokens means max allowed size is 500 tokens
148
159describe ( "content-size" , ( ) => {
16- describe ( "calculateMaxAllowedSize" , ( ) => {
17- it ( "calculates half of the context limit" , ( ) => {
18- expect ( calculateMaxAllowedSize ( 1000 ) ) . to . equal ( 500 )
19- expect ( calculateMaxAllowedSize ( 128000 ) ) . to . equal ( 64000 )
20- } )
21- } )
22-
2310 describe ( "estimateTokens" , ( ) => {
2411 it ( "estimates tokens based on byte count" , ( ) => {
2512 expect ( estimateTokens ( 100 ) ) . to . equal ( 25 ) // 100 bytes / 4 chars per token = 25 tokens
@@ -28,10 +15,10 @@ describe("content-size", () => {
2815 } )
2916
3017 describe ( "wouldExceedSizeLimit" , ( ) => {
31- it ( "checks if byte count would exceed half of context limit " , ( ) => {
32- expect ( wouldExceedSizeLimit ( 100 , 1000 ) ) . to . equal ( false ) // 25 tokens < 500 tokens
33- expect ( wouldExceedSizeLimit ( 2000 , 1000 ) ) . to . equal ( true ) // 500 tokens = 500 tokens (equal is considered exceeding)
34- expect ( wouldExceedSizeLimit ( 2004 , 1000 ) ) . to . equal ( true ) // 501 tokens > 500 tokens
18+ it ( "checks if byte count would exceed max allowed size " , ( ) => {
19+ expect ( wouldExceedSizeLimit ( 100 , 64_000 ) ) . to . equal ( false ) // 25 tokens < (64k - 27k) tokens
20+ expect ( wouldExceedSizeLimit ( 148000 , 64_000 ) ) . to . equal ( true ) // 37k tokens > (64k - 27k) tokens
21+ expect ( wouldExceedSizeLimit ( 392000 , 128_000 ) ) . to . equal ( true ) // 98k tokens > (128k - 30k) tokens
3522 } )
3623 } )
3724
@@ -54,10 +41,10 @@ describe("content-size", () => {
5441 expect ( result . wouldExceedLimit ) . to . equal ( false )
5542 } )
5643
57- it ( "detects when content would exceed half of context limit " , ( ) => {
58- const halfContextLimit = calculateMaxAllowedSize ( CONTEXT_LIMIT ) // 500 tokens
59- const largeContent = "x" . repeat ( halfContextLimit * 4 + 4 ) // Just over half context limit in tokens
60- const result = estimateContentSize ( largeContent , CONTEXT_LIMIT )
44+ it ( "detects when content would exceed max allowed size " , ( ) => {
45+ // Create content that would exceed max allowed size for deepseek (64k - 27k tokens)
46+ const largeContent = "x" . repeat ( 148000 ) // 37k tokens > (64k - 27k) tokens
47+ const result = estimateContentSize ( largeContent , 64_000 )
6148
6249 expect ( result . wouldExceedLimit ) . to . equal ( true )
6350 } )
0 commit comments