@@ -3343,7 +3343,7 @@ def clean_cache(self):
33433343 @pytest .fixture
33443344 def model_with_client (self , bedrock_client , model_id ):
33453345 _ = bedrock_client
3346- return BedrockModel (model_id = model_id )
3346+ return BedrockModel (model_id = model_id , use_native_token_count = True )
33473347
33483348 @pytest .fixture
33493349 def messages (self ):
@@ -3459,7 +3459,7 @@ async def test_fallback_logs_debug(self, model_with_client, bedrock_client, mess
34593459
34603460 @pytest .mark .asyncio
34613461 async def test_caches_model_id_when_count_tokens_unsupported (self , bedrock_client , messages ):
3462- model = BedrockModel (model_id = "unsupported-cache-test-model" )
3462+ model = BedrockModel (model_id = "unsupported-cache-test-model" , use_native_token_count = True )
34633463 bedrock_client .count_tokens .side_effect = ClientError (
34643464 {"Error" : {"Code" : "ValidationException" , "Message" : "The provided model doesn't support counting tokens" }},
34653465 "CountTokens" ,
@@ -3475,7 +3475,7 @@ async def test_caches_model_id_when_count_tokens_unsupported(self, bedrock_clien
34753475
34763476 @pytest .mark .asyncio
34773477 async def test_caches_model_id_when_access_denied (self , bedrock_client , messages ):
3478- model = BedrockModel (model_id = "access-denied-cache-test-model" )
3478+ model = BedrockModel (model_id = "access-denied-cache-test-model" , use_native_token_count = True )
34793479 bedrock_client .count_tokens .side_effect = ClientError (
34803480 {
34813481 "Error" : {
@@ -3523,7 +3523,7 @@ async def test_access_denied_logs_warning_with_full_error(
35233523
35243524 @pytest .mark .asyncio
35253525 async def test_does_not_cache_model_id_for_other_errors (self , bedrock_client , messages ):
3526- model = BedrockModel (model_id = "transient-error-test-model" )
3526+ model = BedrockModel (model_id = "transient-error-test-model" , use_native_token_count = True )
35273527 bedrock_client .count_tokens .side_effect = RuntimeError ("Transient network error" )
35283528
35293529 await model .count_tokens (messages = messages )
@@ -3543,3 +3543,14 @@ async def test_skip_native_api_when_use_native_token_count_false(self, bedrock_c
35433543 bedrock_client .count_tokens .assert_not_called ()
35443544 assert isinstance (result , int )
35453545 assert result >= 0
3546+
3547+ @pytest .mark .asyncio
3548+ async def test_skip_native_api_by_default (self , bedrock_client , model_id , messages ):
3549+ _ = bedrock_client
3550+ model = BedrockModel (model_id = model_id )
3551+
3552+ result = await model .count_tokens (messages = messages )
3553+
3554+ bedrock_client .count_tokens .assert_not_called ()
3555+ assert isinstance (result , int )
3556+ assert result >= 0
0 commit comments