mistralai 1.0.3__py3-none-any.whl → 1.2.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 (230) hide show
  1. mistralai/__init__.py +4 -0
  2. mistralai/_hooks/sdkhooks.py +23 -4
  3. mistralai/_hooks/types.py +27 -9
  4. mistralai/_version.py +12 -0
  5. mistralai/agents.py +334 -164
  6. mistralai/basesdk.py +90 -5
  7. mistralai/batch.py +17 -0
  8. mistralai/chat.py +316 -166
  9. mistralai/classifiers.py +396 -0
  10. mistralai/embeddings.py +79 -55
  11. mistralai/files.py +487 -194
  12. mistralai/fim.py +206 -132
  13. mistralai/fine_tuning.py +3 -2
  14. mistralai/jobs.py +392 -263
  15. mistralai/mistral_jobs.py +733 -0
  16. mistralai/models/__init__.py +593 -50
  17. mistralai/models/agentscompletionrequest.py +70 -17
  18. mistralai/models/agentscompletionstreamrequest.py +72 -17
  19. mistralai/models/apiendpoint.py +9 -0
  20. mistralai/models/archiveftmodelout.py +15 -5
  21. mistralai/models/assistantmessage.py +22 -10
  22. mistralai/models/{modelcard.py → basemodelcard.py} +53 -14
  23. mistralai/models/batcherror.py +17 -0
  24. mistralai/models/batchjobin.py +58 -0
  25. mistralai/models/batchjobout.py +117 -0
  26. mistralai/models/batchjobsout.py +30 -0
  27. mistralai/models/batchjobstatus.py +15 -0
  28. mistralai/models/chatclassificationrequest.py +104 -0
  29. mistralai/models/chatcompletionchoice.py +13 -6
  30. mistralai/models/chatcompletionrequest.py +86 -21
  31. mistralai/models/chatcompletionresponse.py +8 -4
  32. mistralai/models/chatcompletionstreamrequest.py +88 -21
  33. mistralai/models/checkpointout.py +4 -3
  34. mistralai/models/classificationobject.py +21 -0
  35. mistralai/models/classificationrequest.py +59 -0
  36. mistralai/models/classificationresponse.py +21 -0
  37. mistralai/models/completionchunk.py +12 -5
  38. mistralai/models/completionevent.py +2 -3
  39. mistralai/models/completionresponsestreamchoice.py +22 -8
  40. mistralai/models/contentchunk.py +13 -10
  41. mistralai/models/delete_model_v1_models_model_id_deleteop.py +5 -5
  42. mistralai/models/deletefileout.py +4 -3
  43. mistralai/models/deletemodelout.py +5 -4
  44. mistralai/models/deltamessage.py +23 -11
  45. mistralai/models/detailedjobout.py +70 -12
  46. mistralai/models/embeddingrequest.py +14 -9
  47. mistralai/models/embeddingresponse.py +7 -3
  48. mistralai/models/embeddingresponsedata.py +5 -4
  49. mistralai/models/eventout.py +11 -6
  50. mistralai/models/filepurpose.py +8 -0
  51. mistralai/models/files_api_routes_delete_fileop.py +5 -5
  52. mistralai/models/files_api_routes_download_fileop.py +16 -0
  53. mistralai/models/files_api_routes_list_filesop.py +96 -0
  54. mistralai/models/files_api_routes_retrieve_fileop.py +5 -5
  55. mistralai/models/files_api_routes_upload_fileop.py +33 -14
  56. mistralai/models/fileschema.py +22 -15
  57. mistralai/models/fimcompletionrequest.py +44 -16
  58. mistralai/models/fimcompletionresponse.py +8 -4
  59. mistralai/models/fimcompletionstreamrequest.py +44 -16
  60. mistralai/models/finetuneablemodel.py +7 -1
  61. mistralai/models/ftmodelcapabilitiesout.py +6 -4
  62. mistralai/models/ftmodelcard.py +121 -0
  63. mistralai/models/ftmodelout.py +39 -9
  64. mistralai/models/function.py +5 -4
  65. mistralai/models/functioncall.py +4 -3
  66. mistralai/models/functionname.py +17 -0
  67. mistralai/models/githubrepositoryin.py +24 -7
  68. mistralai/models/githubrepositoryout.py +24 -7
  69. mistralai/models/httpvalidationerror.py +1 -3
  70. mistralai/models/imageurl.py +47 -0
  71. mistralai/models/imageurlchunk.py +38 -0
  72. mistralai/models/jobin.py +24 -7
  73. mistralai/models/jobmetadataout.py +32 -8
  74. mistralai/models/jobout.py +65 -12
  75. mistralai/models/jobs_api_routes_batch_cancel_batch_jobop.py +16 -0
  76. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +16 -0
  77. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +95 -0
  78. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +5 -5
  79. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +5 -5
  80. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
  81. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +5 -5
  82. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +85 -18
  83. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +5 -5
  84. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +5 -5
  85. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +10 -6
  86. mistralai/models/jobsout.py +13 -5
  87. mistralai/models/legacyjobmetadataout.py +55 -9
  88. mistralai/models/listfilesout.py +7 -3
  89. mistralai/models/metricout.py +12 -8
  90. mistralai/models/modelcapabilities.py +9 -4
  91. mistralai/models/modellist.py +21 -7
  92. mistralai/models/responseformat.py +7 -8
  93. mistralai/models/responseformats.py +8 -0
  94. mistralai/models/retrieve_model_v1_models_model_id_getop.py +25 -6
  95. mistralai/models/retrievefileout.py +25 -15
  96. mistralai/models/sampletype.py +6 -2
  97. mistralai/models/security.py +14 -5
  98. mistralai/models/source.py +3 -2
  99. mistralai/models/systemmessage.py +10 -9
  100. mistralai/models/textchunk.py +14 -5
  101. mistralai/models/tool.py +10 -9
  102. mistralai/models/toolcall.py +10 -8
  103. mistralai/models/toolchoice.py +29 -0
  104. mistralai/models/toolchoiceenum.py +7 -0
  105. mistralai/models/toolmessage.py +13 -6
  106. mistralai/models/tooltypes.py +8 -0
  107. mistralai/models/trainingfile.py +4 -4
  108. mistralai/models/trainingparameters.py +34 -8
  109. mistralai/models/trainingparametersin.py +36 -10
  110. mistralai/models/unarchiveftmodelout.py +15 -5
  111. mistralai/models/updateftmodelin.py +9 -6
  112. mistralai/models/uploadfileout.py +22 -15
  113. mistralai/models/usageinfo.py +4 -3
  114. mistralai/models/usermessage.py +42 -10
  115. mistralai/models/validationerror.py +5 -3
  116. mistralai/models/wandbintegration.py +23 -7
  117. mistralai/models/wandbintegrationout.py +23 -8
  118. mistralai/models_.py +416 -294
  119. mistralai/sdk.py +31 -19
  120. mistralai/sdkconfiguration.py +9 -11
  121. mistralai/utils/__init__.py +14 -1
  122. mistralai/utils/annotations.py +13 -2
  123. mistralai/utils/logger.py +4 -1
  124. mistralai/utils/retries.py +2 -1
  125. mistralai/utils/security.py +13 -6
  126. mistralai/utils/serializers.py +25 -0
  127. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/METADATA +171 -66
  128. mistralai-1.2.0.dist-info/RECORD +276 -0
  129. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/WHEEL +1 -1
  130. mistralai_azure/__init__.py +4 -0
  131. mistralai_azure/_hooks/sdkhooks.py +23 -4
  132. mistralai_azure/_hooks/types.py +27 -9
  133. mistralai_azure/_version.py +12 -0
  134. mistralai_azure/basesdk.py +91 -6
  135. mistralai_azure/chat.py +308 -166
  136. mistralai_azure/models/__init__.py +164 -16
  137. mistralai_azure/models/assistantmessage.py +29 -11
  138. mistralai_azure/models/chatcompletionchoice.py +15 -6
  139. mistralai_azure/models/chatcompletionrequest.py +94 -22
  140. mistralai_azure/models/chatcompletionresponse.py +8 -4
  141. mistralai_azure/models/chatcompletionstreamrequest.py +96 -22
  142. mistralai_azure/models/completionchunk.py +12 -5
  143. mistralai_azure/models/completionevent.py +2 -3
  144. mistralai_azure/models/completionresponsestreamchoice.py +19 -8
  145. mistralai_azure/models/contentchunk.py +4 -11
  146. mistralai_azure/models/deltamessage.py +30 -12
  147. mistralai_azure/models/function.py +5 -4
  148. mistralai_azure/models/functioncall.py +4 -3
  149. mistralai_azure/models/functionname.py +17 -0
  150. mistralai_azure/models/httpvalidationerror.py +1 -3
  151. mistralai_azure/models/responseformat.py +7 -8
  152. mistralai_azure/models/responseformats.py +8 -0
  153. mistralai_azure/models/security.py +13 -5
  154. mistralai_azure/models/systemmessage.py +10 -9
  155. mistralai_azure/models/textchunk.py +14 -5
  156. mistralai_azure/models/tool.py +10 -9
  157. mistralai_azure/models/toolcall.py +10 -8
  158. mistralai_azure/models/toolchoice.py +29 -0
  159. mistralai_azure/models/toolchoiceenum.py +7 -0
  160. mistralai_azure/models/toolmessage.py +20 -7
  161. mistralai_azure/models/tooltypes.py +8 -0
  162. mistralai_azure/models/usageinfo.py +4 -3
  163. mistralai_azure/models/usermessage.py +42 -10
  164. mistralai_azure/models/validationerror.py +5 -3
  165. mistralai_azure/sdkconfiguration.py +9 -11
  166. mistralai_azure/utils/__init__.py +16 -3
  167. mistralai_azure/utils/annotations.py +13 -2
  168. mistralai_azure/utils/forms.py +10 -9
  169. mistralai_azure/utils/headers.py +8 -8
  170. mistralai_azure/utils/logger.py +6 -0
  171. mistralai_azure/utils/queryparams.py +16 -14
  172. mistralai_azure/utils/retries.py +2 -1
  173. mistralai_azure/utils/security.py +12 -6
  174. mistralai_azure/utils/serializers.py +42 -8
  175. mistralai_azure/utils/url.py +13 -8
  176. mistralai_azure/utils/values.py +6 -0
  177. mistralai_gcp/__init__.py +4 -0
  178. mistralai_gcp/_hooks/sdkhooks.py +23 -4
  179. mistralai_gcp/_hooks/types.py +27 -9
  180. mistralai_gcp/_version.py +12 -0
  181. mistralai_gcp/basesdk.py +91 -6
  182. mistralai_gcp/chat.py +308 -166
  183. mistralai_gcp/fim.py +198 -132
  184. mistralai_gcp/models/__init__.py +186 -18
  185. mistralai_gcp/models/assistantmessage.py +29 -11
  186. mistralai_gcp/models/chatcompletionchoice.py +15 -6
  187. mistralai_gcp/models/chatcompletionrequest.py +91 -22
  188. mistralai_gcp/models/chatcompletionresponse.py +8 -4
  189. mistralai_gcp/models/chatcompletionstreamrequest.py +93 -22
  190. mistralai_gcp/models/completionchunk.py +12 -5
  191. mistralai_gcp/models/completionevent.py +2 -3
  192. mistralai_gcp/models/completionresponsestreamchoice.py +19 -8
  193. mistralai_gcp/models/contentchunk.py +4 -11
  194. mistralai_gcp/models/deltamessage.py +30 -12
  195. mistralai_gcp/models/fimcompletionrequest.py +51 -17
  196. mistralai_gcp/models/fimcompletionresponse.py +8 -4
  197. mistralai_gcp/models/fimcompletionstreamrequest.py +51 -17
  198. mistralai_gcp/models/function.py +5 -4
  199. mistralai_gcp/models/functioncall.py +4 -3
  200. mistralai_gcp/models/functionname.py +17 -0
  201. mistralai_gcp/models/httpvalidationerror.py +1 -3
  202. mistralai_gcp/models/responseformat.py +7 -8
  203. mistralai_gcp/models/responseformats.py +8 -0
  204. mistralai_gcp/models/security.py +13 -5
  205. mistralai_gcp/models/systemmessage.py +10 -9
  206. mistralai_gcp/models/textchunk.py +14 -5
  207. mistralai_gcp/models/tool.py +10 -9
  208. mistralai_gcp/models/toolcall.py +10 -8
  209. mistralai_gcp/models/toolchoice.py +29 -0
  210. mistralai_gcp/models/toolchoiceenum.py +7 -0
  211. mistralai_gcp/models/toolmessage.py +20 -7
  212. mistralai_gcp/models/tooltypes.py +8 -0
  213. mistralai_gcp/models/usageinfo.py +4 -3
  214. mistralai_gcp/models/usermessage.py +42 -10
  215. mistralai_gcp/models/validationerror.py +5 -3
  216. mistralai_gcp/sdk.py +6 -7
  217. mistralai_gcp/sdkconfiguration.py +9 -11
  218. mistralai_gcp/utils/__init__.py +16 -3
  219. mistralai_gcp/utils/annotations.py +13 -2
  220. mistralai_gcp/utils/forms.py +10 -9
  221. mistralai_gcp/utils/headers.py +8 -8
  222. mistralai_gcp/utils/logger.py +6 -0
  223. mistralai_gcp/utils/queryparams.py +16 -14
  224. mistralai_gcp/utils/retries.py +2 -1
  225. mistralai_gcp/utils/security.py +12 -6
  226. mistralai_gcp/utils/serializers.py +42 -8
  227. mistralai_gcp/utils/url.py +13 -8
  228. mistralai_gcp/utils/values.py +6 -0
  229. mistralai-1.0.3.dist-info/RECORD +0 -236
  230. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/LICENSE +0 -0
