File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,15 @@ describe("tiktoken", () => {
2525 expect ( result ) . toBe ( 0 )
2626 } )
2727
28+ it ( "should not throw on text content with special tokens" , async ( ) => {
29+ const content : Anthropic . Messages . ContentBlockParam [ ] = [
30+ { type : "text" , text : "something<|endoftext|>something" } ,
31+ ]
32+
33+ const result = await tiktoken ( content )
34+ expect ( result ) . toBeGreaterThan ( 0 )
35+ } )
36+
2837 it ( "should handle missing text content" , async ( ) => {
2938 // Using 'as any' to bypass TypeScript's type checking for this test case
3039 // since we're specifically testing how the function handles undefined text
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ export async function tiktoken(content: Anthropic.Messages.ContentBlockParam[]):
2424 const text = block . text || ""
2525
2626 if ( text . length > 0 ) {
27- const tokens = encoder . encode ( text )
27+ const tokens = encoder . encode ( text , undefined , [ ] )
2828 totalTokens += tokens . length
2929 }
3030 } else if ( block . type === "image" ) {
You can’t perform that action at this time.
0 commit comments