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_gcp/chat.py CHANGED
@@ -7,12 +7,13 @@ from mistralai_gcp.types import Nullable, OptionalNullable, UNSET
7
7
  from mistralai_gcp.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
  model: Nullable[str],
17
18
  messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
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
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
29
39
  server_url: Optional[str] = None,
30
40
  timeout_ms: Optional[int] = None,
@@ -39,12 +49,12 @@ class Chat(BaseSDK):
39
49
  :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.
40
50
  :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.
41
51
  :param min_tokens: The minimum number of tokens to generate in the completion.
42
- :param stream:
52
+ :param stream:
43
53
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
44
54
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
45
- :param response_format:
46
- :param tools:
47
- :param tool_choice:
55
+ :param response_format:
56
+ :param tools:
57
+ :param tool_choice:
48
58
  :param retries: Override the default retry configuration for this method
49
59
  :param server_url: Override the default server URL for this method
50
60
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -53,10 +63,10 @@ class Chat(BaseSDK):
53
63
  url_variables = None
54
64
  if timeout_ms is None:
55
65
  timeout_ms = self.sdk_configuration.timeout_ms
56
-
66
+
57
67
  if server_url is not None:
58
68
  base_url = server_url
59
-
69
+
60
70
  request = models.ChatCompletionStreamRequest(
61
71
  model=model,
62
72
  temperature=temperature,
@@ -67,11 +77,15 @@ class Chat(BaseSDK):
67
77
  stop=stop,
68
78
  random_seed=random_seed,
69
79
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
70
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
80
+ response_format=utils.get_pydantic_model(
81
+ response_format, Optional[models.ResponseFormat]
82
+ ),
71
83
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
72
- tool_choice=tool_choice,
84
+ tool_choice=utils.get_pydantic_model(
85
+ tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
86
+ ),
73
87
  )
74
-
88
+
75
89
  req = self.build_request(
76
90
  method="POST",
77
91
  path="/streamRawPredict",
@@ -84,48 +98,58 @@ class Chat(BaseSDK):
84
98
  user_agent_header="user-agent",
85
99
  accept_header_value="text/event-stream",
86
100
  security=self.sdk_configuration.security,
87
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
101
+ get_serialized_body=lambda: utils.serialize_request_body(
102
+ request, False, False, "json", models.ChatCompletionStreamRequest
103
+ ),
88
104
  timeout_ms=timeout_ms,
89
105
  )
90
-
106
+
91
107
  if retries == UNSET:
92
108
  if self.sdk_configuration.retry_config is not UNSET:
93
109
  retries = self.sdk_configuration.retry_config
94
110
 
95
111
  retry_config = None
96
112
  if isinstance(retries, utils.RetryConfig):
97
- retry_config = (retries, [
98
- "429",
99
- "500",
100
- "502",
101
- "503",
102
- "504"
103
- ])
104
-
113
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
114
+
105
115
  http_res = self.do_request(
106
- hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
116
+ hook_ctx=HookContext(
117
+ operation_id="stream_chat",
118
+ oauth2_scopes=[],
119
+ security_source=self.sdk_configuration.security,
120
+ ),
107
121
  request=req,
108
- error_status_codes=["422","4XX","5XX"],
122
+ error_status_codes=["422", "4XX", "5XX"],
109
123
  stream=True,
110
- retry_config=retry_config
124
+ retry_config=retry_config,
111
125
  )
112
-
126
+
113
127
  data: Any = None
114
128
  if utils.match_response(http_res, "200", "text/event-stream"):
115
- return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
129
+ return eventstreaming.stream_events(
130
+ http_res,
131
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
132
+ sentinel="[DONE]",
133
+ )
116
134
  if utils.match_response(http_res, "422", "application/json"):
117
135
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
118
136
  raise models.HTTPValidationError(data=data)
119
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
120
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
121
-
137
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
138
+ raise models.SDKError(
139
+ "API error occurred", http_res.status_code, http_res.text, http_res
140
+ )
141
+
122
142
  content_type = http_res.headers.get("Content-Type")
