mistralai 0.4.2__py3-none-any.whl → 0.5.5a50__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-0.5.5a50.dist-info}/LICENSE +1 -1
  115. mistralai-0.5.5a50.dist-info/METADATA +626 -0
  116. mistralai-0.5.5a50.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-0.5.5a50.dist-info}/WHEEL +0 -0
mistralai_gcp/fim.py ADDED
@@ -0,0 +1,439 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from mistralai_gcp import models
5
+ from mistralai_gcp._hooks import HookContext
6
+ from mistralai_gcp.types import OptionalNullable, UNSET
7
+ import mistralai_gcp.utils as utils
8
+ from mistralai_gcp.utils import eventstreaming
9
+ from typing import Any, AsyncGenerator, Generator, Optional, Union
10
+
11
+ class Fim(BaseSDK):
12
+ r"""Fill-in-the-middle API."""
13
+
14
+
15
+ def stream(
16
+ self, *,
17
+ prompt: str,
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] = True,
24
+ stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
25
+ random_seed: OptionalNullable[int] = UNSET,
26
+ suffix: OptionalNullable[str] = UNSET,
27
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
28
+ server_url: Optional[str] = None,
29
+ timeout_ms: Optional[int] = None,
30
+ ) -> Optional[Generator[models.CompletionEvent, None, None]]:
31
+ r"""Stream fim completion
32
+
33
+ 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.
34
+
35
+ :param prompt: The text/code to complete.
36
+ :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
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:
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 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`.
45
+ :param retries: Override the default retry configuration for this method
46
+ :param server_url: Override the default server URL for this method
47
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
48
+ """
49
+ base_url = None
50
+ url_variables = None
51
+ if timeout_ms is None:
52
+ timeout_ms = self.sdk_configuration.timeout_ms
53
+
54
+ if server_url is not None:
55
+ base_url = server_url
56
+
57
+ request = models.FIMCompletionStreamRequest(
58
+ model=model,
59
+ temperature=temperature,
60
+ top_p=top_p,
61
+ max_tokens=max_tokens,
62
+ min_tokens=min_tokens,
63
+ stream=stream,
64
+ stop=stop,
65
+ random_seed=random_seed,
66
+ prompt=prompt,
67
+ suffix=suffix,
68
+ )
69
+
70
+ req = self.build_request(
71
+ method="POST",
72
+ path="/streamRawPredict#fim",
73
+ base_url=base_url,
74
+ url_variables=url_variables,
75
+ request=request,
76
+ request_body_required=True,
77
+ request_has_path_params=False,
78
+ request_has_query_params=True,
79
+ user_agent_header="user-agent",
80
+ accept_header_value="text/event-stream",
81
+ security=self.sdk_configuration.security,
82
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
83
+ timeout_ms=timeout_ms,
84
+ )
85
+
86
+ if retries == UNSET:
87
+ if self.sdk_configuration.retry_config is not UNSET:
88
+ retries = self.sdk_configuration.retry_config
89
+
90
+ retry_config = None
91
+ if isinstance(retries, utils.RetryConfig):
92
+ retry_config = (retries, [
93
+ "429",
94
+ "500",
95
+ "502",
96
+ "503",
97
+ "504"
98
+ ])
99
+
100
+ http_res = self.do_request(
101
+ hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
102
+ request=req,
103
+ error_status_codes=["422","4XX","5XX"],
104
+ stream=True,
105
+ retry_config=retry_config
106
+ )
107
+
108
+ data: Any = None
109
+ if utils.match_response(http_res, "200", "text/event-stream"):
110
+ return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
111
+ if utils.match_response(http_res, "422", "application/json"):
112
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
113
+ raise models.HTTPValidationError(data=data)
114
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
115
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
116
+
117
+ content_type = http_res.headers.get("Content-Type")
118
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
119
+
120
+
121
+
122
+ async def stream_async(
123
+ self, *,
124
+ prompt: str,
125
+ model: OptionalNullable[str] = UNSET,
126
+ temperature: Optional[float] = 0.7,
127
+ top_p: Optional[float] = 1,
128
+ max_tokens: OptionalNullable[int] = UNSET,
129
+ min_tokens: OptionalNullable[int] = UNSET,
130
+ stream: Optional[bool] = True,
131
+ stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
132
+ random_seed: OptionalNullable[int] = UNSET,
133
+ suffix: OptionalNullable[str] = UNSET,
134
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
135
+ server_url: Optional[str] = None,
136
+ timeout_ms: Optional[int] = None,
137
+ ) -> Optional[AsyncGenerator[models.CompletionEvent, None]]:
138
+ r"""Stream fim completion
139
+
140
+ 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.
141
+
142
+ :param prompt: The text/code to complete.
143
+ :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
144
+ :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.
145
+ :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.
146
+ :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.
147
+ :param min_tokens: The minimum number of tokens to generate in the completion.
148
+ :param stream:
149
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
150
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
151
+ :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`.
152
+ :param retries: Override the default retry configuration for this method
153
+ :param server_url: Override the default server URL for this method
154
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
155
+ """
156
+ base_url = None
157
+ url_variables = None
158
+ if timeout_ms is None:
159
+ timeout_ms = self.sdk_configuration.timeout_ms
160
+
161
+ if server_url is not None:
162
+ base_url = server_url
163
+
164
+ request = models.FIMCompletionStreamRequest(
165
+ model=model,
166
+ temperature=temperature,
167
+ top_p=top_p,
168
+ max_tokens=max_tokens,
169
+ min_tokens=min_tokens,
170
+ stream=stream,
171
+ stop=stop,
172
+ random_seed=random_seed,
173
+ prompt=prompt,
174
+ suffix=suffix,
175
+ )
176
+
177
+ req = self.build_request(
178
+ method="POST",
179
+ path="/streamRawPredict#fim",
180
+ base_url=base_url,
181
+ url_variables=url_variables,
182
+ request=request,
183
+ request_body_required=True,
184
+ request_has_path_params=False,
185
+ request_has_query_params=True,
186
+ user_agent_header="user-agent",
187
+ accept_header_value="text/event-stream",
188
+ security=self.sdk_configuration.security,
189
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
190
+ timeout_ms=timeout_ms,
191
+ )
192
+
193
+ if retries == UNSET:
194
+ if self.sdk_configuration.retry_config is not UNSET:
195
+ retries = self.sdk_configuration.retry_config
196
+
197
+ retry_config = None
198
+ if isinstance(retries, utils.RetryConfig):
199
+ retry_config = (retries, [
200
+ "429",
201
+ "500",
202
+ "502",
203
+ "503",
204
+ "504"
205
+ ])
206
+
207
+ http_res = await self.do_request_async(
208
+ hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
209
+ request=req,
210
+ error_status_codes=["422","4XX","5XX"],
211
+ stream=True,
212
+ retry_config=retry_config
213
+ )
214
+
215
+ data: Any = None
216
+ if utils.match_response(http_res, "200", "text/event-stream"):
217
+ return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
218
+ if utils.match_response(http_res, "422", "application/json"):
219
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
220
+ raise models.HTTPValidationError(data=data)
221
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
222
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
223
+
224
+ content_type = http_res.headers.get("Content-Type")
225
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
226
+
227
+
228
+
229
+ def create(
230
+ self, *,
231
+ prompt: str,
232
+ model: OptionalNullable[str] = UNSET,
233
+ temperature: Optional[float] = 0.7,
234
+ top_p: Optional[float] = 1,
235
+ max_tokens: OptionalNullable[int] = UNSET,
236
+ min_tokens: OptionalNullable[int] = UNSET,
237
+ stream: Optional[bool] = False,
238
+ stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
239
+ random_seed: OptionalNullable[int] = UNSET,
240
+ suffix: OptionalNullable[str] = UNSET,
241
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
242
+ server_url: Optional[str] = None,
243
+ timeout_ms: Optional[int] = None,
244
+ ) -> Optional[models.FIMCompletionResponse]:
245
+ r"""Fim Completion
246
+
247
+ FIM completion.
248
+
249
+ :param prompt: The text/code to complete.
250
+ :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
251
+ :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.
252
+ :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.
253
+ :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.
254
+ :param min_tokens: The minimum number of tokens to generate in the completion.
255
+ :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.
256
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
257
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
258
+ :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`.
259
+ :param retries: Override the default retry configuration for this method
260
+ :param server_url: Override the default server URL for this method
261
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
262
+ """
263
+ base_url = None
264
+ url_variables = None
265
+ if timeout_ms is None:
266
+ timeout_ms = self.sdk_configuration.timeout_ms
267
+
268
+ if server_url is not None:
269
+ base_url = server_url
270
+
271
+ request = models.FIMCompletionRequest(
272
+ model=model,
273
+ temperature=temperature,
274
+ top_p=top_p,
275
+ max_tokens=max_tokens,
276
+ min_tokens=min_tokens,
277
+ stream=stream,
278
+ stop=stop,
279
+ random_seed=random_seed,
280
+ prompt=prompt,
281
+ suffix=suffix,
282
+ )
283
+
284
+ req = self.build_request(
285
+ method="POST",
286
+ path="/rawPredict#fim",
287
+ base_url=base_url,
288
+ url_variables=url_variables,
289
+ request=request,
290
+ request_body_required=True,
291
+ request_has_path_params=False,
292
+ request_has_query_params=True,
293
+ user_agent_header="user-agent",
294
+ accept_header_value="application/json",
295
+ security=self.sdk_configuration.security,
296
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
297
+ timeout_ms=timeout_ms,
298
+ )
299
+
300
+ if retries == UNSET:
301
+ if self.sdk_configuration.retry_config is not UNSET:
302
+ retries = self.sdk_configuration.retry_config
303
+
304
+ retry_config = None
305
+ if isinstance(retries, utils.RetryConfig):
306
+ retry_config = (retries, [
307
+ "429",
308
+ "500",
309
+ "502",
310
+ "503",
311
+ "504"
312
+ ])
313
+
314
+ http_res = self.do_request(
315
+ hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
316
+ request=req,
317
+ error_status_codes=["422","4XX","5XX"],
318
+ retry_config=retry_config
319
+ )
320
+
321
+ data: Any = None
322
+ if utils.match_response(http_res, "200", "application/json"):
323
+ return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
324
+ if utils.match_response(http_res, "422", "application/json"):
325
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
326
+ raise models.HTTPValidationError(data=data)
327
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
328
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
329
+
330
+ content_type = http_res.headers.get("Content-Type")
331
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
332
+
333
+
334
+
335
+ async def create_async(
336
+ self, *,
337
+ prompt: str,
338
+ model: OptionalNullable[str] = UNSET,
339
+ temperature: Optional[float] = 0.7,
340
+ top_p: Optional[float] = 1,
341
+ max_tokens: OptionalNullable[int] = UNSET,
342
+ min_tokens: OptionalNullable[int] = UNSET,
343
+ stream: Optional[bool] = False,
344
+ stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
345
+ random_seed: OptionalNullable[int] = UNSET,
346
+ suffix: OptionalNullable[str] = UNSET,
347
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
348
+ server_url: Optional[str] = None,
349
+ timeout_ms: Optional[int] = None,
350
+ ) -> Optional[models.FIMCompletionResponse]:
351
+ r"""Fim Completion
352
+
353
+ FIM completion.
354
+
355
+ :param prompt: The text/code to complete.
356
+ :param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
357
+ :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.
358
+ :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.
359
+ :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.
360
+ :param min_tokens: The minimum number of tokens to generate in the completion.
361
+ :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.
362
+ :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
363
+ :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
364
+ :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`.
365
+ :param retries: Override the default retry configuration for this method
366
+ :param server_url: Override the default server URL for this method
367
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
368
+ """
369
+ base_url = None
370
+ url_variables = None
371
+ if timeout_ms is None:
372
+ timeout_ms = self.sdk_configuration.timeout_ms
373
+
374
+ if server_url is not None:
375
+ base_url = server_url
376
+
377
+ request = models.FIMCompletionRequest(
378
+ model=model,
379
+ temperature=temperature,
380
+ top_p=top_p,
381
+ max_tokens=max_tokens,
382
+ min_tokens=min_tokens,
383
+ stream=stream,
384
+ stop=stop,
385
+ random_seed=random_seed,
386
+ prompt=prompt,
387
+ suffix=suffix,
388
+ )
389
+
390
+ req = self.build_request(
391
+ method="POST",
392
+ path="/rawPredict#fim",
393
+ base_url=base_url,
394
+ url_variables=url_variables,
395
+ request=request,
396
+ request_body_required=True,
397
+ request_has_path_params=False,
398
+ request_has_query_params=True,
399
+ user_agent_header="user-agent",
400
+ accept_header_value="application/json",
401
+ security=self.sdk_configuration.security,
402
+ get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
403
+ timeout_ms=timeout_ms,
404
+ )
405
+
406
+ if retries == UNSET:
407
+ if self.sdk_configuration.retry_config is not UNSET:
408
+ retries = self.sdk_configuration.retry_config
409
+
410
+ retry_config = None
411
+ if isinstance(retries, utils.RetryConfig):
412
+ retry_config = (retries, [
413
+ "429",
414
+ "500",
415
+ "502",
416
+ "503",
417
+ "504"
418
+ ])
419
+
420
+ http_res = await self.do_request_async(
421
+ hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
422
+ request=req,
423
+ error_status_codes=["422","4XX","5XX"],
424
+ retry_config=retry_config
425
+ )
426
+
427
+ data: Any = None
428
+ if utils.match_response(http_res, "200", "application/json"):
429
+ return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
430
+ if utils.match_response(http_res, "422", "application/json"):
431
+ data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
432
+ raise models.HTTPValidationError(data=data)
433
+ if utils.match_response(http_res, ["4XX","5XX"], "*"):
434
+ raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
435
+
436
+ content_type = http_res.headers.get("Content-Type")
437
+ raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
438
+
439
+
@@ -0,0 +1,78 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ # pyright: reportReturnType = false
4
+ from typing_extensions import Protocol, runtime_checkable
5
+ import httpx
6
+ from typing import Any, Optional, Union
7
+
8
+
9
+ @runtime_checkable
10
+ class HttpClient(Protocol):
11
+ def send(
12
+ self,
13
+ request: httpx.Request,
14
+ *,
15
+ stream: bool = False,
16
+ auth: Union[
17
+ httpx._types.AuthTypes, httpx._client.UseClientDefault, None
18
+ ] = httpx.USE_CLIENT_DEFAULT,
19
+ follow_redirects: Union[
20
+ bool, httpx._client.UseClientDefault
21
+ ] = httpx.USE_CLIENT_DEFAULT,
22
+ ) -> httpx.Response:
23
+ pass
24
+
25
+ def build_request(
26
+ self,
27
+ method: str,
28
+ url: httpx._types.URLTypes,
29
+ *,
30
+ content: Optional[httpx._types.RequestContent] = None,
31
+ data: Optional[httpx._types.RequestData] = None,
32
+ files: Optional[httpx._types.RequestFiles] = None,
33
+ json: Optional[Any] = None,
34
+ params: Optional[httpx._types.QueryParamTypes] = None,
35
+ headers: Optional[httpx._types.HeaderTypes] = None,
36
+ cookies: Optional[httpx._types.CookieTypes] = None,
37
+ timeout: Union[
38
+ httpx._types.TimeoutTypes, httpx._client.UseClientDefault
39
+ ] = httpx.USE_CLIENT_DEFAULT,
40
+ extensions: Optional[httpx._types.RequestExtensions] = None,
41
+ ) -> httpx.Request:
42
+ pass
43
+
44
+
45
+ @runtime_checkable
46
+ class AsyncHttpClient(Protocol):
47
+ async def send(
48
+ self,
49
+ request: httpx.Request,
50
+ *,
51
+ stream: bool = False,
52
+ auth: Union[
53
+ httpx._types.AuthTypes, httpx._client.UseClientDefault, None
54
+ ] = httpx.USE_CLIENT_DEFAULT,
55
+ follow_redirects: Union[
56
+ bool, httpx._client.UseClientDefault
57
+ ] = httpx.USE_CLIENT_DEFAULT,
58
+ ) -> httpx.Response:
59
+ pass
60
+
61
+ def build_request(
62
+ self,
63
+ method: str,
64
+ url: httpx._types.URLTypes,
65
+ *,
66
+ content: Optional[httpx._types.RequestContent] = None,
67
+ data: Optional[httpx._types.RequestData] = None,
68
+ files: Optional[httpx._types.RequestFiles] = None,
69
+ json: Optional[Any] = None,
70
+ params: Optional[httpx._types.QueryParamTypes] = None,
71
+ headers: Optional[httpx._types.HeaderTypes] = None,
72
+ cookies: Optional[httpx._types.CookieTypes] = None,
73
+ timeout: Union[
74
+ httpx._types.TimeoutTypes, httpx._client.UseClientDefault
75
+ ] = httpx.USE_CLIENT_DEFAULT,
76
+ extensions: Optional[httpx._types.RequestExtensions] = None,
77
+ ) -> httpx.Request:
78
+ pass
@@ -0,0 +1,31 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .assistantmessage import AssistantMessage, AssistantMessageRole, AssistantMessageTypedDict
4
+ from .chatcompletionchoice import ChatCompletionChoice, ChatCompletionChoiceFinishReason, ChatCompletionChoiceTypedDict, Message, MessageTypedDict
5
+ from .chatcompletionrequest import ChatCompletionRequest, ChatCompletionRequestMessages, ChatCompletionRequestMessagesTypedDict, ChatCompletionRequestStop, ChatCompletionRequestStopTypedDict, ChatCompletionRequestToolChoice, ChatCompletionRequestTypedDict
6
+ from .chatcompletionresponse import ChatCompletionResponse, ChatCompletionResponseTypedDict
7
+ from .chatcompletionstreamrequest import ChatCompletionStreamRequest, ChatCompletionStreamRequestTypedDict, Messages, MessagesTypedDict, Stop, StopTypedDict, ToolChoice
8
+ from .completionchunk import CompletionChunk, CompletionChunkTypedDict
9
+ from .completionevent import CompletionEvent, CompletionEventTypedDict
10
+ from .completionresponsestreamchoice import CompletionResponseStreamChoice, CompletionResponseStreamChoiceTypedDict, FinishReason
11
+ from .contentchunk import ContentChunk, ContentChunkTypedDict
12
+ from .deltamessage import DeltaMessage, DeltaMessageTypedDict
13
+ from .fimcompletionrequest import FIMCompletionRequest, FIMCompletionRequestStop, FIMCompletionRequestStopTypedDict, FIMCompletionRequestTypedDict
14
+ from .fimcompletionresponse import FIMCompletionResponse, FIMCompletionResponseTypedDict
15
+ from .fimcompletionstreamrequest import FIMCompletionStreamRequest, FIMCompletionStreamRequestStop, FIMCompletionStreamRequestStopTypedDict, FIMCompletionStreamRequestTypedDict
16
+ from .function import Function, FunctionTypedDict
17
+ from .functioncall import FunctionCall, FunctionCallTypedDict
18
+ from .httpvalidationerror import HTTPValidationError, HTTPValidationErrorData
19
+ from .responseformat import ResponseFormat, ResponseFormatTypedDict, ResponseFormats
20
+ from .sdkerror import SDKError
21
+ from .security import Security, SecurityTypedDict
22
+ from .systemmessage import Content, ContentTypedDict, Role, SystemMessage, SystemMessageTypedDict
23
+ from .textchunk import TextChunk, TextChunkTypedDict
24
+ from .tool import Tool, ToolTypedDict
25
+ from .toolcall import ToolCall, ToolCallTypedDict
26
+ from .toolmessage import ToolMessage, ToolMessageRole, ToolMessageTypedDict
27
+ from .usageinfo import UsageInfo, UsageInfoTypedDict
28
+ from .usermessage import UserMessage, UserMessageContent, UserMessageContentTypedDict, UserMessageRole, UserMessageTypedDict
29
+ from .validationerror import Loc, LocTypedDict, ValidationError, ValidationErrorTypedDict
30
+
31
+ __all__ = ["AssistantMessage", "AssistantMessageRole", "AssistantMessageTypedDict", "ChatCompletionChoice", "ChatCompletionChoiceFinishReason", "ChatCompletionChoiceTypedDict", "ChatCompletionRequest", "ChatCompletionRequestMessages", "ChatCompletionRequestMessagesTypedDict", "ChatCompletionRequestStop", "ChatCompletionRequestStopTypedDict", "ChatCompletionRequestToolChoice", "ChatCompletionRequestTypedDict", "ChatCompletionResponse", "ChatCompletionResponseTypedDict", "ChatCompletionStreamRequest", "ChatCompletionStreamRequestTypedDict", "CompletionChunk", "CompletionChunkTypedDict", "CompletionEvent", "CompletionEventTypedDict", "CompletionResponseStreamChoice", "CompletionResponseStreamChoiceTypedDict", "Content", "ContentChunk", "ContentChunkTypedDict", "ContentTypedDict", "DeltaMessage", "DeltaMessageTypedDict", "FIMCompletionRequest", "FIMCompletionRequestStop", "FIMCompletionRequestStopTypedDict", "FIMCompletionRequestTypedDict", "FIMCompletionResponse", "FIMCompletionResponseTypedDict", "FIMCompletionStreamRequest", "FIMCompletionStreamRequestStop", "FIMCompletionStreamRequestStopTypedDict", "FIMCompletionStreamRequestTypedDict", "FinishReason", "Function", "FunctionCall", "FunctionCallTypedDict", "FunctionTypedDict", "HTTPValidationError", "HTTPValidationErrorData", "Loc", "LocTypedDict", "Message", "MessageTypedDict", "Messages", "MessagesTypedDict", "ResponseFormat", "ResponseFormatTypedDict", "ResponseFormats", "Role", "SDKError", "Security", "SecurityTypedDict", "Stop", "StopTypedDict", "SystemMessage", "SystemMessageTypedDict", "TextChunk", "TextChunkTypedDict", "Tool", "ToolCall", "ToolCallTypedDict", "ToolChoice", "ToolMessage", "ToolMessageRole", "ToolMessageTypedDict", "ToolTypedDict", "UsageInfo", "UsageInfoTypedDict", "UserMessage", "UserMessageContent", "UserMessageContentTypedDict", "UserMessageRole", "UserMessageTypedDict", "ValidationError", "ValidationErrorTypedDict"]
@@ -0,0 +1,58 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .toolcall import ToolCall, ToolCallTypedDict
5
+ from mistralai_gcp.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
6
+ from pydantic import model_serializer
7
+ from typing import List, Literal, Optional, TypedDict
8
+ from typing_extensions import NotRequired
9
+
10
+
11
+ AssistantMessageRole = Literal["assistant"]
12
+
13
+ class AssistantMessageTypedDict(TypedDict):
14
+ content: NotRequired[Nullable[str]]
15
+ tool_calls: NotRequired[Nullable[List[ToolCallTypedDict]]]
16
+ prefix: NotRequired[bool]
17
+ r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
18
+ role: NotRequired[AssistantMessageRole]
19
+
20
+
21
+ class AssistantMessage(BaseModel):
22
+ content: OptionalNullable[str] = UNSET
23
+ tool_calls: OptionalNullable[List[ToolCall]] = UNSET
24
+ prefix: Optional[bool] = False
25
+ r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
26
+ role: Optional[AssistantMessageRole] = "assistant"
27
+
28
+ @model_serializer(mode="wrap")
29
+ def serialize_model(self, handler):
30
+ optional_fields = ["content", "tool_calls", "prefix", "role"]
31
+ nullable_fields = ["content", "tool_calls"]
32
+ null_default_fields = []
33
+
34
+ serialized = handler(self)
35
+
36
+ m = {}
37
+
38
+ for n, f in self.model_fields.items():
39
+ k = f.alias or n
40
+ val = serialized.get(k)
41
+
42
+ if val is not None and val != UNSET_SENTINEL:
43
+ m[k] = val
44
+ elif val != UNSET_SENTINEL and (
45
+ not k in optional_fields
46
+ or (
47
+ k in optional_fields
48
+ and k in nullable_fields
49
+ and (
50
+ self.__pydantic_fields_set__.intersection({n})
51
+ or k in null_default_fields
52
+ ) # pylint: disable=no-member
53
+ )
54
+ ):
55
+ m[k] = val
56
+
57
+ return m
58
+
@@ -0,0 +1,33 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
5
+ from .systemmessage import SystemMessage, SystemMessageTypedDict
6
+ from .toolmessage import ToolMessage, ToolMessageTypedDict
7
+ from .usermessage import UserMessage, UserMessageTypedDict
8
+ from mistralai_gcp.types import BaseModel
9
+ from mistralai_gcp.utils import get_discriminator
10
+ from pydantic import Discriminator, Tag
11
+ from typing import Literal, Optional, TypedDict, Union
12
+ from typing_extensions import Annotated, NotRequired
13
+
14
+
15
+ ChatCompletionChoiceFinishReason = Literal["stop", "length", "model_length", "error", "tool_calls"]
16
+
17
+ class ChatCompletionChoiceTypedDict(TypedDict):
18
+ index: int
19
+ finish_reason: ChatCompletionChoiceFinishReason
20
+ message: NotRequired[MessageTypedDict]
21
+
22
+
23
+ class ChatCompletionChoice(BaseModel):
24
+ index: int
25
+ finish_reason: ChatCompletionChoiceFinishReason
26
+ message: Optional[Message] = None
27
+
28
+
29
+ MessageTypedDict = Union[SystemMessageTypedDict, UserMessageTypedDict, AssistantMessageTypedDict, ToolMessageTypedDict]
30
+
31
+
32
+ Message = Annotated[Union[Annotated[AssistantMessage, Tag("assistant")], Annotated[SystemMessage, Tag("system")], Annotated[ToolMessage, Tag("tool")], Annotated[UserMessage, Tag("user")]], Discriminator(lambda m: get_discriminator(m, "role", "role"))]
33
+