mistralai 1.0.2__py3-none-any.whl → 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. mistralai/_hooks/sdkhooks.py +23 -4
  2. mistralai/_hooks/types.py +27 -9
  3. mistralai/agents.py +286 -150
  4. mistralai/basesdk.py +90 -5
  5. mistralai/chat.py +260 -144
  6. mistralai/embeddings.py +73 -53
  7. mistralai/files.py +252 -192
  8. mistralai/fim.py +174 -110
  9. mistralai/fine_tuning.py +3 -2
  10. mistralai/jobs.py +372 -263
  11. mistralai/models/__init__.py +499 -46
  12. mistralai/models/agentscompletionrequest.py +47 -11
  13. mistralai/models/agentscompletionstreamrequest.py +49 -11
  14. mistralai/models/archiveftmodelout.py +6 -2
  15. mistralai/models/assistantmessage.py +11 -4
  16. mistralai/models/{modelcard.py → basemodelcard.py} +37 -14
  17. mistralai/models/chatcompletionchoice.py +4 -2
  18. mistralai/models/chatcompletionrequest.py +57 -11
  19. mistralai/models/chatcompletionresponse.py +6 -2
  20. mistralai/models/chatcompletionstreamrequest.py +59 -11
  21. mistralai/models/checkpointout.py +3 -2
  22. mistralai/models/completionchunk.py +10 -3
  23. mistralai/models/completionevent.py +1 -2
  24. mistralai/models/completionresponsestreamchoice.py +13 -5
  25. mistralai/models/contentchunk.py +13 -10
  26. mistralai/models/delete_model_v1_models_model_id_deleteop.py +4 -3
  27. mistralai/models/deletefileout.py +3 -2
  28. mistralai/models/deletemodelout.py +3 -2
  29. mistralai/models/deltamessage.py +9 -4
  30. mistralai/models/detailedjobout.py +59 -7
  31. mistralai/models/embeddingrequest.py +9 -4
  32. mistralai/models/embeddingresponse.py +5 -2
  33. mistralai/models/embeddingresponsedata.py +3 -2
  34. mistralai/models/eventout.py +9 -4
  35. mistralai/models/files_api_routes_delete_fileop.py +4 -3
  36. mistralai/models/files_api_routes_retrieve_fileop.py +4 -3
  37. mistralai/models/files_api_routes_upload_fileop.py +27 -8
  38. mistralai/models/fileschema.py +26 -5
  39. mistralai/models/fimcompletionrequest.py +26 -5
  40. mistralai/models/fimcompletionresponse.py +6 -2
  41. mistralai/models/fimcompletionstreamrequest.py +26 -5
  42. mistralai/models/finetuneablemodel.py +7 -1
  43. mistralai/models/ftmodelcapabilitiesout.py +4 -2
  44. mistralai/models/ftmodelcard.py +103 -0
  45. mistralai/models/ftmodelout.py +32 -6
  46. mistralai/models/function.py +3 -2
  47. mistralai/models/functioncall.py +2 -2
  48. mistralai/models/functionname.py +17 -0
  49. mistralai/models/githubrepositoryin.py +15 -4
  50. mistralai/models/githubrepositoryout.py +15 -4
  51. mistralai/models/httpvalidationerror.py +2 -2
  52. mistralai/models/imageurl.py +48 -0
  53. mistralai/models/imageurlchunk.py +32 -0
  54. mistralai/models/jobin.py +22 -5
  55. mistralai/models/jobmetadataout.py +31 -6
  56. mistralai/models/jobout.py +55 -7
  57. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +4 -3
  58. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +4 -3
  59. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
  60. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +4 -3
  61. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +83 -16
  62. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +4 -3
  63. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +4 -3
  64. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +9 -4
  65. mistralai/models/jobsout.py +6 -2
  66. mistralai/models/legacyjobmetadataout.py +45 -6
  67. mistralai/models/listfilesout.py +2 -2
  68. mistralai/models/metricout.py +11 -6
  69. mistralai/models/modelcapabilities.py +7 -2
  70. mistralai/models/modellist.py +21 -7
  71. mistralai/models/responseformat.py +6 -7
  72. mistralai/models/responseformats.py +8 -0
  73. mistralai/models/retrieve_model_v1_models_model_id_getop.py +24 -5
  74. mistralai/models/retrievefileout.py +26 -5
  75. mistralai/models/security.py +12 -3
  76. mistralai/models/systemmessage.py +6 -5
  77. mistralai/models/textchunk.py +9 -4
  78. mistralai/models/tool.py +9 -8
  79. mistralai/models/toolcall.py +9 -7
  80. mistralai/models/toolchoice.py +29 -0
  81. mistralai/models/toolchoiceenum.py +7 -0
  82. mistralai/models/toolmessage.py +11 -4
  83. mistralai/models/tooltypes.py +8 -0
  84. mistralai/models/trainingfile.py +2 -2
  85. mistralai/models/trainingparameters.py +27 -6
  86. mistralai/models/trainingparametersin.py +29 -8
  87. mistralai/models/unarchiveftmodelout.py +6 -2
  88. mistralai/models/updateftmodelin.py +8 -4
  89. mistralai/models/uploadfileout.py +26 -5
  90. mistralai/models/usageinfo.py +3 -2
  91. mistralai/models/usermessage.py +6 -5
  92. mistralai/models/validationerror.py +3 -2
  93. mistralai/models/wandbintegration.py +14 -4
  94. mistralai/models/wandbintegrationout.py +13 -4
  95. mistralai/models_.py +392 -294
  96. mistralai/sdk.py +24 -19
  97. mistralai/sdkconfiguration.py +6 -8
  98. mistralai/utils/__init__.py +6 -1
  99. mistralai/utils/logger.py +4 -1
  100. mistralai/utils/retries.py +2 -1
  101. mistralai/utils/security.py +13 -6
  102. {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/METADATA +103 -74
  103. mistralai-1.1.0.dist-info/RECORD +254 -0
  104. mistralai_azure/_hooks/sdkhooks.py +23 -4
  105. mistralai_azure/_hooks/types.py +27 -9
  106. mistralai_azure/basesdk.py +91 -6
  107. mistralai_azure/chat.py +252 -144
  108. mistralai_azure/models/__init__.py +157 -15
  109. mistralai_azure/models/assistantmessage.py +18 -5
  110. mistralai_azure/models/chatcompletionchoice.py +7 -3
  111. mistralai_azure/models/chatcompletionrequest.py +65 -12
  112. mistralai_azure/models/chatcompletionresponse.py +6 -2
  113. mistralai_azure/models/chatcompletionstreamrequest.py +67 -12
  114. mistralai_azure/models/completionchunk.py +10 -3
  115. mistralai_azure/models/completionevent.py +1 -2
  116. mistralai_azure/models/completionresponsestreamchoice.py +10 -4
  117. mistralai_azure/models/contentchunk.py +4 -11
  118. mistralai_azure/models/deltamessage.py +16 -5
  119. mistralai_azure/models/function.py +3 -2
  120. mistralai_azure/models/functioncall.py +2 -2
  121. mistralai_azure/models/functionname.py +17 -0
  122. mistralai_azure/models/httpvalidationerror.py +2 -2
  123. mistralai_azure/models/responseformat.py +6 -7
  124. mistralai_azure/models/responseformats.py +8 -0
  125. mistralai_azure/models/security.py +12 -3
  126. mistralai_azure/models/systemmessage.py +6 -5
  127. mistralai_azure/models/textchunk.py +9 -4
  128. mistralai_azure/models/tool.py +9 -8
  129. mistralai_azure/models/toolcall.py +9 -7
  130. mistralai_azure/models/toolchoice.py +29 -0
  131. mistralai_azure/models/toolchoiceenum.py +7 -0
  132. mistralai_azure/models/toolmessage.py +18 -5
  133. mistralai_azure/models/tooltypes.py +8 -0
  134. mistralai_azure/models/usageinfo.py +3 -2
  135. mistralai_azure/models/usermessage.py +6 -5
  136. mistralai_azure/models/validationerror.py +3 -2
  137. mistralai_azure/sdkconfiguration.py +6 -8
  138. mistralai_azure/utils/__init__.py +8 -3
  139. mistralai_azure/utils/forms.py +10 -9
  140. mistralai_azure/utils/headers.py +8 -8
  141. mistralai_azure/utils/logger.py +6 -0
  142. mistralai_azure/utils/queryparams.py +16 -14
  143. mistralai_azure/utils/retries.py +2 -1
  144. mistralai_azure/utils/security.py +12 -6
  145. mistralai_azure/utils/serializers.py +17 -8
  146. mistralai_azure/utils/url.py +13 -8
  147. mistralai_azure/utils/values.py +6 -0
  148. mistralai_gcp/_hooks/sdkhooks.py +23 -4
  149. mistralai_gcp/_hooks/types.py +27 -9
  150. mistralai_gcp/basesdk.py +91 -6
  151. mistralai_gcp/chat.py +252 -144
  152. mistralai_gcp/fim.py +166 -110
  153. mistralai_gcp/models/__init__.py +179 -17
  154. mistralai_gcp/models/assistantmessage.py +18 -5
  155. mistralai_gcp/models/chatcompletionchoice.py +7 -3
  156. mistralai_gcp/models/chatcompletionrequest.py +62 -12
  157. mistralai_gcp/models/chatcompletionresponse.py +6 -2
  158. mistralai_gcp/models/chatcompletionstreamrequest.py +64 -12
  159. mistralai_gcp/models/completionchunk.py +10 -3
  160. mistralai_gcp/models/completionevent.py +1 -2
  161. mistralai_gcp/models/completionresponsestreamchoice.py +10 -4
  162. mistralai_gcp/models/contentchunk.py +4 -11
  163. mistralai_gcp/models/deltamessage.py +16 -5
  164. mistralai_gcp/models/fimcompletionrequest.py +33 -6
  165. mistralai_gcp/models/fimcompletionresponse.py +6 -2
  166. mistralai_gcp/models/fimcompletionstreamrequest.py +33 -6
  167. mistralai_gcp/models/function.py +3 -2
  168. mistralai_gcp/models/functioncall.py +2 -2
  169. mistralai_gcp/models/functionname.py +17 -0
  170. mistralai_gcp/models/httpvalidationerror.py +2 -2
  171. mistralai_gcp/models/responseformat.py +6 -7
  172. mistralai_gcp/models/responseformats.py +8 -0
  173. mistralai_gcp/models/security.py +12 -3
  174. mistralai_gcp/models/systemmessage.py +6 -5
  175. mistralai_gcp/models/textchunk.py +9 -4
  176. mistralai_gcp/models/tool.py +9 -8
  177. mistralai_gcp/models/toolcall.py +9 -7
  178. mistralai_gcp/models/toolchoice.py +29 -0
  179. mistralai_gcp/models/toolchoiceenum.py +7 -0
  180. mistralai_gcp/models/toolmessage.py +18 -5
  181. mistralai_gcp/models/tooltypes.py +8 -0
  182. mistralai_gcp/models/usageinfo.py +3 -2
  183. mistralai_gcp/models/usermessage.py +6 -5
  184. mistralai_gcp/models/validationerror.py +3 -2
  185. mistralai_gcp/sdk.py +14 -10
  186. mistralai_gcp/sdkconfiguration.py +6 -8
  187. mistralai_gcp/utils/__init__.py +8 -3
  188. mistralai_gcp/utils/forms.py +10 -9
  189. mistralai_gcp/utils/headers.py +8 -8
  190. mistralai_gcp/utils/logger.py +6 -0
  191. mistralai_gcp/utils/queryparams.py +16 -14
  192. mistralai_gcp/utils/retries.py +2 -1
  193. mistralai_gcp/utils/security.py +12 -6
  194. mistralai_gcp/utils/serializers.py +17 -8
  195. mistralai_gcp/utils/url.py +13 -8
  196. mistralai_gcp/utils/values.py +6 -0
  197. mistralai-1.0.2.dist-info/RECORD +0 -236
  198. {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/LICENSE +0 -0
  199. {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/WHEEL +0 -0
mistralai_azure/chat.py CHANGED
@@ -7,12 +7,13 @@ from mistralai_azure.types import OptionalNullable, UNSET
7
7
  from mistralai_azure.utils import eventstreaming
8
8
  from typing import Any, AsyncGenerator, Generator, List, Optional, Union
9
9
 
10
+
10
11
  class Chat(BaseSDK):
11
12
  r"""Chat Completion API."""
12
-
13
-
13
+
14
14
  def stream(
15
- self, *,
15
+ self,
16
+ *,
16
17
  messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
17
18
  model: OptionalNullable[str] = "azureai",
18
19
  temperature: Optional[float] = 0.7,
@@ -22,9 +23,18 @@ class Chat(BaseSDK):
22
23
  stream: Optional[bool] = True,
23
24
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
24
25
  random_seed: OptionalNullable[int] = UNSET,
25
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
26
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
27
- tool_choice: Optional[models.ToolChoice] = "auto",
26
+ response_format: Optional[
27
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
28
+ ] = None,
29
+ tools: OptionalNullable[
30
+ Union[List[models.Tool], List[models.ToolTypedDict]]
31
+ ] = UNSET,
32
+ tool_choice: Optional[
33
+ Union[
34
+ models.ChatCompletionStreamRequestToolChoice,
35
+ models.ChatCompletionStreamRequestToolChoiceTypedDict,
36
+ ]
37
+ ] = None,
28
38
  safe_prompt: Optional[bool] = False,
29
39
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
30
40
  server_url: Optional[str] = None,
@@ -40,12 +50,12 @@ class Chat(BaseSDK):
40
50
  :param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
41
51
  :param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
42
52
  :param min_tokens: The minimum number of tokens to generate in the completion.
43
- :param stream:
53
+ :param stream:
44
54
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
45
55
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
46
- :param response_format:
47
- :param tools:
48
- :param tool_choice:
56
+ :param response_format:
57
+ :param tools:
58
+ :param tool_choice:
49
59
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
50
60
  :param retries: Override the default retry configuration for this method
51
61
  :param server_url: Override the default server URL for this method
@@ -55,10 +65,10 @@ class Chat(BaseSDK):
55
65
  url_variables = None
56
66
  if timeout_ms is None:
57
67
  timeout_ms = self.sdk_configuration.timeout_ms
58
-
68
+
59
69
  if server_url is not None:
60
70
  base_url = server_url
61
-
71
+
62
72
  request = models.ChatCompletionStreamRequest(
63
73
  model=model,
64
74
  temperature=temperature,
@@ -69,12 +79,16 @@ class Chat(BaseSDK):
69
79
  stop=stop,
70
80
  random_seed=random_seed,
71
81
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
72
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
82
+ response_format=utils.get_pydantic_model(
83
+ response_format, Optional[models.ResponseFormat]
84
+ ),
73
85
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
74
- tool_choice=tool_choice,
86
+ tool_choice=utils.get_pydantic_model(
87
+ tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
88
+ ),
75
89
  safe_prompt=safe_prompt,
76
90
  )
77
-
91
+
78
92
  req = self.build_request(
79
93
  method="POST",
80
94
  path="/chat/completions#stream",
@@ -87,48 +101,58 @@ class Chat(BaseSDK):
87
101
  user_agent_header="user-agent",
88
102
  accept_header_value="text/event-stream",
89
103
  security=self.sdk_configuration.security,
90
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
104
+ get_serialized_body=lambda: utils.serialize_request_body(
105
+ request, False, False, "json", models.ChatCompletionStreamRequest
106
+ ),
91
107
  timeout_ms=timeout_ms,
92
108
  )
93
-
109
+
94
110
  if retries == UNSET:
95
111
  if self.sdk_configuration.retry_config is not UNSET:
96
112
  retries = self.sdk_configuration.retry_config
97
113
 
98
114
  retry_config = None
99
115
  if isinstance(retries, utils.RetryConfig):
100
- retry_config = (retries, [
101
- "429",
102
- "500",
103
- "502",
104
- "503",
105
- "504"
106
- ])
107
-
116
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
117
+
108
118
  http_res = self.do_request(
109
- hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
119
+ hook_ctx=HookContext(
120
+ operation_id="stream_chat",
121
+ oauth2_scopes=[],
122
+ security_source=self.sdk_configuration.security,
123
+ ),
110
124
  request=req,
111
- error_status_codes=["422","4XX","5XX"],
125
+ error_status_codes=["422", "4XX", "5XX"],
112
126
  stream=True,
113
- retry_config=retry_config
127
+ retry_config=retry_config,
114
128
  )
115
-
129
+
116
130
  data: Any = None
117
131
  if utils.match_response(http_res, "200", "text/event-stream"):
118
- return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
132
+ return eventstreaming.stream_events(
133
+ http_res,
134
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
135
+ sentinel="[DONE]",
136
+ )
119
137
  if utils.match_response(http_res, "422", "application/json"):
120
138
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
121
139
  raise models.HTTPValidationError(data=data)
122
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
123
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
124
-
140
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
141
+ raise models.SDKError(
142
+ "API error occurred", http_res.status_code, http_res.text, http_res
143
+ )
144
+
125
145
  content_type = http_res.headers.get("Content-Type")
126
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
146
+ raise models.SDKError(
147
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
148
+ http_res.status_code,
149
+ http_res.text,
150
+ http_res,
151
+ )
127
152
 
128
-
129
-
130
153
  async def stream_async(
131
- self, *,
154
+ self,
155
+ *,
132
156
  messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
133
157
  model: OptionalNullable[str] = "azureai",
134
158
  temperature: Optional[float] = 0.7,
@@ -138,9 +162,18 @@ class Chat(BaseSDK):
138
162
  stream: Optional[bool] = True,
139
163
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
140
164
  random_seed: OptionalNullable[int] = UNSET,
141
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
142
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
143
- tool_choice: Optional[models.ToolChoice] = "auto",
165
+ response_format: Optional[
166
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
167
+ ] = None,
168
+ tools: OptionalNullable[
169
+ Union[List[models.Tool], List[models.ToolTypedDict]]
170
+ ] = UNSET,
171
+ tool_choice: Optional[
172
+ Union[
173
+ models.ChatCompletionStreamRequestToolChoice,
174
+ models.ChatCompletionStreamRequestToolChoiceTypedDict,
175
+ ]
176
+ ] = None,
144
177
  safe_prompt: Optional[bool] = False,
145
178
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
146
179
  server_url: Optional[str] = None,
@@ -156,12 +189,12 @@ class Chat(BaseSDK):
156
189
  :param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
157
190
  :param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
158
191
  :param min_tokens: The minimum number of tokens to generate in the completion.
159
- :param stream:
192
+ :param stream:
160
193
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
161
194
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
162
- :param response_format:
163
- :param tools:
164
- :param tool_choice:
195
+ :param response_format:
196
+ :param tools:
197
+ :param tool_choice:
165
198
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
166
199
  :param retries: Override the default retry configuration for this method
167
200
  :param server_url: Override the default server URL for this method
@@ -171,10 +204,10 @@ class Chat(BaseSDK):
171
204
  url_variables = None
172
205
  if timeout_ms is None:
173
206
  timeout_ms = self.sdk_configuration.timeout_ms
174
-
207
+
175
208
  if server_url is not None:
176
209
  base_url = server_url
177
-
210
+
178
211
  request = models.ChatCompletionStreamRequest(
179
212
  model=model,
180
213
  temperature=temperature,
@@ -185,13 +218,17 @@ class Chat(BaseSDK):
185
218
  stop=stop,
186
219
  random_seed=random_seed,
187
220
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
188
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
221
+ response_format=utils.get_pydantic_model(
222
+ response_format, Optional[models.ResponseFormat]
223
+ ),
189
224
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
190
- tool_choice=tool_choice,
225
+ tool_choice=utils.get_pydantic_model(
226
+ tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
227
+ ),
191
228
  safe_prompt=safe_prompt,
192
229
  )
193
-
194
- req = self.build_request(
230
+
231
+ req = self.build_request_async(
195
232
  method="POST",
196
233
  path="/chat/completions#stream",
197
234
  base_url=base_url,
@@ -203,60 +240,87 @@ class Chat(BaseSDK):
203
240
  user_agent_header="user-agent",
204
241
  accept_header_value="text/event-stream",
205
242
  security=self.sdk_configuration.security,
206
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
243
+ get_serialized_body=lambda: utils.serialize_request_body(
244
+ request, False, False, "json", models.ChatCompletionStreamRequest
245
+ ),
207
246
  timeout_ms=timeout_ms,
208
247
  )
209
-
248
+
210
249
  if retries == UNSET:
211
250
  if self.sdk_configuration.retry_config is not UNSET:
212
251
  retries = self.sdk_configuration.retry_config
213
252
 
214
253
  retry_config = None
215
254
  if isinstance(retries, utils.RetryConfig):
216
- retry_config = (retries, [
217
- "429",
218
- "500",
219
- "502",
220
- "503",
221
- "504"
222
- ])
223
-
255
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
256
+
224
257
  http_res = await self.do_request_async(
225
- hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
258
+ hook_ctx=HookContext(
259
+ operation_id="stream_chat",
260
+ oauth2_scopes=[],
261
+ security_source=self.sdk_configuration.security,
262
+ ),
226
263
  request=req,
227
- error_status_codes=["422","4XX","5XX"],
264
+ error_status_codes=["422", "4XX", "5XX"],
228
265
  stream=True,
229
- retry_config=retry_config
266
+ retry_config=retry_config,
230
267
  )
231
-
268
+
232
269
  data: Any = None
233
270
  if utils.match_response(http_res, "200", "text/event-stream"):
234
- return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
271
+ return eventstreaming.stream_events_async(
272
+ http_res,
273
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
274
+ sentinel="[DONE]",
275
+ )
235
276
  if utils.match_response(http_res, "422", "application/json"):
236
277
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
237
278
  raise models.HTTPValidationError(data=data)
238
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
239
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
240
-
279
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
280
+ raise models.SDKError(
281
+ "API error occurred", http_res.status_code, http_res.text, http_res
282
+ )
283
+
241
284
  content_type = http_res.headers.get("Content-Type")
242
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
285
+ raise models.SDKError(
286
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
287
+ http_res.status_code,
288
+ http_res.text,
289
+ http_res,
290
+ )
243
291
 
244
-
245
-
246
292
  def complete(
247
- self, *,
248
- messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
293
+ self,
294
+ *,
295
+ messages: Union[
296
+ List[models.ChatCompletionRequestMessages],
297
+ List[models.ChatCompletionRequestMessagesTypedDict],
298
+ ],
249
299
  model: OptionalNullable[str] = "azureai",
250
300
  temperature: Optional[float] = 0.7,
251
301
  top_p: Optional[float] = 1,
252
302
  max_tokens: OptionalNullable[int] = UNSET,
253
303
  min_tokens: OptionalNullable[int] = UNSET,
254
304
  stream: Optional[bool] = False,
255
- stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
305
+ stop: Optional[
306
+ Union[
307
+ models.ChatCompletionRequestStop,
308
+ models.ChatCompletionRequestStopTypedDict,
309
+ ]
310
+ ] = None,
256
311
  random_seed: OptionalNullable[int] = UNSET,
257
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
258
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
259
- tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
312
+ response_format: Optional[
313
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
314
+ ] = None,
315
+ tools: OptionalNullable[
316
+ Union[List[models.Tool], List[models.ToolTypedDict]]
317
+ ] = UNSET,
318
+ tool_choice: Optional[
319
+ Union[
320
+ models.ChatCompletionRequestToolChoice,
321
+ models.ChatCompletionRequestToolChoiceTypedDict,
322
+ ]
323
+ ] = None,
260
324
  safe_prompt: Optional[bool] = False,
261
325
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
262
326
  server_url: Optional[str] = None,
@@ -273,9 +337,9 @@ class Chat(BaseSDK):
273
337
  :param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
274
338
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
275
339
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
276
- :param response_format:
277
- :param tools:
278
- :param tool_choice:
340
+ :param response_format:
341
+ :param tools:
342
+ :param tool_choice:
279
343
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
280
344
  :param retries: Override the default retry configuration for this method
281
345
  :param server_url: Override the default server URL for this method
@@ -285,10 +349,10 @@ class Chat(BaseSDK):
285
349
  url_variables = None
286
350
  if timeout_ms is None:
287
351
  timeout_ms = self.sdk_configuration.timeout_ms
288
-
352
+
289
353
  if server_url is not None:
290
354
  base_url = server_url
291
-
355
+
292
356
  request = models.ChatCompletionRequest(
293
357
  model=model,
294
358
  temperature=temperature,
@@ -298,13 +362,19 @@ class Chat(BaseSDK):
298
362
  stream=stream,
299
363
  stop=stop,
300
364
  random_seed=random_seed,
301
- messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
302
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
365
+ messages=utils.get_pydantic_model(
366
+ messages, List[models.ChatCompletionRequestMessages]
367
+ ),
368
+ response_format=utils.get_pydantic_model(
369
+ response_format, Optional[models.ResponseFormat]
370
+ ),
303
371
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
304
- tool_choice=tool_choice,
372
+ tool_choice=utils.get_pydantic_model(
373
+ tool_choice, Optional[models.ChatCompletionRequestToolChoice]
374
+ ),
305
375
  safe_prompt=safe_prompt,
306
376
  )
307
-
377
+
308
378
  req = self.build_request(
309
379
  method="POST",
310
380
  path="/chat/completions",
@@ -317,59 +387,84 @@ class Chat(BaseSDK):
317
387
  user_agent_header="user-agent",
318
388
  accept_header_value="application/json",
319
389
  security=self.sdk_configuration.security,
320
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
390
+ get_serialized_body=lambda: utils.serialize_request_body(
391
+ request, False, False, "json", models.ChatCompletionRequest
392
+ ),
321
393
  timeout_ms=timeout_ms,
322
394
  )
323
-
395
+
324
396
  if retries == UNSET:
325
397
  if self.sdk_configuration.retry_config is not UNSET:
326
398
  retries = self.sdk_configuration.retry_config
327
399
 
328
400
  retry_config = None
329
401
  if isinstance(retries, utils.RetryConfig):
330
- retry_config = (retries, [
331
- "429",
332
- "500",
333
- "502",
334
- "503",
335
- "504"
336
- ])
337
-
402
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
403
+
338
404
  http_res = self.do_request(
339
- hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
405
+ hook_ctx=HookContext(
406
+ operation_id="chat_completion_v1_chat_completions_post",
407
+ oauth2_scopes=[],
408
+ security_source=self.sdk_configuration.security,
409
+ ),
340
410
  request=req,
341
- error_status_codes=["422","4XX","5XX"],
342
- retry_config=retry_config
411
+ error_status_codes=["422", "4XX", "5XX"],
412
+ retry_config=retry_config,
343
413
  )
344
-
414
+
345
415
  data: Any = None
346
416
  if utils.match_response(http_res, "200", "application/json"):
347
- return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
417
+ return utils.unmarshal_json(
418
+ http_res.text, Optional[models.ChatCompletionResponse]
419
+ )
348
420
  if utils.match_response(http_res, "422", "application/json"):
349
421
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
350
422
  raise models.HTTPValidationError(data=data)
351
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
352
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
353
-
423
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
424
+ raise models.SDKError(
425
+ "API error occurred", http_res.status_code, http_res.text, http_res
426
+ )
427
+
354
428
  content_type = http_res.headers.get("Content-Type")
355
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
429
+ raise models.SDKError(
430
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
431
+ http_res.status_code,
432
+ http_res.text,
433
+ http_res,
434
+ )
356
435
 
357
-
358
-
359
436
  async def complete_async(
360
- self, *,
361
- messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
437
+ self,
438
+ *,
439
+ messages: Union[
440
+ List[models.ChatCompletionRequestMessages],
441
+ List[models.ChatCompletionRequestMessagesTypedDict],
442
+ ],
362
443
  model: OptionalNullable[str] = "azureai",
363
444
  temperature: Optional[float] = 0.7,
364
445
  top_p: Optional[float] = 1,
365
446
  max_tokens: OptionalNullable[int] = UNSET,
366
447
  min_tokens: OptionalNullable[int] = UNSET,
367
448
  stream: Optional[bool] = False,
368
- stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
449
+ stop: Optional[
450
+ Union[
451
+ models.ChatCompletionRequestStop,
452
+ models.ChatCompletionRequestStopTypedDict,
453
+ ]
454
+ ] = None,
369
455
  random_seed: OptionalNullable[int] = UNSET,
370
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
371
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
372
- tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
456
+ response_format: Optional[
457
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
458
+ ] = None,
459
+ tools: OptionalNullable[
460
+ Union[List[models.Tool], List[models.ToolTypedDict]]
461
+ ] = UNSET,
462
+ tool_choice: Optional[
463
+ Union[
464
+ models.ChatCompletionRequestToolChoice,
465
+ models.ChatCompletionRequestToolChoiceTypedDict,
466
+ ]
467
+ ] = None,
373
468
  safe_prompt: Optional[bool] = False,
374
469
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
375
470
  server_url: Optional[str] = None,
@@ -386,9 +481,9 @@ class Chat(BaseSDK):
386
481
  :param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
387
482
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
388
483
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
389
- :param response_format:
390
- :param tools:
391
- :param tool_choice:
484
+ :param response_format:
485
+ :param tools:
486
+ :param tool_choice:
392
487
  :param safe_prompt: Whether to inject a safety prompt before all conversations.
393
488
  :param retries: Override the default retry configuration for this method
394
489
  :param server_url: Override the default server URL for this method
@@ -398,10 +493,10 @@ class Chat(BaseSDK):
398
493
  url_variables = None
399
494
  if timeout_ms is None:
400
495
  timeout_ms = self.sdk_configuration.timeout_ms
401
-
496
+
402
497
  if server_url is not None:
403
498
  base_url = server_url
404
-
499
+
405
500
  request = models.ChatCompletionRequest(
406
501
  model=model,
407
502
  temperature=temperature,
@@ -411,14 +506,20 @@ class Chat(BaseSDK):
411
506
  stream=stream,
412
507
  stop=stop,
413
508
  random_seed=random_seed,
414
- messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
415
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
509
+ messages=utils.get_pydantic_model(
510
+ messages, List[models.ChatCompletionRequestMessages]
511
+ ),
512
+ response_format=utils.get_pydantic_model(
513
+ response_format, Optional[models.ResponseFormat]
514
+ ),
416
515
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
417
- tool_choice=tool_choice,
516
+ tool_choice=utils.get_pydantic_model(
517
+ tool_choice, Optional[models.ChatCompletionRequestToolChoice]
518
+ ),
418
519
  safe_prompt=safe_prompt,
419
520
  )
420
-
421
- req = self.build_request(
521
+
522
+ req = self.build_request_async(
422
523
  method="POST",
423
524
  path="/chat/completions",
424
525
  base_url=base_url,
@@ -430,41 +531,48 @@ class Chat(BaseSDK):
430
531
  user_agent_header="user-agent",
431
532
  accept_header_value="application/json",
432
533
  security=self.sdk_configuration.security,
433
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
534
+ get_serialized_body=lambda: utils.serialize_request_body(
535
+ request, False, False, "json", models.ChatCompletionRequest
536
+ ),
434
537
  timeout_ms=timeout_ms,
435
538
  )
436
-
539
+
437
540
  if retries == UNSET:
438
541
  if self.sdk_configuration.retry_config is not UNSET:
439
542
  retries = self.sdk_configuration.retry_config
440
543
 
441
544
  retry_config = None
442
545
  if isinstance(retries, utils.RetryConfig):
443
- retry_config = (retries, [
444
- "429",
445
- "500",
446
- "502",
447
- "503",
448
- "504"
449
- ])
450
-
546
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
547
+
451
548
  http_res = await self.do_request_async(
452
- hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
549
+ hook_ctx=HookContext(
550
+ operation_id="chat_completion_v1_chat_completions_post",
551
+ oauth2_scopes=[],
552
+ security_source=self.sdk_configuration.security,
553
+ ),
453
554
  request=req,
454
- error_status_codes=["422","4XX","5XX"],
455
- retry_config=retry_config
555
+ error_status_codes=["422", "4XX", "5XX"],
556
+ retry_config=retry_config,
456
557
  )
457
-
558
+
458
559
  data: Any = None
459
560
  if utils.match_response(http_res, "200", "application/json"):
460
- return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
561
+ return utils.unmarshal_json(
562
+ http_res.text, Optional[models.ChatCompletionResponse]
563
+ )
461
564
  if utils.match_response(http_res, "422", "application/json"):
462
565
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
463
566
  raise models.HTTPValidationError(data=data)
464
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
465
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
466
-
467
- content_type = http_res.headers.get("Content-Type")
468
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
567
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
568
+ raise models.SDKError(
569
+ "API error occurred", http_res.status_code, http_res.text, http_res
570
+ )
469
571
 
470
-
572
+ content_type = http_res.headers.get("Content-Type")
573
+ raise models.SDKError(
574
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
575
+ http_res.status_code,
576
+ http_res.text,
577
+ http_res,
578
+ )