123
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
143
+ raise models.SDKError(
144
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
145
+ http_res.status_code,
146
+ http_res.text,
147
+ http_res,
148
+ )
124
149
 
125
-
126
-
127
150
  async def stream_async(
128
- self, *,
151
+ self,
152
+ *,
129
153
  model: Nullable[str],
130
154
  messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
131
155
  temperature: Optional[float] = 0.7,
@@ -135,9 +159,18 @@ class Chat(BaseSDK):
135
159
  stream: Optional[bool] = True,
136
160
  stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
137
161
  random_seed: OptionalNullable[int] = UNSET,
138
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
139
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
140
- tool_choice: Optional[models.ToolChoice] = "auto",
162
+ response_format: Optional[
163
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
164
+ ] = None,
165
+ tools: OptionalNullable[
166
+ Union[List[models.Tool], List[models.ToolTypedDict]]
167
+ ] = UNSET,
168
+ tool_choice: Optional[
169
+ Union[
170
+ models.ChatCompletionStreamRequestToolChoice,
171
+ models.ChatCompletionStreamRequestToolChoiceTypedDict,
172
+ ]
173
+ ] = None,
141
174
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
142
175
  server_url: Optional[str] = None,
143
176
  timeout_ms: Optional[int] = None,
@@ -152,12 +185,12 @@ class Chat(BaseSDK):
152
185
  :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.
153
186
  :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.
154
187
  :param min_tokens: The minimum number of tokens to generate in the completion.
155
- :param stream:
188
+ :param stream:
156
189
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
157
190
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
158
- :param response_format:
159
- :param tools:
160
- :param tool_choice:
191
+ :param response_format:
192
+ :param tools:
193
+ :param tool_choice:
161
194
  :param retries: Override the default retry configuration for this method
162
195
  :param server_url: Override the default server URL for this method
163
196
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -166,10 +199,10 @@ class Chat(BaseSDK):
166
199
  url_variables = None
167
200
  if timeout_ms is None:
168
201
  timeout_ms = self.sdk_configuration.timeout_ms
169
-
202
+
170
203
  if server_url is not None:
171
204
  base_url = server_url
172
-
205
+
173
206
  request = models.ChatCompletionStreamRequest(
174
207
  model=model,
175
208
  temperature=temperature,
@@ -180,12 +213,16 @@ class Chat(BaseSDK):
180
213
  stop=stop,
181
214
  random_seed=random_seed,
182
215
  messages=utils.get_pydantic_model(messages, List[models.Messages]),
183
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
216
+ response_format=utils.get_pydantic_model(
217
+ response_format, Optional[models.ResponseFormat]
218
+ ),
184
219
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
185
- tool_choice=tool_choice,
220
+ tool_choice=utils.get_pydantic_model(
221
+ tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
222
+ ),
186
223
  )
187
-
188
- req = self.build_request(
224
+
225
+ req = self.build_request_async(
189
226
  method="POST",
190
227
  path="/streamRawPredict",
191
228
  base_url=base_url,
@@ -197,60 +234,87 @@ class Chat(BaseSDK):
197
234
  user_agent_header="user-agent",
198
235
  accept_header_value="text/event-stream",
199
236
  security=self.sdk_configuration.security,
200
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
237
+ get_serialized_body=lambda: utils.serialize_request_body(
238
+ request, False, False, "json", models.ChatCompletionStreamRequest
239
+ ),
201
240
  timeout_ms=timeout_ms,
202
241
  )
203
-
242
+
204
243
  if retries == UNSET:
205
244
  if self.sdk_configuration.retry_config is not UNSET:
206
245
  retries = self.sdk_configuration.retry_config
207
246
 
208
247
  retry_config = None
209
248
  if isinstance(retries, utils.RetryConfig):
210
- retry_config = (retries, [
211
- "429",
212
- "500",
213
- "502",
214
- "503",
215
- "504"
216
- ])
217
-
249
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
250
+
218
251
  http_res = await self.do_request_async(
219
- hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
252
+ hook_ctx=HookContext(
253
+ operation_id="stream_chat",
254
+ oauth2_scopes=[],
255
+ security_source=self.sdk_configuration.security,
256
+ ),
220
257
  request=req,
221
- error_status_codes=["422","4XX","5XX"],
258
+ error_status_codes=["422", "4XX", "5XX"],
222
259
  stream=True,
223
- retry_config=retry_config
260
+ retry_config=retry_config,
224
261
  )
225
-
262
+
226
263
  data: Any = None
227
264
  if utils.match_response(http_res, "200", "text/event-stream"):
228
- return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
265
+ return eventstreaming.stream_events_async(
266
+ http_res,
267
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
268
+ sentinel="[DONE]",
269
+ )
229
270
  if utils.match_response(http_res, "422", "application/json"):
230
271
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
231
272
  raise models.HTTPValidationError(data=data)
232
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
233
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
234
-
273
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
274
+ raise models.SDKError(
275
+ "API error occurred", http_res.status_code, http_res.text, http_res
276
+ )
277
+
235
278
  content_type = http_res.headers.get("Content-Type")
236
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
279
+ raise models.SDKError(
280
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
281
+ http_res.status_code,
282
+ http_res.text,
283
+ http_res,
284
+ )
237
285
 
238
-
239
-
240
286
  def complete(
241
- self, *,
287
+ self,
288
+ *,
242
289
  model: Nullable[str],
243
- messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
290
+ messages: Union[
291
+ List[models.ChatCompletionRequestMessages],
292
+ List[models.ChatCompletionRequestMessagesTypedDict],
293
+ ],
244
294
  temperature: Optional[float] = 0.7,
245
295
  top_p: Optional[float] = 1,
246
296
  max_tokens: OptionalNullable[int] = UNSET,
247
297
  min_tokens: OptionalNullable[int] = UNSET,
248
298
  stream: Optional[bool] = False,
249
- stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
299
+ stop: Optional[
300
+ Union[
301
+ models.ChatCompletionRequestStop,
302
+ models.ChatCompletionRequestStopTypedDict,
303
+ ]
304
+ ] = None,
250
305
  random_seed: OptionalNullable[int] = UNSET,
251
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
252
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
253
- tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
306
+ response_format: Optional[
307
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
308
+ ] = None,
309
+ tools: OptionalNullable[
310
+ Union[List[models.Tool], List[models.ToolTypedDict]]
311
+ ] = UNSET,
312
+ tool_choice: Optional[
313
+ Union[
314
+ models.ChatCompletionRequestToolChoice,
315
+ models.ChatCompletionRequestToolChoiceTypedDict,
316
+ ]
317
+ ] = None,
254
318
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
255
319
  server_url: Optional[str] = None,
256
320
  timeout_ms: Optional[int] = None,
@@ -266,9 +330,9 @@ class Chat(BaseSDK):
266
330
  :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.
267
331
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
268
332
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
269
- :param response_format:
270
- :param tools:
271
- :param tool_choice:
333
+ :param response_format:
334
+ :param tools:
335
+ :param tool_choice:
272
336
  :param retries: Override the default retry configuration for this method
273
337
  :param server_url: Override the default server URL for this method
274
338
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -277,10 +341,10 @@ class Chat(BaseSDK):
277
341
  url_variables = None
278
342
  if timeout_ms is None:
279
343
  timeout_ms = self.sdk_configuration.timeout_ms
280
-
344
+
281
345
  if server_url is not None:
282
346
  base_url = server_url
283
-
347
+
284
348
  request = models.ChatCompletionRequest(
285
349
  model=model,
286
350
  temperature=temperature,
@@ -290,12 +354,18 @@ class Chat(BaseSDK):
290
354
  stream=stream,
291
355
  stop=stop,
292
356
  random_seed=random_seed,
293
- messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
294
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
357
+ messages=utils.get_pydantic_model(
358
+ messages, List[models.ChatCompletionRequestMessages]
359
+ ),
360
+ response_format=utils.get_pydantic_model(
361
+ response_format, Optional[models.ResponseFormat]
362
+ ),
295
363
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
296
- tool_choice=tool_choice,
364
+ tool_choice=utils.get_pydantic_model(
365
+ tool_choice, Optional[models.ChatCompletionRequestToolChoice]
366
+ ),
297
367
  )
298
-
368
+
299
369
  req = self.build_request(
300
370
  method="POST",
301
371
  path="/rawPredict",
@@ -308,59 +378,84 @@ class Chat(BaseSDK):
308
378
  user_agent_header="user-agent",
309
379
  accept_header_value="application/json",
310
380
  security=self.sdk_configuration.security,
311
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
381
+ get_serialized_body=lambda: utils.serialize_request_body(
382
+ request, False, False, "json", models.ChatCompletionRequest
383
+ ),
312
384
  timeout_ms=timeout_ms,
313
385
  )
314
-
386
+
315
387
  if retries == UNSET:
316
388
  if self.sdk_configuration.retry_config is not UNSET:
317
389
  retries = self.sdk_configuration.retry_config
318
390
 
319
391
  retry_config = None
320
392
  if isinstance(retries, utils.RetryConfig):
321
- retry_config = (retries, [
322
- "429",
323
- "500",
324
- "502",
325
- "503",
326
- "504"
327
- ])
328
-
393
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
394
+
329
395
  http_res = self.do_request(
330
- hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
396
+ hook_ctx=HookContext(
397
+ operation_id="chat_completion_v1_chat_completions_post",
398
+ oauth2_scopes=[],
399
+ security_source=self.sdk_configuration.security,
400
+ ),
331
401
  request=req,
332
- error_status_codes=["422","4XX","5XX"],
333
- retry_config=retry_config
402
+ error_status_codes=["422", "4XX", "5XX"],
403
+ retry_config=retry_config,
334
404
  )
335
-
405
+
336
406
  data: Any = None
337
407
  if utils.match_response(http_res, "200", "application/json"):
338
- return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
408
+ return utils.unmarshal_json(
409
+ http_res.text, Optional[models.ChatCompletionResponse]
410
+ )
339
411
  if utils.match_response(http_res, "422", "application/json"):
340
412
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
341
413
  raise models.HTTPValidationError(data=data)
342
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
343
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
344
-
414
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
415
+ raise models.SDKError(
416
+ "API error occurred", http_res.status_code, http_res.text, http_res
417
+ )
418
+
345
419
  content_type = http_res.headers.get("Content-Type")
346
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
420
+ raise models.SDKError(
421
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
422
+ http_res.status_code,
423
+ http_res.text,
424
+ http_res,
425
+ )
347
426
 
348
-
349
-
350
427
  async def complete_async(
351
- self, *,
428
+ self,
429
+ *,
352
430
  model: Nullable[str],
353
- messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
431
+ messages: Union[
432
+ List[models.ChatCompletionRequestMessages],
433
+ List[models.ChatCompletionRequestMessagesTypedDict],
434
+ ],
354
435
  temperature: Optional[float] = 0.7,
355
436
  top_p: Optional[float] = 1,
356
437
  max_tokens: OptionalNullable[int] = UNSET,
357
438
  min_tokens: OptionalNullable[int] = UNSET,
358
439
  stream: Optional[bool] = False,
359
- stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
440
+ stop: Optional[
441
+ Union[
442
+ models.ChatCompletionRequestStop,
443
+ models.ChatCompletionRequestStopTypedDict,
444
+ ]
445
+ ] = None,
360
446
  random_seed: OptionalNullable[int] = UNSET,
361
- response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
362
- tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
363
- tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
447
+ response_format: Optional[
448
+ Union[models.ResponseFormat, models.ResponseFormatTypedDict]
449
+ ] = None,
450
+ tools: OptionalNullable[
451
+ Union[List[models.Tool], List[models.ToolTypedDict]]
452
+ ] = UNSET,
453
+ tool_choice: Optional[
454
+ Union[
455
+ models.ChatCompletionRequestToolChoice,
456
+ models.ChatCompletionRequestToolChoiceTypedDict,
457
+ ]
458
+ ] = None,
364
459
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
365
460
  server_url: Optional[str] = None,
366
461
  timeout_ms: Optional[int] = None,
@@ -376,9 +471,9 @@ class Chat(BaseSDK):
376
471
  :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.
377
472
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
378
473
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
379
- :param response_format:
380
- :param tools:
381
- :param tool_choice:
474
+ :param response_format:
475
+ :param tools:
476
+ :param tool_choice:
382
477
  :param retries: Override the default retry configuration for this method
383
478
  :param server_url: Override the default server URL for this method
384
479
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -387,10 +482,10 @@ class Chat(BaseSDK):
387
482
  url_variables = None
388
483
  if timeout_ms is None:
389
484
  timeout_ms = self.sdk_configuration.timeout_ms
390
-
485
+
391
486
  if server_url is not None:
392
487
  base_url = server_url
393
-
488
+
394
489
  request = models.ChatCompletionRequest(
395
490
  model=model,
396
491
  temperature=temperature,
@@ -400,13 +495,19 @@ class Chat(BaseSDK):
400
495
  stream=stream,
401
496
  stop=stop,
402
497
  random_seed=random_seed,
403
- messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
404
- response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
498
+ messages=utils.get_pydantic_model(
499
+ messages, List[models.ChatCompletionRequestMessages]
500
+ ),
501
+ response_format=utils.get_pydantic_model(
502
+ response_format, Optional[models.ResponseFormat]
503
+ ),
405
504
  tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
406
- tool_choice=tool_choice,
505
+ tool_choice=utils.get_pydantic_model(
506
+ tool_choice, Optional[models.ChatCompletionRequestToolChoice]
507
+ ),
407
508
  )
408
-
409
- req = self.build_request(
509
+
510
+ req = self.build_request_async(
410
511
  method="POST",
411
512
  path="/rawPredict",
412
513
  base_url=base_url,
@@ -418,41 +519,48 @@ class Chat(BaseSDK):
418
519
  user_agent_header="user-agent",
419
520
  accept_header_value="application/json",
420
521
  security=self.sdk_configuration.security,
421
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
522
+ get_serialized_body=lambda: utils.serialize_request_body(
523
+ request, False, False, "json", models.ChatCompletionRequest
524
+ ),
422
525
  timeout_ms=timeout_ms,
423
526
  )
424
-
527
+
425
528
  if retries == UNSET:
426
529
  if self.sdk_configuration.retry_config is not UNSET:
427
530
  retries = self.sdk_configuration.retry_config
428
531
 
429
532
  retry_config = None
430
533
  if isinstance(retries, utils.RetryConfig):
431
- retry_config = (retries, [
432
- "429",
433
- "500",
434
- "502",
435
- "503",
436
- "504"
437
- ])
438
-
534
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
535
+
439
536
  http_res = await self.do_request_async(
440
- hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
537
+ hook_ctx=HookContext(
538
+ operation_id="chat_completion_v1_chat_completions_post",
539
+ oauth2_scopes=[],
540
+ security_source=self.sdk_configuration.security,
541
+ ),
441
542
  request=req,
442
- error_status_codes=["422","4XX","5XX"],
443
- retry_config=retry_config
543
+ error_status_codes=["422", "4XX", "5XX"],
544
+ retry_config=retry_config,
444
545
  )
445
-
546
+
446
547
  data: Any = None
447
548
  if utils.match_response(http_res, "200", "application/json"):
448
- return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
549
+ return utils.unmarshal_json(
550
+ http_res.text, Optional[models.ChatCompletionResponse]
551
+ )
449
552
  if utils.match_response(http_res, "422", "application/json"):
450
553
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
451
554
  raise models.HTTPValidationError(data=data)
452
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
453
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
454
-
455
- content_type = http_res.headers.get("Content-Type")
456
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
555
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
556
+ raise models.SDKError(
557
+ "API error occurred", http_res.status_code, http_res.text, http_res
558
+ )
457
559
 
458
-
560
+ content_type = http_res.headers.get("Content-Type")
561
+ raise models.SDKError(
562
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
563
+ http_res.status_code,
564
+ http_res.text,
565
+ http_res,
566
+ )