@@ -412,19 +412,19 @@ func hashPrompt(ctx context.Context, request *types.LLMRequest, blockSizeTokens
412412 }
413413
414414 // convert block size from tokens to characters
415- cacheBlockSize := blockSizeTokens * averageCharactersPerToken
415+ cacheBlockSizeChars := blockSizeTokens * averageCharactersPerToken
416416
417- if len (userInput ) < cacheBlockSize {
418- loggerDebug .Info ("Request body too small for prefix cache" , "size" , len (userInput ), "block size in chars" , cacheBlockSize )
417+ if len (userInput ) < cacheBlockSizeChars {
418+ loggerDebug .Info ("Request body too small for prefix cache" , "size" , len (userInput ), "block size in chars" , cacheBlockSizeChars )
419419 return nil
420420 }
421- if len (userInput ) > cacheBlockSize * maxPrefixBlocks {
422- loggerDebug .Info ("Truncating input" , "size" , len (userInput ), "max prefix blocks" , maxPrefixBlocks , "block size in chars" , cacheBlockSize )
423- userInput = userInput [:maxPrefixBlocks * cacheBlockSize ]
421+ if len (userInput ) > cacheBlockSizeChars * maxPrefixBlocks {
422+ loggerDebug .Info ("Truncating input" , "size" , len (userInput ), "max prefix blocks" , maxPrefixBlocks , "block size in chars" , cacheBlockSizeChars )
423+ userInput = userInput [:maxPrefixBlocks * cacheBlockSizeChars ]
424424 }
425425 // Split the body into blocks of size cacheBlockSize.
426426 // If the last block is smaller than cacheBlockSize, it will be ignored.
427- res := make ([]BlockHash , 0 , len (userInput )/ cacheBlockSize )
427+ res := make ([]BlockHash , 0 , len (userInput )/ cacheBlockSizeChars )
428428 // Add the model to the first block hash so that different models have different hashes even with the same body.
429429 h := xxhash .New ()
430430 _ , _ = h .Write ([]byte (request .TargetModel ))
@@ -433,9 +433,9 @@ func hashPrompt(ctx context.Context, request *types.LLMRequest, blockSizeTokens
433433 }
434434
435435 prevBlockHash := BlockHash (h .Sum64 ())
436- for i := 0 ; i + cacheBlockSize <= len (userInput ); i += cacheBlockSize {
436+ for i := 0 ; i + cacheBlockSizeChars <= len (userInput ); i += cacheBlockSizeChars {
437437 h .Reset ()
438- _ , _ = h .Write (userInput [i : i + cacheBlockSize ])
438+ _ , _ = h .Write (userInput [i : i + cacheBlockSizeChars ])
439439 _ , _ = h .Write (toBytes (prevBlockHash ))
440440 res = append (res , BlockHash (h .Sum64 ()))
441441
0 commit comments