@@ -58,15 +58,29 @@ class ChatCompletion(EBResource, CreatableWithStreaming):
58
58
"ernie-3.5-8k" : {
59
59
"model_id" : "completions" ,
60
60
},
61
+ "ernie-3.5-8k-0205" : {
62
+ "model_id" : "ernie-3.5-8k-0205" ,
63
+ },
64
+ "ernie-3.5-8k-0329" : {
65
+ "model_id" : "ernie-3.5-8k-0329" ,
66
+ },
67
+ "ernie-3.5-128k" : {
68
+ "model_id" : "ernie-3.5-128k" ,
69
+ },
61
70
"ernie-lite" : {
62
71
"model_id" : "eb-instant" ,
63
72
},
73
+ "ernie-lite-8k-0308" : {
74
+ "model_id" : "ernie-lite-8k" ,
75
+ },
64
76
"ernie-4.0" : {
65
77
"model_id" : "completions_pro" ,
66
78
},
67
- "ernie-longtext" : {
68
- # ernie-longtext(ernie_bot_8k) will be deprecated in 2024.4.11
69
- "model_id" : "completions" ,
79
+ "ernie-4.0-8k-0329" : {
80
+ "model_id" : "ernie-4.0-8k-0329" ,
81
+ },
82
+ "ernie-4.0-8k-0104" : {
83
+ "model_id" : "ernie-4.0-8k-0104" ,
70
84
},
71
85
"ernie-speed" : {
72
86
"model_id" : "ernie_speed" ,
@@ -97,10 +111,6 @@ class ChatCompletion(EBResource, CreatableWithStreaming):
97
111
"ernie-4.0" : {
98
112
"model_id" : "completions_pro" ,
99
113
},
100
- "ernie-longtext" : {
101
- # ernie-longtext(ernie_bot_8k) will be deprecated in 2024.4.11
102
- "model_id" : "completions" ,
103
- },
104
114
"ernie-speed" : {
105
115
"model_id" : "ernie_speed" ,
106
116
},
@@ -156,6 +166,7 @@ def create(
156
166
extra_params : Optional [dict ] = ...,
157
167
headers : Optional [HeadersType ] = ...,
158
168
request_timeout : Optional [float ] = ...,
169
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
159
170
max_output_tokens : Optional [int ] = ...,
160
171
_config_ : Optional [ConfigDictType ] = ...,
161
172
) -> "ChatCompletionResponse" :
@@ -183,6 +194,7 @@ def create(
183
194
extra_params : Optional [dict ] = ...,
184
195
headers : Optional [HeadersType ] = ...,
185
196
request_timeout : Optional [float ] = ...,
197
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
186
198
max_output_tokens : Optional [int ] = ...,
187
199
_config_ : Optional [ConfigDictType ] = ...,
188
200
) -> Iterator ["ChatCompletionResponse" ]:
@@ -210,6 +222,7 @@ def create(
210
222
extra_params : Optional [dict ] = ...,
211
223
headers : Optional [HeadersType ] = ...,
212
224
request_timeout : Optional [float ] = ...,
225
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
213
226
max_output_tokens : Optional [int ] = ...,
214
227
_config_ : Optional [ConfigDictType ] = ...,
215
228
) -> Union ["ChatCompletionResponse" , Iterator ["ChatCompletionResponse" ]]:
@@ -236,6 +249,7 @@ def create(
236
249
extra_params : Optional [dict ] = None ,
237
250
headers : Optional [HeadersType ] = None ,
238
251
request_timeout : Optional [float ] = None ,
252
+ response_format : Optional [Literal ["json_object" , "text" ]] = None ,
239
253
max_output_tokens : Optional [int ] = None ,
240
254
_config_ : Optional [ConfigDictType ] = None ,
241
255
) -> Union ["ChatCompletionResponse" , Iterator ["ChatCompletionResponse" ]]:
@@ -292,6 +306,8 @@ def create(
292
306
kwargs ["headers" ] = headers
293
307
if request_timeout is not None :
294
308
kwargs ["request_timeout" ] = request_timeout
309
+ if response_format is not None :
310
+ kwargs ["response_format" ] = response_format
295
311
296
312
resp = resource .create_resource (** kwargs )
297
313
return transform (ChatCompletionResponse .from_mapping , resp )
@@ -318,6 +334,7 @@ async def acreate(
318
334
extra_params : Optional [dict ] = ...,
319
335
headers : Optional [HeadersType ] = ...,
320
336
request_timeout : Optional [float ] = ...,
337
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
321
338
max_output_tokens : Optional [int ] = ...,
322
339
_config_ : Optional [ConfigDictType ] = ...,
323
340
) -> EBResponse :
@@ -345,6 +362,7 @@ async def acreate(
345
362
extra_params : Optional [dict ] = ...,
346
363
headers : Optional [HeadersType ] = ...,
347
364
request_timeout : Optional [float ] = ...,
365
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
348
366
max_output_tokens : Optional [int ] = ...,
349
367
_config_ : Optional [ConfigDictType ] = ...,
350
368
) -> AsyncIterator ["ChatCompletionResponse" ]:
@@ -372,6 +390,7 @@ async def acreate(
372
390
extra_params : Optional [dict ] = ...,
373
391
headers : Optional [HeadersType ] = ...,
374
392
request_timeout : Optional [float ] = ...,
393
+ response_format : Optional [Literal ["json_object" , "text" ]] = ...,
375
394
max_output_tokens : Optional [int ] = ...,
376
395
_config_ : Optional [ConfigDictType ] = ...,
377
396
) -> Union ["ChatCompletionResponse" , AsyncIterator ["ChatCompletionResponse" ]]:
@@ -398,6 +417,7 @@ async def acreate(
398
417
extra_params : Optional [dict ] = None ,
399
418
headers : Optional [HeadersType ] = None ,
400
419
request_timeout : Optional [float ] = None ,
420
+ response_format : Optional [Literal ["json_object" , "text" ]] = None ,
401
421
max_output_tokens : Optional [int ] = None ,
402
422
_config_ : Optional [ConfigDictType ] = None ,
403
423
) -> Union ["ChatCompletionResponse" , AsyncIterator ["ChatCompletionResponse" ]]:
@@ -423,6 +443,7 @@ async def acreate(
423
443
validate_functions: Whether to validate the function descriptions.
424
444
headers: Custom headers to send with the request.
425
445
request_timeout: Timeout for a single request.
446
+ response_format: Format of the response.
426
447
_config_: Overrides the global settings.
427
448
428
449
Returns:
@@ -460,9 +481,11 @@ async def acreate(
460
481
461
482
def _check_model_kwargs (self , model_name : str , kwargs : Dict [str , Any ]) -> None :
462
483
if model_name in ("ernie-speed" , "ernie-speed-128k" , "ernie-char-8k" , "ernie-tiny-8k" , "ernie-lite" ):
463
- for arg in ("functions" , "disable_search" , "enable_citation" , "tool_choice" ):
484
+ for arg in ("functions" , "disable_search" , "enable_citation" , "tool_choice" , "response_format" ):
464
485
if arg in kwargs :
465
- raise errors .InvalidArgumentError (f"`{ arg } ` is not supported by the { model_name } model." )
486
+ raise errors .InvalidArgumentError (
487
+ f"`{ arg } ` is not supported by the `{ model_name } ` model."
488
+ )
466
489
467
490
def _prepare_create (self , kwargs : Dict [str , Any ]) -> RequestWithStream :
468
491
def _update_model_name (given_name : str , old_name_to_new_name : Dict [str , str ]) -> str :
@@ -497,6 +520,7 @@ def _set_val_if_key_exists(src: dict, dst: dict, key: str) -> None:
497
520
"extra_params" ,
498
521
"headers" ,
499
522
"request_timeout" ,
523
+ "response_format" ,
500
524
"max_output_tokens" ,
501
525
}
502
526
@@ -561,6 +585,7 @@ def _set_val_if_key_exists(src: dict, dst: dict, key: str) -> None:
561
585
_set_val_if_key_exists (kwargs , params , "tool_choice" )
562
586
_set_val_if_key_exists (kwargs , params , "stream" )
563
587
_set_val_if_key_exists (kwargs , params , "max_output_tokens" )
588
+ _set_val_if_key_exists (kwargs , params , "response_format" )
564
589
565
590
if "extra_params" in kwargs :
566
591
params .update (kwargs ["extra_params" ])
0 commit comments