mistralai/fim.py CHANGED
@@ -7,22 +7,28 @@ from mistralai.types import Nullable, OptionalNullable, UNSET
7
7
  from mistralai.utils import eventstreaming, get_security_from_env
8
8
  from typing import Any, AsyncGenerator, Generator, Optional, Union
9
9
 
10
+
10
11
  class Fim(BaseSDK):
11
12
  r"""Fill-in-the-middle API."""
12
-
13
-
13
+
14
14
  def complete(
15
- self, *,
15
+ self,
16
+ *,
16
17
  model: Nullable[str],
17
18
  prompt: str,
18
- temperature: Optional[float] = 0.7,
19
+ temperature: OptionalNullable[float] = UNSET,
19
20
  top_p: Optional[float] = 1,
20
21
  max_tokens: OptionalNullable[int] = UNSET,
21
- min_tokens: OptionalNullable[int] = UNSET,
22
22
  stream: Optional[bool] = False,
23
- stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
23
+ stop: Optional[
24
+ Union[
25
+ models.FIMCompletionRequestStop,
26
+ models.FIMCompletionRequestStopTypedDict,
27
+ ]
28
+ ] = None,
24
29
  random_seed: OptionalNullable[int] = UNSET,
25
30
  suffix: OptionalNullable[str] = UNSET,
31
+ min_tokens: OptionalNullable[int] = UNSET,
26
32
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
27
33
  server_url: Optional[str] = None,
28
34
  timeout_ms: Optional[int] = None,
@@ -33,14 +39,14 @@ class Fim(BaseSDK):
33
39
 
34
40
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
35
41
  :param prompt: The text/code to complete.
36
- :param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
42
+ :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
37
43
  :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.
38
44
  :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.
39
- :param min_tokens: The minimum number of tokens to generate in the completion.
40
45
  :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.
41
46
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
42
47
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
43
48
  :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
49
+ :param min_tokens: The minimum number of tokens to generate in the completion.
44
50
  :param retries: Override the default retry configuration for this method
45
51
  :param server_url: Override the default server URL for this method
46
52
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -49,23 +55,23 @@ class Fim(BaseSDK):
49
55
  url_variables = None
50
56
  if timeout_ms is None:
51
57
  timeout_ms = self.sdk_configuration.timeout_ms
52
-
58
+
53
59
  if server_url is not None:
54
60
  base_url = server_url
55
-
61
+
56
62
  request = models.FIMCompletionRequest(
57
63
  model=model,
58
64
  temperature=temperature,
59
65
  top_p=top_p,
60
66
  max_tokens=max_tokens,
61
- min_tokens=min_tokens,
62
67
  stream=stream,
63
68
  stop=stop,
64
69
  random_seed=random_seed,
65
70
  prompt=prompt,
66
71
  suffix=suffix,
72
+ min_tokens=min_tokens,
67
73
  )
68
-
74
+
69
75
  req = self.build_request(
70
76
  method="POST",
71
77
  path="/v1/fim/completions",
@@ -78,57 +84,74 @@ class Fim(BaseSDK):
78
84
  user_agent_header="user-agent",
79
85
  accept_header_value="application/json",
80
86
  security=self.sdk_configuration.security,
81
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
87
+ get_serialized_body=lambda: utils.serialize_request_body(
88
+ request, False, False, "json", models.FIMCompletionRequest
89
+ ),
82
90
  timeout_ms=timeout_ms,
83
91
  )
84
-
92
+
85
93
  if retries == UNSET:
86
94
  if self.sdk_configuration.retry_config is not UNSET:
87
95
  retries = self.sdk_configuration.retry_config
88
96
 
89
97
  retry_config = None
90
98
  if isinstance(retries, utils.RetryConfig):
91
- retry_config = (retries, [
92
- "429",
93
- "500",
94
- "502",
95
- "503",
96
- "504"
97
- ])
98
-
99
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
100
+
99
101
  http_res = self.do_request(
100
- hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
102
+ hook_ctx=HookContext(
103
+ operation_id="fim_completion_v1_fim_completions_post",
104
+ oauth2_scopes=[],
105
+ security_source=get_security_from_env(
106
+ self.sdk_configuration.security, models.Security
107
+ ),
108
+ ),
101
109
  request=req,
102
- error_status_codes=["422","4XX","5XX"],
103
- retry_config=retry_config
110
+ error_status_codes=["422", "4XX", "5XX"],
111
+ retry_config=retry_config,
104
112
  )
105
-
113
+
106
114
  data: Any = None
107
115
  if utils.match_response(http_res, "200", "application/json"):
108
- return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
116
+ return utils.unmarshal_json(
117
+ http_res.text, Optional[models.FIMCompletionResponse]
118
+ )
109
119
  if utils.match_response(http_res, "422", "application/json"):
110
120
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
111
121
  raise models.HTTPValidationError(data=data)
112
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
113
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
114
-
122
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
123
+ http_res_text = utils.stream_to_text(http_res)
124
+ raise models.SDKError(
125
+ "API error occurred", http_res.status_code, http_res_text, http_res
126
+ )
127
+
115
128
  content_type = http_res.headers.get("Content-Type")
116
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
129
+ http_res_text = utils.stream_to_text(http_res)
130
+ raise models.SDKError(
131
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
132
+ http_res.status_code,
133
+ http_res_text,
134
+ http_res,
135
+ )
117
136
 
118
-
119
-
120
137
  async def complete_async(
121
- self, *,
138
+ self,
139
+ *,
122
140
  model: Nullable[str],
123
141
  prompt: str,
124
- temperature: Optional[float] = 0.7,
142
+ temperature: OptionalNullable[float] = UNSET,
125
143
  top_p: Optional[float] = 1,
126
144
  max_tokens: OptionalNullable[int] = UNSET,
127
- min_tokens: OptionalNullable[int] = UNSET,
128
145
  stream: Optional[bool] = False,
129
- stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
146
+ stop: Optional[
147
+ Union[
148
+ models.FIMCompletionRequestStop,
149
+ models.FIMCompletionRequestStopTypedDict,
150
+ ]
151
+ ] = None,
130
152
  random_seed: OptionalNullable[int] = UNSET,
131
153
  suffix: OptionalNullable[str] = UNSET,
154
+ min_tokens: OptionalNullable[int] = UNSET,
132
155
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
133
156
  server_url: Optional[str] = None,
134
157
  timeout_ms: Optional[int] = None,
@@ -139,14 +162,14 @@ class Fim(BaseSDK):
139
162
 
140
163
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
141
164
  :param prompt: The text/code to complete.
142
- :param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
165
+ :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
143
166
  :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.
144
167
  :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.
145
- :param min_tokens: The minimum number of tokens to generate in the completion.
146
168
  :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.
147
169
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
148
170
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
149
171
  :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
172
+ :param min_tokens: The minimum number of tokens to generate in the completion.
150
173
  :param retries: Override the default retry configuration for this method
151
174
  :param server_url: Override the default server URL for this method
152
175
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -155,24 +178,24 @@ class Fim(BaseSDK):
155
178
  url_variables = None
156
179
  if timeout_ms is None:
157
180
  timeout_ms = self.sdk_configuration.timeout_ms
158
-
181
+
159
182
  if server_url is not None:
160
183
  base_url = server_url
161
-
184
+
162
185
  request = models.FIMCompletionRequest(
163
186
  model=model,
164
187
  temperature=temperature,
165
188
  top_p=top_p,
166
189
  max_tokens=max_tokens,
167
- min_tokens=min_tokens,
168
190
  stream=stream,
169
191
  stop=stop,
170
192
  random_seed=random_seed,
171
193
  prompt=prompt,
172
194
  suffix=suffix,
195
+ min_tokens=min_tokens,
173
196
  )
174
-
175
- req = self.build_request(
197
+
198
+ req = self.build_request_async(
176
199
  method="POST",
177
200
  path="/v1/fim/completions",
178
201
  base_url=base_url,
@@ -184,57 +207,74 @@ class Fim(BaseSDK):
184
207
  user_agent_header="user-agent",
185
208
  accept_header_value="application/json",
186
209
  security=self.sdk_configuration.security,
187
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
210
+ get_serialized_body=lambda: utils.serialize_request_body(
211
+ request, False, False, "json", models.FIMCompletionRequest
212
+ ),
188
213
  timeout_ms=timeout_ms,
189
214
  )
190
-
215
+
191
216
  if retries == UNSET:
192
217
  if self.sdk_configuration.retry_config is not UNSET:
193
218
  retries = self.sdk_configuration.retry_config
194
219
 
195
220
  retry_config = None
196
221
  if isinstance(retries, utils.RetryConfig):
197
- retry_config = (retries, [
198
- "429",
199
- "500",
200
- "502",
201
- "503",
202
- "504"
203
- ])
204
-
222
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
223
+
205
224
  http_res = await self.do_request_async(
206
- hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
225
+ hook_ctx=HookContext(
226
+ operation_id="fim_completion_v1_fim_completions_post",
227
+ oauth2_scopes=[],
228
+ security_source=get_security_from_env(
229
+ self.sdk_configuration.security, models.Security
230
+ ),
231
+ ),
207
232
  request=req,
208
- error_status_codes=["422","4XX","5XX"],
209
- retry_config=retry_config
233
+ error_status_codes=["422", "4XX", "5XX"],
234
+ retry_config=retry_config,
210
235
  )
211
-
236
+
212
237
  data: Any = None
213
238
  if utils.match_response(http_res, "200", "application/json"):
214
- return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
239
+ return utils.unmarshal_json(
240
+ http_res.text, Optional[models.FIMCompletionResponse]
241
+ )
215
242
  if utils.match_response(http_res, "422", "application/json"):
216
243
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
217
244
  raise models.HTTPValidationError(data=data)
218
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
219
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
220
-
245
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
246
+ http_res_text = await utils.stream_to_text_async(http_res)
247
+ raise models.SDKError(
248
+ "API error occurred", http_res.status_code, http_res_text, http_res
249
+ )
250
+
221
251
  content_type = http_res.headers.get("Content-Type")
222
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
252
+ http_res_text = await utils.stream_to_text_async(http_res)
253
+ raise models.SDKError(
254
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
255
+ http_res.status_code,
256
+ http_res_text,
257
+ http_res,
258
+ )
223
259
 
224
-
225
-
226
260
  def stream(
227
- self, *,
261
+ self,
262
+ *,
228
263
  model: Nullable[str],
229
264
  prompt: str,
230
- temperature: Optional[float] = 0.7,
265
+ temperature: OptionalNullable[float] = UNSET,
231
266
  top_p: Optional[float] = 1,
232
267
  max_tokens: OptionalNullable[int] = UNSET,
233
- min_tokens: OptionalNullable[int] = UNSET,
234
268
  stream: Optional[bool] = True,
235
- stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
269
+ stop: Optional[
270
+ Union[
271
+ models.FIMCompletionStreamRequestStop,
272
+ models.FIMCompletionStreamRequestStopTypedDict,
273
+ ]
274
+ ] = None,
236
275
  random_seed: OptionalNullable[int] = UNSET,
237
276
  suffix: OptionalNullable[str] = UNSET,
277
+ min_tokens: OptionalNullable[int] = UNSET,
238
278
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
239
279
  server_url: Optional[str] = None,
240
280
  timeout_ms: Optional[int] = None,
@@ -245,14 +285,14 @@ class Fim(BaseSDK):
245
285
 
246
286
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
247
287
  :param prompt: The text/code to complete.
248
- :param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
288
+ :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
249
289
  :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.
250
290
  :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.
251
- :param min_tokens: The minimum number of tokens to generate in the completion.
252
- :param stream:
291
+ :param stream:
253
292
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
254
293
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
255
294
  :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
295
+ :param min_tokens: The minimum number of tokens to generate in the completion.
256
296
  :param retries: Override the default retry configuration for this method
257
297
  :param server_url: Override the default server URL for this method
258
298
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -261,23 +301,23 @@ class Fim(BaseSDK):
261
301
  url_variables = None
262
302
  if timeout_ms is None:
263
303
  timeout_ms = self.sdk_configuration.timeout_ms
264
-
304
+
265
305
  if server_url is not None:
266
306
  base_url = server_url
267
-
307
+
268
308
  request = models.FIMCompletionStreamRequest(
269
309
  model=model,
270
310
  temperature=temperature,
271
311
  top_p=top_p,
272
312
  max_tokens=max_tokens,
273
- min_tokens=min_tokens,
274
313
  stream=stream,
275
314
  stop=stop,
276
315
  random_seed=random_seed,
277
316
  prompt=prompt,
278
317
  suffix=suffix,
318
+ min_tokens=min_tokens,
279
319
  )
280
-
320
+
281
321
  req = self.build_request(
282
322
  method="POST",
283
323
  path="/v1/fim/completions#stream",
@@ -290,58 +330,78 @@ class Fim(BaseSDK):
290
330
  user_agent_header="user-agent",
291
331
  accept_header_value="text/event-stream",
292
332
  security=self.sdk_configuration.security,
293
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
333
+ get_serialized_body=lambda: utils.serialize_request_body(
334
+ request, False, False, "json", models.FIMCompletionStreamRequest
335
+ ),
294
336
  timeout_ms=timeout_ms,
295
337
  )
296
-
338
+
297
339
  if retries == UNSET:
298
340
  if self.sdk_configuration.retry_config is not UNSET:
299
341
  retries = self.sdk_configuration.retry_config
300
342
 
301
343
  retry_config = None
302
344
  if isinstance(retries, utils.RetryConfig):
303
- retry_config = (retries, [
304
- "429",
305
- "500",
306
- "502",
307
- "503",
308
- "504"
309
- ])
310
-
345
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
346
+
311
347
  http_res = self.do_request(
312
- hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
348
+ hook_ctx=HookContext(
349
+ operation_id="stream_fim",
350
+ oauth2_scopes=[],
351
+ security_source=get_security_from_env(
352
+ self.sdk_configuration.security, models.Security
353
+ ),
354
+ ),
313
355
  request=req,
314
- error_status_codes=["422","4XX","5XX"],
356
+ error_status_codes=["422", "4XX", "5XX"],
315
357
  stream=True,
316
- retry_config=retry_config
358
+ retry_config=retry_config,
317
359
  )
318
-
360
+
319
361
  data: Any = None
320
362
  if utils.match_response(http_res, "200", "text/event-stream"):
321
- return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
363
+ return eventstreaming.stream_events(
364
+ http_res,
365
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
366
+ sentinel="[DONE]",
367
+ )
322
368
  if utils.match_response(http_res, "422", "application/json"):
323
- data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
369
+ http_res_text = utils.stream_to_text(http_res)
370
+ data = utils.unmarshal_json(http_res_text, models.HTTPValidationErrorData)
324
371
  raise models.HTTPValidationError(data=data)
325
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
326
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
327
-
372
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
373
+ http_res_text = utils.stream_to_text(http_res)
374
+ raise models.SDKError(
375
+ "API error occurred", http_res.status_code, http_res_text, http_res
376
+ )
377
+
328
378
  content_type = http_res.headers.get("Content-Type")
329
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
379
+ http_res_text = utils.stream_to_text(http_res)
380
+ raise models.SDKError(
381
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
382
+ http_res.status_code,
383
+ http_res_text,
384
+ http_res,
385
+ )
330
386
 
331
-
332
-
333
387
  async def stream_async(
334
- self, *,
388
+ self,
389
+ *,
335
390
  model: Nullable[str],
336
391
  prompt: str,
337
- temperature: Optional[float] = 0.7,
392
+ temperature: OptionalNullable[float] = UNSET,
338
393
  top_p: Optional[float] = 1,
339
394
  max_tokens: OptionalNullable[int] = UNSET,
340
- min_tokens: OptionalNullable[int] = UNSET,
341
395
  stream: Optional[bool] = True,
342
- stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
396
+ stop: Optional[
397
+ Union[
398
+ models.FIMCompletionStreamRequestStop,
399
+ models.FIMCompletionStreamRequestStopTypedDict,
400
+ ]
401
+ ] = None,
343
402
  random_seed: OptionalNullable[int] = UNSET,
344
403
  suffix: OptionalNullable[str] = UNSET,
404
+ min_tokens: OptionalNullable[int] = UNSET,
345
405
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
346
406
  server_url: Optional[str] = None,
347
407
  timeout_ms: Optional[int] = None,
@@ -352,14 +412,14 @@ class Fim(BaseSDK):
352
412
 
353
413
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
354
414
  :param prompt: The text/code to complete.
355
- :param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
415
+ :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
356
416
  :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.
357
417
  :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.
358
- :param min_tokens: The minimum number of tokens to generate in the completion.
359
- :param stream:
418
+ :param stream:
360
419
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
361
420
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
362
421
  :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
422
+ :param min_tokens: The minimum number of tokens to generate in the completion.
363
423
  :param retries: Override the default retry configuration for this method
364
424
  :param server_url: Override the default server URL for this method
365
425
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -368,24 +428,24 @@ class Fim(BaseSDK):
368
428
  url_variables = None
369
429
  if timeout_ms is None:
370
430
  timeout_ms = self.sdk_configuration.timeout_ms
371
-
431
+
372
432
  if server_url is not None:
373
433
  base_url = server_url
374
-
434
+
375
435
  request = models.FIMCompletionStreamRequest(
376
436
  model=model,
377
437
  temperature=temperature,
378
438
  top_p=top_p,
379
439
  max_tokens=max_tokens,
380
- min_tokens=min_tokens,
381
440
  stream=stream,
382
441
  stop=stop,
383
442
  random_seed=random_seed,
384
443
  prompt=prompt,
385
444
  suffix=suffix,
445
+ min_tokens=min_tokens,
386
446
  )
387
-
388
- req = self.build_request(
447
+
448
+ req = self.build_request_async(
389
449
  method="POST",
390
450
  path="/v1/fim/completions#stream",
391
451
  base_url=base_url,
@@ -397,42 +457,56 @@ class Fim(BaseSDK):
397
457
  user_agent_header="user-agent",
398
458
  accept_header_value="text/event-stream",
399
459
  security=self.sdk_configuration.security,
400
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
460
+ get_serialized_body=lambda: utils.serialize_request_body(
461
+ request, False, False, "json", models.FIMCompletionStreamRequest
462
+ ),
401
463
  timeout_ms=timeout_ms,
402
464
  )
403
-
465
+
404
466
  if retries == UNSET:
405
467
  if self.sdk_configuration.retry_config is not UNSET:
406
468
  retries = self.sdk_configuration.retry_config
407
469
 
408
470
  retry_config = None
409
471
  if isinstance(retries, utils.RetryConfig):
410
- retry_config = (retries, [
411
- "429",
412
- "500",
413
- "502",
414
- "503",
415
- "504"
416
- ])
417
-
472
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
473
+
418
474
  http_res = await self.do_request_async(
419
- hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
475
+ hook_ctx=HookContext(
476
+ operation_id="stream_fim",
477
+ oauth2_scopes=[],
478
+ security_source=get_security_from_env(
479
+ self.sdk_configuration.security, models.Security
480
+ ),
481
+ ),
420
482
  request=req,
421
- error_status_codes=["422","4XX","5XX"],
483
+ error_status_codes=["422", "4XX", "5XX"],
422
484
  stream=True,
423
- retry_config=retry_config
485
+ retry_config=retry_config,
424
486
  )
425
-
487
+
426
488
  data: Any = None
427
489
  if utils.match_response(http_res, "200", "text/event-stream"):
428
- return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
490
+ return eventstreaming.stream_events_async(
491
+ http_res,
492
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
493
+ sentinel="[DONE]",
494
+ )
429
495
  if utils.match_response(http_res, "422", "application/json"):
430
- data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
496
+ http_res_text = await utils.stream_to_text_async(http_res)
497
+ data = utils.unmarshal_json(http_res_text, models.HTTPValidationErrorData)
431
498
  raise models.HTTPValidationError(data=data)
432
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
433
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
434
-
435
- content_type = http_res.headers.get("Content-Type")
436
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
499
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
500
+ http_res_text = await utils.stream_to_text_async(http_res)
501
+ raise models.SDKError(
502
+ "API error occurred", http_res.status_code, http_res_text, http_res
503
+ )
437
504
 
438
-
505
+ content_type = http_res.headers.get("Content-Type")
506
+ http_res_text = await utils.stream_to_text_async(http_res)
507
+ raise models.SDKError(
508
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
509
+ http_res.status_code,
510
+ http_res_text,
511
+ http_res,
512
+ )
mistralai/fine_tuning.py CHANGED
@@ -4,13 +4,14 @@ from .basesdk import BaseSDK
4
4
  from .sdkconfiguration import SDKConfiguration
5
5
  from mistralai.jobs import Jobs
6
6
 
7
+
7
8
  class FineTuning(BaseSDK):
8
9
  jobs: Jobs
10
+
9
11
  def __init__(self, sdk_config: SDKConfiguration) -> None:
10
12
  BaseSDK.__init__(self, sdk_config)
11
13
  self.sdk_configuration = sdk_config
12
14
  self._init_sdks()
13
-
15
+
14
16
  def _init_sdks(self):
15
17
  self.jobs = Jobs(self.sdk_configuration)
16
-