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