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_gcp/fim.py CHANGED
@@ -7,22 +7,28 @@ from mistralai_gcp.types import Nullable, OptionalNullable, UNSET
7
7
  from mistralai_gcp.utils import eventstreaming
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 stream(
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] = True,
23
- stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
23
+ stop: Optional[
24
+ Union[
25
+ models.FIMCompletionStreamRequestStop,
26
+ models.FIMCompletionStreamRequestStopTypedDict,
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
- :param stream:
45
+ :param stream:
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.FIMCompletionStreamRequest(
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="/streamRawPredict#fim",
@@ -78,58 +84,76 @@ class Fim(BaseSDK):
78
84
  user_agent_header="user-agent",
79
85
  accept_header_value="text/event-stream",
80
86
  security=self.sdk_configuration.security,
81
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
87
+ get_serialized_body=lambda: utils.serialize_request_body(
88
+ request, False, False, "json", models.FIMCompletionStreamRequest
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="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
102
+ hook_ctx=HookContext(
103
+ operation_id="stream_fim",
104
+ oauth2_scopes=[],
105
+ security_source=self.sdk_configuration.security,
106
+ ),
101
107
  request=req,
102
- error_status_codes=["422","4XX","5XX"],
108
+ error_status_codes=["422", "4XX", "5XX"],
103
109
  stream=True,
104
- retry_config=retry_config
110
+ retry_config=retry_config,
105
111
  )
106
-
112
+
107
113
  data: Any = None
108
114
  if utils.match_response(http_res, "200", "text/event-stream"):
109
- return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
115
+ return eventstreaming.stream_events(
116
+ http_res,
117
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
118
+ sentinel="[DONE]",
119
+ )
110
120
  if utils.match_response(http_res, "422", "application/json"):
111
- data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
121
+ http_res_text = utils.stream_to_text(http_res)
122
+ data = utils.unmarshal_json(http_res_text, models.HTTPValidationErrorData)
112
123
  raise models.HTTPValidationError(data=data)
113
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
114
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
115
-
124
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
125
+ http_res_text = utils.stream_to_text(http_res)
126
+ raise models.SDKError(
127
+ "API error occurred", http_res.status_code, http_res_text, http_res
128
+ )
129
+
116
130
  content_type = http_res.headers.get("Content-Type")
117
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
131
+ http_res_text = utils.stream_to_text(http_res)
132
+ raise models.SDKError(
133
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
134
+ http_res.status_code,
135
+ http_res_text,
136
+ http_res,
137
+ )
118
138
 
119
-
120
-
121
139
  async def stream_async(
122
- self, *,
140
+ self,
141
+ *,
123
142
  model: Nullable[str],
124
143
  prompt: str,
125
- temperature: Optional[float] = 0.7,
144
+ temperature: OptionalNullable[float] = UNSET,
126
145
  top_p: Optional[float] = 1,
127
146
  max_tokens: OptionalNullable[int] = UNSET,
128
- min_tokens: OptionalNullable[int] = UNSET,
129
147
  stream: Optional[bool] = True,
130
- stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
148
+ stop: Optional[
149
+ Union[
150
+ models.FIMCompletionStreamRequestStop,
151
+ models.FIMCompletionStreamRequestStopTypedDict,
152
+ ]
153
+ ] = None,
131
154
  random_seed: OptionalNullable[int] = UNSET,
132
155
  suffix: OptionalNullable[str] = UNSET,
156
+ min_tokens: OptionalNullable[int] = UNSET,
133
157
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
134
158
  server_url: Optional[str] = None,
135
159
  timeout_ms: Optional[int] = None,
@@ -140,14 +164,14 @@ class Fim(BaseSDK):
140
164
 
141
165
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
142
166
  :param prompt: The text/code to complete.
143
- :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.
167
+ :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.
144
168
  :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.
145
169
  :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.
146
- :param min_tokens: The minimum number of tokens to generate in the completion.
147
- :param stream:
170
+ :param stream:
148
171
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
149
172
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
150
173
  :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`.
174
+ :param min_tokens: The minimum number of tokens to generate in the completion.
151
175
  :param retries: Override the default retry configuration for this method
152
176
  :param server_url: Override the default server URL for this method
153
177
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -156,24 +180,24 @@ class Fim(BaseSDK):
156
180
  url_variables = None
157
181
  if timeout_ms is None:
158
182
  timeout_ms = self.sdk_configuration.timeout_ms
159
-
183
+
160
184
  if server_url is not None:
161
185
  base_url = server_url
162
-
186
+
163
187
  request = models.FIMCompletionStreamRequest(
164
188
  model=model,
165
189
  temperature=temperature,
166
190
  top_p=top_p,
167
191
  max_tokens=max_tokens,
168
- min_tokens=min_tokens,
169
192
  stream=stream,
170
193
  stop=stop,
171
194
  random_seed=random_seed,
172
195
  prompt=prompt,
173
196
  suffix=suffix,
197
+ min_tokens=min_tokens,
174
198
  )
175
-
176
- req = self.build_request(
199
+
200
+ req = self.build_request_async(
177
201
  method="POST",
178
202
  path="/streamRawPredict#fim",
179
203
  base_url=base_url,
@@ -185,58 +209,76 @@ class Fim(BaseSDK):
185
209
  user_agent_header="user-agent",
186
210
  accept_header_value="text/event-stream",
187
211
  security=self.sdk_configuration.security,
188
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
212
+ get_serialized_body=lambda: utils.serialize_request_body(
213
+ request, False, False, "json", models.FIMCompletionStreamRequest
214
+ ),
189
215
  timeout_ms=timeout_ms,
190
216
  )
191
-
217
+
192
218
  if retries == UNSET:
193
219
  if self.sdk_configuration.retry_config is not UNSET:
194
220
  retries = self.sdk_configuration.retry_config
195
221
 
196
222
  retry_config = None
197
223
  if isinstance(retries, utils.RetryConfig):
198
- retry_config = (retries, [
199
- "429",
200
- "500",
201
- "502",
202
- "503",
203
- "504"
204
- ])
205
-
224
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
225
+
206
226
  http_res = await self.do_request_async(
207
- hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
227
+ hook_ctx=HookContext(
228
+ operation_id="stream_fim",
229
+ oauth2_scopes=[],
230
+ security_source=self.sdk_configuration.security,
231
+ ),
208
232
  request=req,
209
- error_status_codes=["422","4XX","5XX"],
233
+ error_status_codes=["422", "4XX", "5XX"],
210
234
  stream=True,
211
- retry_config=retry_config
235
+ retry_config=retry_config,
212
236
  )
213
-
237
+
214
238
  data: Any = None
215
239
  if utils.match_response(http_res, "200", "text/event-stream"):
216
- return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
240
+ return eventstreaming.stream_events_async(
241
+ http_res,
242
+ lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
243
+ sentinel="[DONE]",
244
+ )
217
245
  if utils.match_response(http_res, "422", "application/json"):
218
- data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
246
+ http_res_text = await utils.stream_to_text_async(http_res)
247
+ data = utils.unmarshal_json(http_res_text, models.HTTPValidationErrorData)
219
248
  raise models.HTTPValidationError(data=data)
220
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
221
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
222
-
249
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
250
+ http_res_text = await utils.stream_to_text_async(http_res)
251
+ raise models.SDKError(
252
+ "API error occurred", http_res.status_code, http_res_text, http_res
253
+ )
254
+
223
255
  content_type = http_res.headers.get("Content-Type")
224
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
256
+ http_res_text = await utils.stream_to_text_async(http_res)
257
+ raise models.SDKError(
258
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
259
+ http_res.status_code,
260
+ http_res_text,
261
+ http_res,
262
+ )
225
263
 
226
-
227
-
228
264
  def complete(
229
- self, *,
265
+ self,
266
+ *,
230
267
  model: Nullable[str],
231
268
  prompt: str,
232
- temperature: Optional[float] = 0.7,
269
+ temperature: OptionalNullable[float] = UNSET,
233
270
  top_p: Optional[float] = 1,
234
271
  max_tokens: OptionalNullable[int] = UNSET,
235
- min_tokens: OptionalNullable[int] = UNSET,
236
272
  stream: Optional[bool] = False,
237
- stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
273
+ stop: Optional[
274
+ Union[
275
+ models.FIMCompletionRequestStop,
276
+ models.FIMCompletionRequestStopTypedDict,
277
+ ]
278
+ ] = None,
238
279
  random_seed: OptionalNullable[int] = UNSET,
239
280
  suffix: OptionalNullable[str] = UNSET,
281
+ min_tokens: OptionalNullable[int] = UNSET,
240
282
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
241
283
  server_url: Optional[str] = None,
242
284
  timeout_ms: Optional[int] = None,
@@ -247,14 +289,14 @@ class Fim(BaseSDK):
247
289
 
248
290
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
249
291
  :param prompt: The text/code to complete.
250
- :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.
292
+ :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.
251
293
  :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.
252
294
  :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.
253
- :param min_tokens: The minimum number of tokens to generate in the completion.
254
295
  :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.
255
296
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
256
297
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
257
298
  :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`.
299
+ :param min_tokens: The minimum number of tokens to generate in the completion.
258
300
  :param retries: Override the default retry configuration for this method
259
301
  :param server_url: Override the default server URL for this method
260
302
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -263,23 +305,23 @@ class Fim(BaseSDK):
263
305
  url_variables = None
264
306
  if timeout_ms is None:
265
307
  timeout_ms = self.sdk_configuration.timeout_ms
266
-
308
+
267
309
  if server_url is not None:
268
310
  base_url = server_url
269
-
311
+
270
312
  request = models.FIMCompletionRequest(
271
313
  model=model,
272
314
  temperature=temperature,
273
315
  top_p=top_p,
274
316
  max_tokens=max_tokens,
275
- min_tokens=min_tokens,
276
317
  stream=stream,
277
318
  stop=stop,
278
319
  random_seed=random_seed,
279
320
  prompt=prompt,
280
321
  suffix=suffix,
322
+ min_tokens=min_tokens,
281
323
  )
282
-
324
+
283
325
  req = self.build_request(
284
326
  method="POST",
285
327
  path="/rawPredict#fim",
@@ -292,57 +334,72 @@ class Fim(BaseSDK):
292
334
  user_agent_header="user-agent",
293
335
  accept_header_value="application/json",
294
336
  security=self.sdk_configuration.security,
295
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
337
+ get_serialized_body=lambda: utils.serialize_request_body(
338
+ request, False, False, "json", models.FIMCompletionRequest
339
+ ),
296
340
  timeout_ms=timeout_ms,
297
341
  )
298
-
342
+
299
343
  if retries == UNSET:
300
344
  if self.sdk_configuration.retry_config is not UNSET:
301
345
  retries = self.sdk_configuration.retry_config
302
346
 
303
347
  retry_config = None
304
348
  if isinstance(retries, utils.RetryConfig):
305
- retry_config = (retries, [
306
- "429",
307
- "500",
308
- "502",
309
- "503",
310
- "504"
311
- ])
312
-
349
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
350
+
313
351
  http_res = self.do_request(
314
- hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
352
+ hook_ctx=HookContext(
353
+ operation_id="fim_completion_v1_fim_completions_post",
354
+ oauth2_scopes=[],
355
+ security_source=self.sdk_configuration.security,
356
+ ),
315
357
  request=req,
316
- error_status_codes=["422","4XX","5XX"],
317
- retry_config=retry_config
358
+ error_status_codes=["422", "4XX", "5XX"],
359
+ retry_config=retry_config,
318
360
  )
319
-
361
+
320
362
  data: Any = None
321
363
  if utils.match_response(http_res, "200", "application/json"):
322
- return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
364
+ return utils.unmarshal_json(
365
+ http_res.text, Optional[models.FIMCompletionResponse]
366
+ )
323
367
  if utils.match_response(http_res, "422", "application/json"):
324
368
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
325
369
  raise models.HTTPValidationError(data=data)
326
- if utils.match_response(http_res, ["4XX","5XX"], "*"):
327
- raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
328
-
370
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
371
+ http_res_text = utils.stream_to_text(http_res)
372
+ raise models.SDKError(
373
+ "API error occurred", http_res.status_code, http_res_text, http_res
374
+ )
375
+
329
376
  content_type = http_res.headers.get("Content-Type")
330
- raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
377
+ http_res_text = utils.stream_to_text(http_res)
378
+ raise models.SDKError(
379
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
380
+ http_res.status_code,
381
+ http_res_text,
382
+ http_res,
383
+ )
331
384
 
332
-
333
-
334
385
  async def complete_async(
335
- self, *,
386
+ self,
387
+ *,
336
388
  model: Nullable[str],
337
389
  prompt: str,
338
- temperature: Optional[float] = 0.7,
390
+ temperature: OptionalNullable[float] = UNSET,
339
391
  top_p: Optional[float] = 1,
340
392
  max_tokens: OptionalNullable[int] = UNSET,
341
- min_tokens: OptionalNullable[int] = UNSET,
342
393
  stream: Optional[bool] = False,
343
- stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
394
+ stop: Optional[
395
+ Union[
396
+ models.FIMCompletionRequestStop,
397
+ models.FIMCompletionRequestStopTypedDict,
398
+ ]
399
+ ] = None,
344
400
  random_seed: OptionalNullable[int] = UNSET,
345
401
  suffix: OptionalNullable[str] = UNSET,
402
+ min_tokens: OptionalNullable[int] = UNSET,
346
403
  retries: OptionalNullable[utils.RetryConfig] = UNSET,
347
404
  server_url: Optional[str] = None,
348
405
  timeout_ms: Optional[int] = None,
@@ -353,14 +410,14 @@ class Fim(BaseSDK):
353
410
 
354
411
  :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
355
412
  :param prompt: The text/code to complete.
356
- :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.
413
+ :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.
357
414
  :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.
358
415
  :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.
359
- :param min_tokens: The minimum number of tokens to generate in the completion.
360
416
  :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.
361
417
  :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
362
418
  :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
363
419
  :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`.
420
+ :param min_tokens: The minimum number of tokens to generate in the completion.
364
421
  :param retries: Override the default retry configuration for this method
365
422
  :param server_url: Override the default server URL for this method
366
423
  :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
@@ -369,24 +426,24 @@ class Fim(BaseSDK):
369
426
  url_variables = None
370
427
  if timeout_ms is None:
371
428
  timeout_ms = self.sdk_configuration.timeout_ms
372
-
429
+
373
430
  if server_url is not None:
374
431
  base_url = server_url
375
-
432
+
376
433
  request = models.FIMCompletionRequest(
377
434
  model=model,
378
435
  temperature=temperature,
379
436
  top_p=top_p,
380
437
  max_tokens=max_tokens,
381
- min_tokens=min_tokens,
382
438
  stream=stream,
383
439
  stop=stop,
384
440
  random_seed=random_seed,
385
441
  prompt=prompt,
386
442
  suffix=suffix,
443
+ min_tokens=min_tokens,
387
444
  )
388
-
389
- req = self.build_request(
445
+
446
+ req = self.build_request_async(
390
447
  method="POST",
391
448
  path="/rawPredict#fim",
392
449
  base_url=base_url,
@@ -398,41 +455,50 @@ class Fim(BaseSDK):
398
455
  user_agent_header="user-agent",
399
456
  accept_header_value="application/json",
400
457
  security=self.sdk_configuration.security,
401
- get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
458
+ get_serialized_body=lambda: utils.serialize_request_body(
459
+ request, False, False, "json", models.FIMCompletionRequest
460
+ ),
402
461
  timeout_ms=timeout_ms,
403
462
  )
404
-
463
+
405
464
  if retries == UNSET:
406
465
  if self.sdk_configuration.retry_config is not UNSET:
407
466
  retries = self.sdk_configuration.retry_config
408
467
 
409
468
  retry_config = None
410
469
  if isinstance(retries, utils.RetryConfig):
411
- retry_config = (retries, [
412
- "429",
413
- "500",
414
- "502",
415
- "503",
416
- "504"
417
- ])
418
-
470
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
471
+
419
472
  http_res = await self.do_request_async(
420
- hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
473
+ hook_ctx=HookContext(
474
+ operation_id="fim_completion_v1_fim_completions_post",
475
+ oauth2_scopes=[],
476
+ security_source=self.sdk_configuration.security,
477
+ ),
421
478
  request=req,
422
- error_status_codes=["422","4XX","5XX"],
423
- retry_config=retry_config
479
+ error_status_codes=["422", "4XX", "5XX"],
480
+ retry_config=retry_config,
424
481
  )
425
-
482
+
426
483
  data: Any = None
427
484
  if utils.match_response(http_res, "200", "application/json"):
428
- return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
485
+ return utils.unmarshal_json(
486
+ http_res.text, Optional[models.FIMCompletionResponse]
487
+ )
429
488
  if utils.match_response(http_res, "422", "application/json"):
430
489
  data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
431
490
  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)
491
+ if utils.match_response(http_res, ["4XX", "5XX"], "*"):
492
+ http_res_text = await utils.stream_to_text_async(http_res)
493
+ raise models.SDKError(
494
+ "API error occurred", http_res.status_code, http_res_text, http_res
495
+ )
437
496
 
438
-
497
+ content_type = http_res.headers.get("Content-Type")
498
+ http_res_text = await utils.stream_to_text_async(http_res)
499
+ raise models.SDKError(
500
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
501
+ http_res.status_code,
502
+ http_res_text,
503
+ http_res,
504
+ )