File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed
core/sliding-window/__tests__ Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -42,13 +42,15 @@ export abstract class BaseProvider implements ApiHandler {
4242 if ( block . type === "text" ) {
4343 // Use tiktoken for text token counting
4444 const text = block . text || ""
45+
4546 if ( text . length > 0 ) {
4647 const tokens = this . encoder . encode ( text )
4748 totalTokens += tokens . length
4849 }
4950 } else if ( block . type === "image" ) {
5051 // For images, calculate based on data size
5152 const imageSource = block . source
53+
5254 if ( imageSource && typeof imageSource === "object" && "data" in imageSource ) {
5355 const base64Data = imageSource . data as string
5456 totalTokens += Math . ceil ( Math . sqrt ( base64Data . length ) )
Original file line number Diff line number Diff line change 33import { Anthropic } from "@anthropic-ai/sdk"
44
55import { ModelInfo } from "../../../shared/api"
6- import { ApiHandler } from "../../../api"
76import { BaseProvider } from "../../../api/providers/base-provider"
8- import { TOKEN_BUFFER_PERCENTAGE } from "../index"
9- import { estimateTokenCount , truncateConversation , truncateConversationIfNeeded } from "../index"
7+ import {
8+ TOKEN_BUFFER_PERCENTAGE ,
9+ estimateTokenCount ,
10+ truncateConversation ,
11+ truncateConversationIfNeeded ,
12+ } from "../index"
1013
1114// Create a mock ApiHandler for testing
1215class MockApiHandler extends BaseProvider {
You can’t perform that action at this time.
0 commit comments