mistralai 0.4.2__py3-none-any.whl → 1.0.0rc1__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 (240) hide show
  1. mistralai/__init__.py +5 -0
  2. mistralai/_hooks/__init__.py +5 -0
  3. mistralai/_hooks/custom_user_agent.py +16 -0
  4. mistralai/_hooks/deprecation_warning.py +26 -0
  5. mistralai/_hooks/registration.py +17 -0
  6. mistralai/_hooks/sdkhooks.py +57 -0
  7. mistralai/_hooks/types.py +76 -0
  8. mistralai/async_client.py +5 -413
  9. mistralai/basesdk.py +216 -0
  10. mistralai/chat.py +475 -0
  11. mistralai/client.py +5 -414
  12. mistralai/embeddings.py +182 -0
  13. mistralai/files.py +600 -84
  14. mistralai/fim.py +439 -0
  15. mistralai/fine_tuning.py +855 -0
  16. mistralai/httpclient.py +78 -0
  17. mistralai/models/__init__.py +80 -0
  18. mistralai/models/archiveftmodelout.py +19 -0
  19. mistralai/models/assistantmessage.py +58 -0
  20. mistralai/models/chatcompletionchoice.py +33 -0
  21. mistralai/models/chatcompletionrequest.py +114 -0
  22. mistralai/models/chatcompletionresponse.py +27 -0
  23. mistralai/models/chatcompletionstreamrequest.py +112 -0
  24. mistralai/models/checkpointout.py +25 -0
  25. mistralai/models/completionchunk.py +27 -0
  26. mistralai/models/completionevent.py +15 -0
  27. mistralai/models/completionresponsestreamchoice.py +53 -0
  28. mistralai/models/contentchunk.py +17 -0
  29. mistralai/models/delete_model_v1_models_model_id_deleteop.py +16 -0
  30. mistralai/models/deletefileout.py +24 -0
  31. mistralai/models/deletemodelout.py +25 -0
  32. mistralai/models/deltamessage.py +52 -0
  33. mistralai/models/detailedjobout.py +96 -0
  34. mistralai/models/embeddingrequest.py +66 -0
  35. mistralai/models/embeddingresponse.py +24 -0
  36. mistralai/models/embeddingresponsedata.py +19 -0
  37. mistralai/models/eventout.py +55 -0
  38. mistralai/models/files_api_routes_delete_fileop.py +16 -0
  39. mistralai/models/files_api_routes_retrieve_fileop.py +16 -0
  40. mistralai/models/files_api_routes_upload_fileop.py +51 -0
  41. mistralai/models/fileschema.py +76 -0
  42. mistralai/models/fimcompletionrequest.py +99 -0
  43. mistralai/models/fimcompletionresponse.py +27 -0
  44. mistralai/models/fimcompletionstreamrequest.py +97 -0
  45. mistralai/models/finetuneablemodel.py +8 -0
  46. mistralai/models/ftmodelcapabilitiesout.py +21 -0
  47. mistralai/models/ftmodelout.py +70 -0
  48. mistralai/models/function.py +19 -0
  49. mistralai/models/functioncall.py +16 -0
  50. mistralai/models/githubrepositoryin.py +57 -0
  51. mistralai/models/githubrepositoryout.py +57 -0
  52. mistralai/models/httpvalidationerror.py +23 -0
  53. mistralai/models/jobin.py +78 -0
  54. mistralai/models/jobmetadataout.py +59 -0
  55. mistralai/models/jobout.py +112 -0
  56. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +16 -0
  57. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +18 -0
  58. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +73 -0
  59. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +18 -0
  60. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +86 -0
  61. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +16 -0
  62. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +16 -0
  63. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +19 -0
  64. mistralai/models/jobsout.py +20 -0
  65. mistralai/models/legacyjobmetadataout.py +85 -0
  66. mistralai/models/listfilesout.py +17 -0
  67. mistralai/models/metricout.py +55 -0
  68. mistralai/models/modelcapabilities.py +21 -0
  69. mistralai/models/modelcard.py +71 -0
  70. mistralai/models/modellist.py +18 -0
  71. mistralai/models/responseformat.py +18 -0
  72. mistralai/models/retrieve_model_v1_models_model_id_getop.py +16 -0
  73. mistralai/models/retrievefileout.py +76 -0
  74. mistralai/models/sampletype.py +7 -0
  75. mistralai/models/sdkerror.py +22 -0
  76. mistralai/models/security.py +16 -0
  77. mistralai/models/source.py +7 -0
  78. mistralai/models/systemmessage.py +26 -0
  79. mistralai/models/textchunk.py +17 -0
  80. mistralai/models/tool.py +18 -0
  81. mistralai/models/toolcall.py +20 -0
  82. mistralai/models/toolmessage.py +55 -0
  83. mistralai/models/trainingfile.py +17 -0
  84. mistralai/models/trainingparameters.py +53 -0
  85. mistralai/models/trainingparametersin.py +61 -0
  86. mistralai/models/unarchiveftmodelout.py +19 -0
  87. mistralai/models/updateftmodelin.py +49 -0
  88. mistralai/models/uploadfileout.py +76 -0
  89. mistralai/models/usageinfo.py +18 -0
  90. mistralai/models/usermessage.py +26 -0
  91. mistralai/models/validationerror.py +24 -0
  92. mistralai/models/wandbintegration.py +61 -0
  93. mistralai/models/wandbintegrationout.py +57 -0
  94. mistralai/models_.py +928 -0
  95. mistralai/py.typed +1 -0
  96. mistralai/sdk.py +111 -0
  97. mistralai/sdkconfiguration.py +53 -0
  98. mistralai/types/__init__.py +21 -0
  99. mistralai/types/basemodel.py +35 -0
  100. mistralai/utils/__init__.py +82 -0
  101. mistralai/utils/annotations.py +19 -0
  102. mistralai/utils/enums.py +34 -0
  103. mistralai/utils/eventstreaming.py +179 -0
  104. mistralai/utils/forms.py +207 -0
  105. mistralai/utils/headers.py +136 -0
  106. mistralai/utils/metadata.py +118 -0
  107. mistralai/utils/queryparams.py +203 -0
  108. mistralai/utils/requestbodies.py +66 -0
  109. mistralai/utils/retries.py +216 -0
  110. mistralai/utils/security.py +182 -0
  111. mistralai/utils/serializers.py +181 -0
  112. mistralai/utils/url.py +150 -0
  113. mistralai/utils/values.py +128 -0
  114. {mistralai-0.4.2.dist-info → mistralai-1.0.0rc1.dist-info}/LICENSE +1 -1
  115. mistralai-1.0.0rc1.dist-info/METADATA +621 -0
  116. mistralai-1.0.0rc1.dist-info/RECORD +228 -0
  117. mistralai_azure/__init__.py +5 -0
  118. mistralai_azure/_hooks/__init__.py +5 -0
  119. mistralai_azure/_hooks/custom_user_agent.py +16 -0
  120. mistralai_azure/_hooks/registration.py +15 -0
  121. mistralai_azure/_hooks/sdkhooks.py +57 -0
  122. mistralai_azure/_hooks/types.py +76 -0
  123. mistralai_azure/basesdk.py +215 -0
  124. mistralai_azure/chat.py +475 -0
  125. mistralai_azure/httpclient.py +78 -0
  126. mistralai_azure/models/__init__.py +28 -0
  127. mistralai_azure/models/assistantmessage.py +58 -0
  128. mistralai_azure/models/chatcompletionchoice.py +33 -0
  129. mistralai_azure/models/chatcompletionrequest.py +114 -0
  130. mistralai_azure/models/chatcompletionresponse.py +27 -0
  131. mistralai_azure/models/chatcompletionstreamrequest.py +112 -0
  132. mistralai_azure/models/completionchunk.py +27 -0
  133. mistralai_azure/models/completionevent.py +15 -0
  134. mistralai_azure/models/completionresponsestreamchoice.py +53 -0
  135. mistralai_azure/models/contentchunk.py +17 -0
  136. mistralai_azure/models/deltamessage.py +52 -0
  137. mistralai_azure/models/function.py +19 -0
  138. mistralai_azure/models/functioncall.py +16 -0
  139. mistralai_azure/models/httpvalidationerror.py +23 -0
  140. mistralai_azure/models/responseformat.py +18 -0
  141. mistralai_azure/models/sdkerror.py +22 -0
  142. mistralai_azure/models/security.py +16 -0
  143. mistralai_azure/models/systemmessage.py +26 -0
  144. mistralai_azure/models/textchunk.py +17 -0
  145. mistralai_azure/models/tool.py +18 -0
  146. mistralai_azure/models/toolcall.py +20 -0
  147. mistralai_azure/models/toolmessage.py +55 -0
  148. mistralai_azure/models/usageinfo.py +18 -0
  149. mistralai_azure/models/usermessage.py +26 -0
  150. mistralai_azure/models/validationerror.py +24 -0
  151. mistralai_azure/py.typed +1 -0
  152. mistralai_azure/sdk.py +102 -0
  153. mistralai_azure/sdkconfiguration.py +53 -0
  154. mistralai_azure/types/__init__.py +21 -0
  155. mistralai_azure/types/basemodel.py +35 -0
  156. mistralai_azure/utils/__init__.py +80 -0
  157. mistralai_azure/utils/annotations.py +19 -0
  158. mistralai_azure/utils/enums.py +34 -0
  159. mistralai_azure/utils/eventstreaming.py +179 -0
  160. mistralai_azure/utils/forms.py +207 -0
  161. mistralai_azure/utils/headers.py +136 -0
  162. mistralai_azure/utils/metadata.py +118 -0
  163. mistralai_azure/utils/queryparams.py +203 -0
  164. mistralai_azure/utils/requestbodies.py +66 -0
  165. mistralai_azure/utils/retries.py +216 -0
  166. mistralai_azure/utils/security.py +168 -0
  167. mistralai_azure/utils/serializers.py +181 -0
  168. mistralai_azure/utils/url.py +150 -0
  169. mistralai_azure/utils/values.py +128 -0
  170. mistralai_gcp/__init__.py +5 -0
  171. mistralai_gcp/_hooks/__init__.py +5 -0
  172. mistralai_gcp/_hooks/custom_user_agent.py +16 -0
  173. mistralai_gcp/_hooks/registration.py +15 -0
  174. mistralai_gcp/_hooks/sdkhooks.py +57 -0
  175. mistralai_gcp/_hooks/types.py +76 -0
  176. mistralai_gcp/basesdk.py +215 -0
  177. mistralai_gcp/chat.py +463 -0
  178. mistralai_gcp/fim.py +439 -0
  179. mistralai_gcp/httpclient.py +78 -0
  180. mistralai_gcp/models/__init__.py +31 -0
  181. mistralai_gcp/models/assistantmessage.py +58 -0
  182. mistralai_gcp/models/chatcompletionchoice.py +33 -0
  183. mistralai_gcp/models/chatcompletionrequest.py +110 -0
  184. mistralai_gcp/models/chatcompletionresponse.py +27 -0
  185. mistralai_gcp/models/chatcompletionstreamrequest.py +108 -0
  186. mistralai_gcp/models/completionchunk.py +27 -0
  187. mistralai_gcp/models/completionevent.py +15 -0
  188. mistralai_gcp/models/completionresponsestreamchoice.py +53 -0
  189. mistralai_gcp/models/contentchunk.py +17 -0
  190. mistralai_gcp/models/deltamessage.py +52 -0
  191. mistralai_gcp/models/fimcompletionrequest.py +99 -0
  192. mistralai_gcp/models/fimcompletionresponse.py +27 -0
  193. mistralai_gcp/models/fimcompletionstreamrequest.py +97 -0
  194. mistralai_gcp/models/function.py +19 -0
  195. mistralai_gcp/models/functioncall.py +16 -0
  196. mistralai_gcp/models/httpvalidationerror.py +23 -0
  197. mistralai_gcp/models/responseformat.py +18 -0
  198. mistralai_gcp/models/sdkerror.py +22 -0
  199. mistralai_gcp/models/security.py +16 -0
  200. mistralai_gcp/models/systemmessage.py +26 -0
  201. mistralai_gcp/models/textchunk.py +17 -0
  202. mistralai_gcp/models/tool.py +18 -0
  203. mistralai_gcp/models/toolcall.py +20 -0
  204. mistralai_gcp/models/toolmessage.py +55 -0
  205. mistralai_gcp/models/usageinfo.py +18 -0
  206. mistralai_gcp/models/usermessage.py +26 -0
  207. mistralai_gcp/models/validationerror.py +24 -0
  208. mistralai_gcp/py.typed +1 -0
  209. mistralai_gcp/sdk.py +165 -0
  210. mistralai_gcp/sdkconfiguration.py +53 -0
  211. mistralai_gcp/types/__init__.py +21 -0
  212. mistralai_gcp/types/basemodel.py +35 -0
  213. mistralai_gcp/utils/__init__.py +80 -0
  214. mistralai_gcp/utils/annotations.py +19 -0
  215. mistralai_gcp/utils/enums.py +34 -0
  216. mistralai_gcp/utils/eventstreaming.py +179 -0
  217. mistralai_gcp/utils/forms.py +207 -0
  218. mistralai_gcp/utils/headers.py +136 -0
  219. mistralai_gcp/utils/metadata.py +118 -0
  220. mistralai_gcp/utils/queryparams.py +203 -0
  221. mistralai_gcp/utils/requestbodies.py +66 -0
  222. mistralai_gcp/utils/retries.py +216 -0
  223. mistralai_gcp/utils/security.py +168 -0
  224. mistralai_gcp/utils/serializers.py +181 -0
  225. mistralai_gcp/utils/url.py +150 -0
  226. mistralai_gcp/utils/values.py +128 -0
  227. py.typed +1 -0
  228. mistralai/client_base.py +0 -211
  229. mistralai/constants.py +0 -5
  230. mistralai/exceptions.py +0 -54
  231. mistralai/jobs.py +0 -172
  232. mistralai/models/chat_completion.py +0 -93
  233. mistralai/models/common.py +0 -9
  234. mistralai/models/embeddings.py +0 -19
  235. mistralai/models/files.py +0 -23
  236. mistralai/models/jobs.py +0 -100
  237. mistralai/models/models.py +0 -39
  238. mistralai-0.4.2.dist-info/METADATA +0 -82
  239. mistralai-0.4.2.dist-info/RECORD +0 -20
  240. {mistralai-0.4.2.dist-info → mistralai-1.0.0rc1.dist-info}/WHEEL +0 -0
