Skip to content

Commit 40f366d

Browse files
committed
feat(genai): Add local tokenizer samples for Count and Compute
1 parent 56b25f2 commit 40f366d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

genai/count_tokens/counttoken_with_txt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def count_tokens() -> int:
2525
)
2626
print(response)
2727
# Example output:
28-
# total_tokens=10
28+
# total_tokens=9
2929
# cached_content_token_count=None
3030
# [END googlegenaisdk_counttoken_with_txt]
3131
return response.total_tokens
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
google-genai==1.42.0
2+
sentencepiece==0.2.1

genai/count_tokens/test_count_tokens_examples.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import os
2020

2121
import counttoken_compute_with_txt
22+
import counttoken_localtokenizer_compute_with_txt
23+
import counttoken_localtokenizer_with_txt
2224
import counttoken_resp_with_txt
2325
import counttoken_with_txt
2426
import counttoken_with_txt_vid
@@ -43,3 +45,11 @@ def test_counttoken_with_txt() -> None:
4345

4446
def test_counttoken_with_txt_vid() -> None:
4547
assert counttoken_with_txt_vid.count_tokens()
48+
49+
50+
def test_counttoken_localtokenizer_with_txt() -> None:
51+
assert counttoken_localtokenizer_with_txt.counttoken_localtokenizer_with_txt()
52+
53+
54+
def test_counttoken_localtokenizer_compute_with_txt() -> None:
55+
assert counttoken_localtokenizer_compute_with_txt.counttoken_localtokenizer_compute_with_txt()

0 commit comments

Comments
 (0)