@@ -27,8 +27,12 @@ def server():
2727
2828
2929@pytest .mark .asyncio
30- async def test_basic_completion_with_emoji (server ):
30+ @pytest .mark .parametrize ("return_token_ids" , [True , False , None ])
31+ async def test_basic_completion_with_emoji (server , return_token_ids : bool | None ):
3132 """Test basic completion with emoji to verify token_ids field."""
33+ extra_body = None
34+ if return_token_ids is not None :
35+ extra_body = {"return_token_ids" : return_token_ids }
3236 async with server .get_async_client () as client :
3337 # Test with return_token_ids enabled
3438 completion = await client .completions .create (
@@ -37,14 +41,20 @@ async def test_basic_completion_with_emoji(server):
3741 max_tokens = 10 ,
3842 temperature = 0 ,
3943 logprobs = 1 ,
40- extra_body = { "return_token_ids" : True } ,
44+ extra_body = extra_body ,
4145 )
4246
4347 # Check the raw response to see the structure
4448 completion_dict = completion .model_dump ()
4549
4650 # Verify prompt_token_ids field is present in the completion response
4751 assert "prompt_token_ids" in completion_dict ["choices" ][0 ]
52+ if not return_token_ids :
53+ # If return_token_ids is False, token_ids should not be present
54+ assert completion_dict ["choices" ][0 ].get ("token_ids" ) is None
55+ assert completion_dict ["choices" ][0 ].get ("prompt_token_ids" ) is None
56+ # Skip further checks
57+ return
4858 assert isinstance (completion .choices [0 ].prompt_token_ids , list )
4959
5060 # Check against the expected prompt token IDs
0 commit comments