mistralai/chat.py ADDED
@@ -0,0 +1,475 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from mistralai import models
5
+ from mistralai._hooks import HookContext
6
+ from mistralai.types import OptionalNullable, UNSET
7
+ import mistralai.utils as utils
8
+ from mistralai.utils import eventstreaming
9
+ from typing import Any, AsyncGenerator, Generator, List, Optional, Union
10
+
11
+ class Chat(BaseSDK):
12
+ r"""Chat Completion API."""
13
+
14
+
15
+ def create(
16
+ self, *,
17
+ messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
18
+ model: OptionalNullable[str] = UNSET,
19
+ temperature: Optional[float] = 0.7,
20
+ top_p: Optional[float] = 1,
21
+ max_tokens: OptionalNullable[int] = UNSET,
22
+ min_tokens: OptionalNullable[int] = UNSET,
23
+ stream: Optional[bool] = False,
24
+ stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
25
+ random_seed: OptionalNullable[int] = UNSET,
26
+ response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
27
+ tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
28
+ safe_prompt: Optional[bool] = False,
29
+ tool_choice: Optional[models.ToolChoice] = "auto",
30
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
31
+ server_url: Optional[str] = None,
32
+ timeout_ms: Optional[int] = None,
33
+ ) -> Optional[models.ChatCompletionResponse]:
34
+ r"""Chat Completion
35
+
36
+ Chat Completion
37
+
38
+ :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
39
+ :param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
40
+ :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.
41
+ :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.
42
+ :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.
43
+ :param min_tokens: The minimum number of tokens to generate in the completion.
44
+ :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.
45
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
46
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
47
+ :param response_format:
48
+ :param tools:
49
+ :param safe_prompt: Whether to inject a safety prompt before all conversations.
50
+ :param tool_choice:
51
+ :param retries: Override the default retry configuration for this method
52
+ :param server_url: Override the default server URL for this method
53
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
54
+ """
55
+ base_url = None
56
+ url_variables = None
57
+ if timeout_ms is None:
58
+ timeout_ms = self.sdk_configuration.timeout_ms
59
+
60
+ if server_url is not None:
61
+ base_url = server_url
62
+
63
+ request = models.ChatCompletionRequest(
64
+ model=model,
65
+ temperature=temperature,
66
+ top_p=top_p,
67
+ max_tokens=max_tokens,
68
+ min_tokens=min_tokens,
69
+ stream=stream,
70
+ stop=stop,
71
+ random_seed=random_seed,
72
+ messages=utils.get_pydantic_model(messages, List[models.Messages]),
73
+ response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
74
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
75
+ safe_prompt=safe_prompt,
76
+ tool_choice=tool_choice,
77
+ )
78
+
79
+ req = self.build_request(
80
+ method="POST",
81
+ path="/v1/chat/completions",
82
+ base_url=base_url,
83
+ url_variables=url_variables,
84
+ request=request,
85
+ request_body_required=True,
86
+ request_has_path_params=False,
87
+ request_has_query_params=True,
88
+ user_agent_header="user-agent",
89
+ accept_header_value="application/json",
90
+ security=self.sdk_configuration.security,
91
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
92
+ timeout_ms=timeout_ms,
93
+ )
94
+
95
+ if retries == UNSET:
96
+ if self.sdk_configuration.retry_config is not UNSET:
97
+ retries = self.sdk_configuration.retry_config
98
+
99
+ retry_config = None
100
+ if isinstance(retries, utils.RetryConfig):
101
+ retry_config = (retries, [
102
+ "429",
103
+ "500",
104
+ "502",
105
+ "503",
106
+ "504"
107
+ ])
108
+
109
+ http_res = self.do_request(
110
+ hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
111
+ request=req,
112
+ error_status_codes=["422","4XX","5XX"],
113
+ retry_config=retry_config
114
+ )
115
+
116
+ data: Any = None
117
+ if utils.match_response(http_res, "200", "application/json"):
118
+ return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
119
+ if utils.match_response(http_res, "422", "application/json"):
120
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
121
+ raise models.HTTPValidationError(data=data)
122
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
123
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
124
+
125
+ content_type = http_res.headers.get("Content-Type")
126
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
127
+
128
+
129
+
130
+ async def create_async(
131
+ self, *,
132
+ messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
133
+ model: OptionalNullable[str] = UNSET,
134
+ temperature: Optional[float] = 0.7,
135
+ top_p: Optional[float] = 1,
136
+ max_tokens: OptionalNullable[int] = UNSET,
137
+ min_tokens: OptionalNullable[int] = UNSET,
138
+ stream: Optional[bool] = False,
139
+ stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
140
+ random_seed: OptionalNullable[int] = UNSET,
141
+ response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
142
+ tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
143
+ safe_prompt: Optional[bool] = False,
144
+ tool_choice: Optional[models.ToolChoice] = "auto",
145
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
146
+ server_url: Optional[str] = None,
147
+ timeout_ms: Optional[int] = None,
148
+ ) -> Optional[models.ChatCompletionResponse]:
149
+ r"""Chat Completion
150
+
151
+ Chat Completion
152
+
153
+ :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
154
+ :param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
155
+ :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.
156
+ :param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
157
+ :param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
158
+ :param min_tokens: The minimum number of tokens to generate in the completion.
159
+ :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.
160
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
161
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
162
+ :param response_format:
163
+ :param tools:
164
+ :param safe_prompt: Whether to inject a safety prompt before all conversations.
165
+ :param tool_choice:
166
+ :param retries: Override the default retry configuration for this method
167
+ :param server_url: Override the default server URL for this method
168
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
169
+ """
170
+ base_url = None
171
+ url_variables = None
172
+ if timeout_ms is None:
173
+ timeout_ms = self.sdk_configuration.timeout_ms
174
+
175
+ if server_url is not None:
176
+ base_url = server_url
177
+
178
+ request = models.ChatCompletionRequest(
179
+ model=model,
180
+ temperature=temperature,
181
+ top_p=top_p,
182
+ max_tokens=max_tokens,
183
+ min_tokens=min_tokens,
184
+ stream=stream,
185
+ stop=stop,
186
+ random_seed=random_seed,
187
+ messages=utils.get_pydantic_model(messages, List[models.Messages]),
188
+ response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
189
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
190
+ safe_prompt=safe_prompt,
191
+ tool_choice=tool_choice,
192
+ )
193
+
194
+ req = self.build_request(
195
+ method="POST",
196
+ path="/v1/chat/completions",
197
+ base_url=base_url,
198
+ url_variables=url_variables,
199
+ request=request,
200
+ request_body_required=True,
201
+ request_has_path_params=False,
202
+ request_has_query_params=True,
203
+ user_agent_header="user-agent",
204
+ accept_header_value="application/json",
205
+ security=self.sdk_configuration.security,
206
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
207
+ timeout_ms=timeout_ms,
208
+ )
209
+
210
+ if retries == UNSET:
211
+ if self.sdk_configuration.retry_config is not UNSET:
212
+ retries = self.sdk_configuration.retry_config
213
+
214
+ retry_config = None
215
+ if isinstance(retries, utils.RetryConfig):
216
+ retry_config = (retries, [
217
+ "429",
218
+ "500",
219
+ "502",
220
+ "503",
221
+ "504"
222
+ ])
223
+
224
+ http_res = await self.do_request_async(
225
+ hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
226
+ request=req,
227
+ error_status_codes=["422","4XX","5XX"],
228
+ retry_config=retry_config
229
+ )
230
+
231
+ data: Any = None
232
+ if utils.match_response(http_res, "200", "application/json"):
233
+ return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
234
+ if utils.match_response(http_res, "422", "application/json"):
235
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
236
+ raise models.HTTPValidationError(data=data)
237
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
238
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
239
+
240
+ content_type = http_res.headers.get("Content-Type")
241
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
242
+
243
+
244
+
245
+ def stream(
246
+ self, *,
247
+ messages: Union[List[models.ChatCompletionStreamRequestMessages], List[models.ChatCompletionStreamRequestMessagesTypedDict]],
248
+ model: OptionalNullable[str] = UNSET,
249
+ temperature: Optional[float] = 0.7,
250
+ top_p: Optional[float] = 1,
251
+ max_tokens: OptionalNullable[int] = UNSET,
252
+ min_tokens: OptionalNullable[int] = UNSET,
253
+ stream: Optional[bool] = True,
254
+ stop: Optional[Union[models.ChatCompletionStreamRequestStop, models.ChatCompletionStreamRequestStopTypedDict]] = None,
255
+ random_seed: OptionalNullable[int] = UNSET,
256
+ response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
257
+ tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
258
+ safe_prompt: Optional[bool] = False,
259
+ tool_choice: Optional[models.ChatCompletionStreamRequestToolChoice] = "auto",
260
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
261
+ server_url: Optional[str] = None,
262
+ timeout_ms: Optional[int] = None,
263
+ ) -> Optional[Generator[models.CompletionEvent, None, None]]:
264
+ r"""Stream chat completion
265
+
266
+ Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent 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
+
268
+ :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
269
+ :param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
270
+ :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.
271
+ :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.
272
+ :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.
273
+ :param min_tokens: The minimum number of tokens to generate in the completion.
274
+ :param stream:
275
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
276
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
277
+ :param response_format:
278
+ :param tools:
279
+ :param safe_prompt: Whether to inject a safety prompt before all conversations.
280
+ :param tool_choice:
281
+ :param retries: Override the default retry configuration for this method
282
+ :param server_url: Override the default server URL for this method
283
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
284
+ """
285
+ base_url = None
286
+ url_variables = None
287
+ if timeout_ms is None:
288
+ timeout_ms = self.sdk_configuration.timeout_ms
289
+
290
+ if server_url is not None:
291
+ base_url = server_url
292
+
293
+ request = models.ChatCompletionStreamRequest(
294
+ model=model,
295
+ temperature=temperature,
296
+ top_p=top_p,
297
+ max_tokens=max_tokens,
298
+ min_tokens=min_tokens,
299
+ stream=stream,
300
+ stop=stop,
301
+ random_seed=random_seed,
302
+ messages=utils.get_pydantic_model(messages, List[models.ChatCompletionStreamRequestMessages]),
303
+ response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
304
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
305
+ safe_prompt=safe_prompt,
306
+ tool_choice=tool_choice,
307
+ )
308
+
309
+ req = self.build_request(
310
+ method="POST",
311
+ path="/v1/chat/completions#stream",
312
+ base_url=base_url,
313
+ url_variables=url_variables,
314
+ request=request,
315
+ request_body_required=True,
316
+ request_has_path_params=False,
317
+ request_has_query_params=True,
318
+ user_agent_header="user-agent",
319
+ accept_header_value="text/event-stream",
320
+ security=self.sdk_configuration.security,
321
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
322
+ timeout_ms=timeout_ms,
323
+ )
324
+
325
+ if retries == UNSET:
326
+ if self.sdk_configuration.retry_config is not UNSET:
327
+ retries = self.sdk_configuration.retry_config
328
+
329
+ retry_config = None
330
+ if isinstance(retries, utils.RetryConfig):
331
+ retry_config = (retries, [
332
+ "429",
333
+ "500",
334
+ "502",
335
+ "503",
336
+ "504"
337
+ ])
338
+
339
+ http_res = self.do_request(
340
+ hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
341
+ request=req,
342
+ error_status_codes=["422","4XX","5XX"],
343
+ stream=True,
344
+ retry_config=retry_config
345
+ )
346
+
347
+ data: Any = None
348
+ if utils.match_response(http_res, "200", "text/event-stream"):
349
+ return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
350
+ if utils.match_response(http_res, "422", "application/json"):
351
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
352
+ raise models.HTTPValidationError(data=data)
353
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
354
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
355
+
356
+ content_type = http_res.headers.get("Content-Type")
357
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
358
+
359
+
360
+
361
+ async def stream_async(
362
+ self, *,
363
+ messages: Union[List[models.ChatCompletionStreamRequestMessages], List[models.ChatCompletionStreamRequestMessagesTypedDict]],
364
+ model: OptionalNullable[str] = UNSET,
365
+ temperature: Optional[float] = 0.7,
366
+ top_p: Optional[float] = 1,
367
+ max_tokens: OptionalNullable[int] = UNSET,
368
+ min_tokens: OptionalNullable[int] = UNSET,
369
+ stream: Optional[bool] = True,
370
+ stop: Optional[Union[models.ChatCompletionStreamRequestStop, models.ChatCompletionStreamRequestStopTypedDict]] = None,
371
+ random_seed: OptionalNullable[int] = UNSET,
372
+ response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
373
+ tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
374
+ safe_prompt: Optional[bool] = False,
375
+ tool_choice: Optional[models.ChatCompletionStreamRequestToolChoice] = "auto",
376
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
377
+ server_url: Optional[str] = None,
378
+ timeout_ms: Optional[int] = None,
379
+ ) -> Optional[AsyncGenerator[models.CompletionEvent, None]]:
380
+ r"""Stream chat completion
381
+
382
+ Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent 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.
383
+
384
+ :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
385
+ :param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
386
+ :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.
387
+ :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.
388
+ :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.
389
+ :param min_tokens: The minimum number of tokens to generate in the completion.
390
+ :param stream:
391
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
392
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
393
+ :param response_format:
394
+ :param tools:
395
+ :param safe_prompt: Whether to inject a safety prompt before all conversations.
396
+ :param tool_choice:
397
+ :param retries: Override the default retry configuration for this method
398
+ :param server_url: Override the default server URL for this method
399
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
400
+ """
401
+ base_url = None
402
+ url_variables = None
403
+ if timeout_ms is None:
404
+ timeout_ms = self.sdk_configuration.timeout_ms
405
+
406
+ if server_url is not None:
407
+ base_url = server_url
408
+
409
+ request = models.ChatCompletionStreamRequest(
410
+ model=model,
411
+ temperature=temperature,
412
+ top_p=top_p,
413
+ max_tokens=max_tokens,
414
+ min_tokens=min_tokens,
415
+ stream=stream,
416
+ stop=stop,
417
+ random_seed=random_seed,
418
+ messages=utils.get_pydantic_model(messages, List[models.ChatCompletionStreamRequestMessages]),
419
+ response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
420
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
421
+ safe_prompt=safe_prompt,
422
+ tool_choice=tool_choice,
423
+ )
424
+
425
+ req = self.build_request(
426
+ method="POST",
427
+ path="/v1/chat/completions#stream",
428
+ base_url=base_url,
429
+ url_variables=url_variables,
430
+ request=request,
431
+ request_body_required=True,
432
+ request_has_path_params=False,
433
+ request_has_query_params=True,
434
+ user_agent_header="user-agent",
435
+ accept_header_value="text/event-stream",
436
+ security=self.sdk_configuration.security,
437
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
438
+ timeout_ms=timeout_ms,
439
+ )
440
+
441
+ if retries == UNSET:
442
+ if self.sdk_configuration.retry_config is not UNSET:
443
+ retries = self.sdk_configuration.retry_config
444
+
445
+ retry_config = None
446
+ if isinstance(retries, utils.RetryConfig):
447
+ retry_config = (retries, [
448
+ "429",
449
+ "500",
450
+ "502",
451
+ "503",
452
+ "504"
453
+ ])
454
+
455
+ http_res = await self.do_request_async(
456
+ hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
457
+ request=req,
458
+ error_status_codes=["422","4XX","5XX"],
459
+ stream=True,
460
+ retry_config=retry_config
461
+ )
462
+
463
+ data: Any = None
464
+ if utils.match_response(http_res, "200", "text/event-stream"):
465
+ return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
466
+ if utils.match_response(http_res, "422", "application/json"):
467
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
468
+ raise models.HTTPValidationError(data=data)
469
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
470
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
471
+
472
+ content_type = http_res.headers.get("Content-Type")
473
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
474
+
475
+