@@ -80,15 +80,15 @@ def test_chat_completion(self, client, api_type, api_version, **kwargs):
8080 @configure
8181 @pytest .mark .parametrize (
8282 "api_type, api_version" ,
83- [(AZURE , GA ), (AZURE , PREVIEW ), (OPENAI , "v1" )]
83+ [(GPT_4_AZURE , GA ), (GPT_4_AZURE , PREVIEW ), (OPENAI , "v1" )]
8484 )
8585 def test_streamed_chat_completions (self , client , api_type , api_version , ** kwargs ):
8686 messages = [
8787 {"role" : "system" , "content" : "You are a helpful assistant." },
8888 {"role" : "user" , "content" : "How do I bake a chocolate cake?" }
8989 ]
9090
91- response = client .chat .completions .create (messages = messages , stream = True , ** kwargs )
91+ response = client .chat .completions .create (messages = messages , stream = True , stream_options = { "include_usage" : True }, ** kwargs )
9292
9393 for completion in response :
9494 # API versions after 2023-05-15 send an empty first completion with RAI
@@ -100,6 +100,10 @@ def test_streamed_chat_completions(self, client, api_type, api_version, **kwargs
100100 for c in completion .choices :
101101 assert c .index is not None
102102 assert c .delta is not None
103+ if completion .usage :
104+ assert completion .usage .completion_tokens is not None
105+ assert completion .usage .prompt_tokens is not None
106+ assert completion .usage .total_tokens == completion .usage .completion_tokens + completion .usage .prompt_tokens
103107
104108 @configure
105109 @pytest .mark .parametrize (
@@ -1164,7 +1168,7 @@ def test_chat_completion_logprobs(self, client, api_type, api_version, **kwargs)
11641168 assert logprob .bytes is not None
11651169
11661170 @configure
1167- @pytest .mark .parametrize ("api_type, api_version" , [(GPT_4_AZURE , PREVIEW ), (GPT_4_OPENAI , "v1" )])
1171+ @pytest .mark .parametrize ("api_type, api_version" , [(GPT_4_AZURE , PREVIEW ), (GPT_4_AZURE , GA ), ( GPT_4_OPENAI , "v1" )])
11681172 def test_chat_completion_structured_outputs (self , client , api_type , api_version , ** kwargs ):
11691173
11701174 class Step (BaseModel ):
@@ -1202,3 +1206,50 @@ class MathResponse(BaseModel):
12021206 assert step .explanation
12031207 assert step .output
12041208 assert completion .choices [0 ].message .parsed .final_answer
1209+
1210+ @configure
1211+ @pytest .mark .parametrize ("api_type, api_version" , [(GPT_4_AZURE , GA ), (GPT_4_AZURE , PREVIEW ), (GPT_4_OPENAI , "v1" )])
1212+ def test_chat_completion_parallel_tool_calls_disable (self , client , api_type , api_version , ** kwargs ):
1213+ messages = [
1214+ {"role" : "system" , "content" : "Don't make assumptions about what values to plug into tools. Ask for clarification if a user request is ambiguous." },
1215+ {"role" : "user" , "content" : "What's the weather like today in Seattle and Los Angeles?" }
1216+ ]
1217+ tools = [
1218+ {
1219+ "type" : "function" ,
1220+ "function" : {
1221+ "name" : "get_current_weather" ,
1222+ "description" : "Get the current weather in a given location" ,
1223+ "parameters" : {
1224+ "type" : "object" ,
1225+ "properties" : {
1226+ "location" : {
1227+ "type" : "string" ,
1228+ "description" : "The city and state, e.g. San Francisco, CA" ,
1229+ },
1230+ "unit" : {"type" : "string" , "enum" : ["celsius" , "fahrenheit" ]},
1231+ },
1232+ "required" : ["location" ],
1233+ },
1234+ }
1235+ }
1236+ ]
1237+
1238+ completion = client .chat .completions .create (
1239+ messages = messages ,
1240+ tools = tools ,
1241+ parallel_tool_calls = False ,
1242+ ** kwargs
1243+ )
1244+ assert completion .id
1245+ assert completion .object == "chat.completion"
1246+ assert completion .model
1247+ assert completion .created
1248+ assert completion .usage .completion_tokens is not None
1249+ assert completion .usage .prompt_tokens is not None
1250+ assert completion .usage .total_tokens == completion .usage .completion_tokens + completion .usage .prompt_tokens
1251+ assert len (completion .choices ) == 1
1252+ assert completion .choices [0 ].finish_reason
1253+ assert completion .choices [0 ].index is not None
1254+ assert completion .choices [0 ].message .role
1255+ assert len (completion .choices [0 ].message .tool_calls ) == 1
0 commit comments