mistralai 1.10.0__py3-none-any.whl → 1.11.1__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 (270) hide show
  1. mistralai/_hooks/tracing.py +28 -3
  2. mistralai/_version.py +3 -3
  3. mistralai/accesses.py +22 -12
  4. mistralai/agents.py +88 -44
  5. mistralai/basesdk.py +6 -0
  6. mistralai/chat.py +96 -40
  7. mistralai/classifiers.py +48 -23
  8. mistralai/conversations.py +186 -64
  9. mistralai/documents.py +72 -26
  10. mistralai/embeddings.py +24 -9
  11. mistralai/extra/README.md +1 -1
  12. mistralai/extra/mcp/auth.py +10 -11
  13. mistralai/extra/mcp/base.py +17 -16
  14. mistralai/extra/mcp/sse.py +13 -15
  15. mistralai/extra/mcp/stdio.py +5 -6
  16. mistralai/extra/observability/otel.py +47 -68
  17. mistralai/extra/run/context.py +33 -43
  18. mistralai/extra/run/result.py +29 -30
  19. mistralai/extra/run/tools.py +8 -9
  20. mistralai/extra/struct_chat.py +15 -8
  21. mistralai/extra/utils/response_format.py +5 -3
  22. mistralai/files.py +58 -24
  23. mistralai/fim.py +20 -12
  24. mistralai/httpclient.py +0 -1
  25. mistralai/jobs.py +65 -26
  26. mistralai/libraries.py +20 -10
  27. mistralai/mistral_agents.py +438 -30
  28. mistralai/mistral_jobs.py +62 -17
  29. mistralai/models/__init__.py +46 -1
  30. mistralai/models/agent.py +1 -1
  31. mistralai/models/agentconversation.py +1 -1
  32. mistralai/models/agenthandoffdoneevent.py +1 -1
  33. mistralai/models/agenthandoffentry.py +3 -2
  34. mistralai/models/agenthandoffstartedevent.py +1 -1
  35. mistralai/models/agents_api_v1_agents_get_versionop.py +21 -0
  36. mistralai/models/agents_api_v1_agents_list_versionsop.py +33 -0
  37. mistralai/models/agents_api_v1_agents_listop.py +5 -1
  38. mistralai/models/agents_api_v1_conversations_listop.py +1 -1
  39. mistralai/models/agentscompletionrequest.py +2 -5
  40. mistralai/models/agentscompletionstreamrequest.py +2 -5
  41. mistralai/models/archiveftmodelout.py +1 -1
  42. mistralai/models/assistantmessage.py +1 -1
  43. mistralai/models/audiochunk.py +1 -1
  44. mistralai/models/audioencoding.py +18 -0
  45. mistralai/models/audioformat.py +17 -0
  46. mistralai/models/basemodelcard.py +1 -1
  47. mistralai/models/batchjobin.py +18 -9
  48. mistralai/models/batchjobout.py +6 -1
  49. mistralai/models/batchjobsout.py +1 -1
  50. mistralai/models/batchrequest.py +48 -0
  51. mistralai/models/chatcompletionchoice.py +10 -5
  52. mistralai/models/chatcompletionrequest.py +2 -5
  53. mistralai/models/chatcompletionstreamrequest.py +2 -5
  54. mistralai/models/classificationrequest.py +37 -3
  55. mistralai/models/classifierdetailedjobout.py +4 -2
  56. mistralai/models/classifierftmodelout.py +3 -2
  57. mistralai/models/classifierjobout.py +4 -2
  58. mistralai/models/codeinterpretertool.py +1 -1
  59. mistralai/models/completiondetailedjobout.py +5 -2
  60. mistralai/models/completionftmodelout.py +3 -2
  61. mistralai/models/completionjobout.py +5 -2
  62. mistralai/models/completionresponsestreamchoice.py +9 -8
  63. mistralai/models/conversationappendrequest.py +4 -1
  64. mistralai/models/conversationappendstreamrequest.py +4 -1
  65. mistralai/models/conversationhistory.py +2 -1
  66. mistralai/models/conversationmessages.py +1 -1
  67. mistralai/models/conversationrequest.py +5 -1
  68. mistralai/models/conversationresponse.py +2 -1
  69. mistralai/models/conversationrestartrequest.py +4 -1
  70. mistralai/models/conversationrestartstreamrequest.py +4 -1
  71. mistralai/models/conversationstreamrequest.py +5 -1
  72. mistralai/models/documentlibrarytool.py +1 -1
  73. mistralai/models/documenturlchunk.py +1 -1
  74. mistralai/models/embeddingdtype.py +7 -1
  75. mistralai/models/embeddingrequest.py +11 -3
  76. mistralai/models/encodingformat.py +4 -1
  77. mistralai/models/entitytype.py +8 -1
  78. mistralai/models/filepurpose.py +8 -1
  79. mistralai/models/files_api_routes_list_filesop.py +4 -11
  80. mistralai/models/files_api_routes_upload_fileop.py +2 -6
  81. mistralai/models/fileschema.py +3 -5
  82. mistralai/models/finetuneablemodeltype.py +4 -1
  83. mistralai/models/ftclassifierlossfunction.py +4 -1
  84. mistralai/models/ftmodelcard.py +1 -1
  85. mistralai/models/functioncallentry.py +3 -2
  86. mistralai/models/functioncallevent.py +1 -1
  87. mistralai/models/functionresultentry.py +3 -2
  88. mistralai/models/functiontool.py +1 -1
  89. mistralai/models/githubrepositoryin.py +1 -1
  90. mistralai/models/githubrepositoryout.py +1 -1
  91. mistralai/models/httpvalidationerror.py +4 -2
  92. mistralai/models/imagegenerationtool.py +1 -1
  93. mistralai/models/imageurlchunk.py +1 -1
  94. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +40 -3
  95. mistralai/models/jobsout.py +1 -1
  96. mistralai/models/legacyjobmetadataout.py +1 -1
  97. mistralai/models/messageinputentry.py +9 -3
  98. mistralai/models/messageoutputentry.py +6 -3
  99. mistralai/models/messageoutputevent.py +4 -2
  100. mistralai/models/mistralerror.py +11 -7
  101. mistralai/models/mistralpromptmode.py +1 -1
  102. mistralai/models/modelconversation.py +1 -1
  103. mistralai/models/no_response_error.py +5 -1
  104. mistralai/models/ocrrequest.py +11 -1
  105. mistralai/models/ocrtableobject.py +4 -1
  106. mistralai/models/referencechunk.py +1 -1
  107. mistralai/models/requestsource.py +5 -1
  108. mistralai/models/responsedoneevent.py +1 -1
  109. mistralai/models/responseerrorevent.py +1 -1
  110. mistralai/models/responseformats.py +5 -1
  111. mistralai/models/responsestartedevent.py +1 -1
  112. mistralai/models/responsevalidationerror.py +2 -0
  113. mistralai/models/retrievefileout.py +3 -5
  114. mistralai/models/sampletype.py +7 -1
  115. mistralai/models/sdkerror.py +2 -0
  116. mistralai/models/shareenum.py +7 -1
  117. mistralai/models/sharingdelete.py +2 -4
  118. mistralai/models/sharingin.py +3 -5
  119. mistralai/models/source.py +8 -1
  120. mistralai/models/systemmessage.py +1 -1
  121. mistralai/models/textchunk.py +1 -1
  122. mistralai/models/thinkchunk.py +1 -1
  123. mistralai/models/timestampgranularity.py +1 -1
  124. mistralai/models/tool.py +2 -6
  125. mistralai/models/toolcall.py +2 -6
  126. mistralai/models/toolchoice.py +2 -6
  127. mistralai/models/toolchoiceenum.py +6 -1
  128. mistralai/models/toolexecutiondeltaevent.py +2 -1
  129. mistralai/models/toolexecutiondoneevent.py +2 -1
  130. mistralai/models/toolexecutionentry.py +4 -2
  131. mistralai/models/toolexecutionstartedevent.py +2 -1
  132. mistralai/models/toolfilechunk.py +13 -5
  133. mistralai/models/toolmessage.py +1 -1
  134. mistralai/models/toolreferencechunk.py +15 -5
  135. mistralai/models/tooltypes.py +1 -1
  136. mistralai/models/transcriptionsegmentchunk.py +1 -1
  137. mistralai/models/transcriptionstreamdone.py +1 -1
  138. mistralai/models/transcriptionstreamlanguage.py +1 -1
  139. mistralai/models/transcriptionstreamsegmentdelta.py +1 -1
  140. mistralai/models/transcriptionstreamtextdelta.py +1 -1
  141. mistralai/models/unarchiveftmodelout.py +1 -1
  142. mistralai/models/uploadfileout.py +3 -5
  143. mistralai/models/usermessage.py +1 -1
  144. mistralai/models/wandbintegration.py +1 -1
  145. mistralai/models/wandbintegrationout.py +1 -1
  146. mistralai/models/websearchpremiumtool.py +1 -1
  147. mistralai/models/websearchtool.py +1 -1
  148. mistralai/models_.py +24 -12
  149. mistralai/ocr.py +38 -10
  150. mistralai/sdk.py +2 -2
  151. mistralai/transcriptions.py +28 -12
  152. mistralai/types/basemodel.py +41 -3
  153. mistralai/utils/__init__.py +0 -3
  154. mistralai/utils/annotations.py +32 -8
  155. mistralai/utils/enums.py +60 -0
  156. mistralai/utils/forms.py +21 -10
  157. mistralai/utils/queryparams.py +14 -2
  158. mistralai/utils/requestbodies.py +3 -3
  159. mistralai/utils/retries.py +69 -5
  160. mistralai/utils/serializers.py +0 -20
  161. mistralai/utils/unmarshal_json_response.py +15 -1
  162. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/METADATA +144 -159
  163. mistralai-1.11.1.dist-info/RECORD +495 -0
  164. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/WHEEL +1 -1
  165. mistralai_azure/_version.py +3 -3
  166. mistralai_azure/basesdk.py +21 -5
  167. mistralai_azure/chat.py +82 -109
  168. mistralai_azure/httpclient.py +0 -1
  169. mistralai_azure/models/__init__.py +66 -4
  170. mistralai_azure/models/assistantmessage.py +1 -1
  171. mistralai_azure/models/chatcompletionchoice.py +10 -7
  172. mistralai_azure/models/chatcompletionrequest.py +24 -10
  173. mistralai_azure/models/chatcompletionstreamrequest.py +24 -10
  174. mistralai_azure/models/completionresponsestreamchoice.py +11 -7
  175. mistralai_azure/models/documenturlchunk.py +1 -1
  176. mistralai_azure/models/httpvalidationerror.py +15 -8
  177. mistralai_azure/models/imageurlchunk.py +1 -1
  178. mistralai_azure/models/mistralazureerror.py +30 -0
  179. mistralai_azure/models/mistralpromptmode.py +1 -1
  180. mistralai_azure/models/no_response_error.py +17 -0
  181. mistralai_azure/models/ocrpageobject.py +32 -5
  182. mistralai_azure/models/ocrrequest.py +20 -1
  183. mistralai_azure/models/ocrtableobject.py +34 -0
  184. mistralai_azure/models/prediction.py +4 -0
  185. mistralai_azure/models/referencechunk.py +1 -1
  186. mistralai_azure/models/responseformat.py +4 -2
  187. mistralai_azure/models/responseformats.py +5 -2
  188. mistralai_azure/models/responsevalidationerror.py +27 -0
  189. mistralai_azure/models/sdkerror.py +32 -14
  190. mistralai_azure/models/systemmessage.py +8 -4
  191. mistralai_azure/models/systemmessagecontentchunks.py +21 -0
  192. mistralai_azure/models/textchunk.py +1 -1
  193. mistralai_azure/models/thinkchunk.py +35 -0
  194. mistralai_azure/models/tool.py +2 -6
  195. mistralai_azure/models/toolcall.py +2 -6
  196. mistralai_azure/models/toolchoice.py +2 -6
  197. mistralai_azure/models/toolchoiceenum.py +6 -1
  198. mistralai_azure/models/toolmessage.py +1 -1
  199. mistralai_azure/models/tooltypes.py +1 -1
  200. mistralai_azure/models/usermessage.py +1 -1
  201. mistralai_azure/ocr.py +39 -40
  202. mistralai_azure/types/basemodel.py +41 -3
  203. mistralai_azure/utils/__init__.py +18 -8
  204. mistralai_azure/utils/annotations.py +32 -8
  205. mistralai_azure/utils/enums.py +60 -0
  206. mistralai_azure/utils/eventstreaming.py +10 -0
  207. mistralai_azure/utils/forms.py +21 -10
  208. mistralai_azure/utils/queryparams.py +14 -2
  209. mistralai_azure/utils/requestbodies.py +3 -3
  210. mistralai_azure/utils/retries.py +69 -5
  211. mistralai_azure/utils/serializers.py +3 -22
  212. mistralai_azure/utils/unmarshal_json_response.py +38 -0
  213. mistralai_gcp/_hooks/types.py +7 -0
  214. mistralai_gcp/_version.py +4 -4
  215. mistralai_gcp/basesdk.py +33 -25
  216. mistralai_gcp/chat.py +98 -109
  217. mistralai_gcp/fim.py +62 -85
  218. mistralai_gcp/httpclient.py +6 -17
  219. mistralai_gcp/models/__init__.py +321 -116
  220. mistralai_gcp/models/assistantmessage.py +2 -2
  221. mistralai_gcp/models/chatcompletionchoice.py +10 -7
  222. mistralai_gcp/models/chatcompletionrequest.py +38 -7
  223. mistralai_gcp/models/chatcompletionresponse.py +6 -6
  224. mistralai_gcp/models/chatcompletionstreamrequest.py +38 -7
  225. mistralai_gcp/models/completionresponsestreamchoice.py +12 -8
  226. mistralai_gcp/models/deltamessage.py +1 -1
  227. mistralai_gcp/models/fimcompletionrequest.py +9 -10
  228. mistralai_gcp/models/fimcompletionresponse.py +6 -6
  229. mistralai_gcp/models/fimcompletionstreamrequest.py +9 -10
  230. mistralai_gcp/models/httpvalidationerror.py +15 -8
  231. mistralai_gcp/models/imageurl.py +1 -1
  232. mistralai_gcp/models/imageurlchunk.py +1 -1
  233. mistralai_gcp/models/jsonschema.py +1 -1
  234. mistralai_gcp/models/mistralgcperror.py +30 -0
  235. mistralai_gcp/models/mistralpromptmode.py +8 -0
  236. mistralai_gcp/models/no_response_error.py +17 -0
  237. mistralai_gcp/models/prediction.py +4 -0
  238. mistralai_gcp/models/referencechunk.py +1 -1
  239. mistralai_gcp/models/responseformat.py +5 -3
  240. mistralai_gcp/models/responseformats.py +5 -2
  241. mistralai_gcp/models/responsevalidationerror.py +27 -0
  242. mistralai_gcp/models/sdkerror.py +32 -14
  243. mistralai_gcp/models/systemmessage.py +8 -4
  244. mistralai_gcp/models/systemmessagecontentchunks.py +21 -0
  245. mistralai_gcp/models/textchunk.py +1 -1
  246. mistralai_gcp/models/thinkchunk.py +35 -0
  247. mistralai_gcp/models/tool.py +2 -6
  248. mistralai_gcp/models/toolcall.py +2 -6
  249. mistralai_gcp/models/toolchoice.py +2 -6
  250. mistralai_gcp/models/toolchoiceenum.py +6 -1
  251. mistralai_gcp/models/toolmessage.py +2 -2
  252. mistralai_gcp/models/tooltypes.py +1 -1
  253. mistralai_gcp/models/usageinfo.py +71 -8
  254. mistralai_gcp/models/usermessage.py +2 -2
  255. mistralai_gcp/sdk.py +12 -10
  256. mistralai_gcp/sdkconfiguration.py +0 -7
  257. mistralai_gcp/types/basemodel.py +41 -3
  258. mistralai_gcp/utils/__init__.py +141 -46
  259. mistralai_gcp/utils/annotations.py +32 -8
  260. mistralai_gcp/utils/datetimes.py +23 -0
  261. mistralai_gcp/utils/enums.py +125 -25
  262. mistralai_gcp/utils/eventstreaming.py +10 -0
  263. mistralai_gcp/utils/forms.py +62 -30
  264. mistralai_gcp/utils/queryparams.py +14 -2
  265. mistralai_gcp/utils/requestbodies.py +3 -3
  266. mistralai_gcp/utils/retries.py +69 -5
  267. mistralai_gcp/utils/serializers.py +33 -23
  268. mistralai_gcp/utils/unmarshal_json_response.py +38 -0
  269. mistralai-1.10.0.dist-info/RECORD +0 -475
  270. {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,23 +1,27 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from __future__ import annotations
4
- from .textchunk import TextChunk, TextChunkTypedDict
4
+ from .systemmessagecontentchunks import (
5
+ SystemMessageContentChunks,
6
+ SystemMessageContentChunksTypedDict,
7
+ )
5
8
  from mistralai_gcp.types import BaseModel
6
9
  from typing import List, Literal, Optional, Union
7
10
  from typing_extensions import NotRequired, TypeAliasType, TypedDict
8
11
 
9
12
 
10
13
  SystemMessageContentTypedDict = TypeAliasType(
11
- "SystemMessageContentTypedDict", Union[str, List[TextChunkTypedDict]]
14
+ "SystemMessageContentTypedDict",
15
+ Union[str, List[SystemMessageContentChunksTypedDict]],
12
16
  )
13
17
 
14
18
 
15
19
  SystemMessageContent = TypeAliasType(
16
- "SystemMessageContent", Union[str, List[TextChunk]]
20
+ "SystemMessageContent", Union[str, List[SystemMessageContentChunks]]
17
21
  )
18
22
 
19
23
 
20
- Role = Literal["system"]
24
+ Role = Literal["system",]
21
25
 
22
26
 
23
27
  class SystemMessageTypedDict(TypedDict):
@@ -0,0 +1,21 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .textchunk import TextChunk, TextChunkTypedDict
5
+ from .thinkchunk import ThinkChunk, ThinkChunkTypedDict
6
+ from mistralai_gcp.utils import get_discriminator
7
+ from pydantic import Discriminator, Tag
8
+ from typing import Union
9
+ from typing_extensions import Annotated, TypeAliasType
10
+
11
+
12
+ SystemMessageContentChunksTypedDict = TypeAliasType(
13
+ "SystemMessageContentChunksTypedDict",
14
+ Union[TextChunkTypedDict, ThinkChunkTypedDict],
15
+ )
16
+
17
+
18
+ SystemMessageContentChunks = Annotated[
19
+ Union[Annotated[TextChunk, Tag("text")], Annotated[ThinkChunk, Tag("thinking")]],
20
+ Discriminator(lambda m: get_discriminator(m, "type", "type")),
21
+ ]
@@ -6,7 +6,7 @@ from typing import Literal, Optional
6
6
  from typing_extensions import NotRequired, TypedDict
7
7
 
8
8
 
9
- Type = Literal["text"]
9
+ Type = Literal["text",]
10
10
 
11
11
 
12
12
  class TextChunkTypedDict(TypedDict):
@@ -0,0 +1,35 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .referencechunk import ReferenceChunk, ReferenceChunkTypedDict
5
+ from .textchunk import TextChunk, TextChunkTypedDict
6
+ from mistralai_gcp.types import BaseModel
7
+ from typing import List, Literal, Optional, Union
8
+ from typing_extensions import NotRequired, TypeAliasType, TypedDict
9
+
10
+
11
+ ThinkingTypedDict = TypeAliasType(
12
+ "ThinkingTypedDict", Union[ReferenceChunkTypedDict, TextChunkTypedDict]
13
+ )
14
+
15
+
16
+ Thinking = TypeAliasType("Thinking", Union[ReferenceChunk, TextChunk])
17
+
18
+
19
+ ThinkChunkType = Literal["thinking",]
20
+
21
+
22
+ class ThinkChunkTypedDict(TypedDict):
23
+ thinking: List[ThinkingTypedDict]
24
+ closed: NotRequired[bool]
25
+ r"""Whether the thinking chunk is closed or not. Currently only used for prefixing."""
26
+ type: NotRequired[ThinkChunkType]
27
+
28
+
29
+ class ThinkChunk(BaseModel):
30
+ thinking: List[Thinking]
31
+
32
+ closed: Optional[bool] = None
33
+ r"""Whether the thinking chunk is closed or not. Currently only used for prefixing."""
34
+
35
+ type: Optional[ThinkChunkType] = "thinking"
@@ -4,10 +4,8 @@ from __future__ import annotations
4
4
  from .function import Function, FunctionTypedDict
5
5
  from .tooltypes import ToolTypes
6
6
  from mistralai_gcp.types import BaseModel
7
- from mistralai_gcp.utils import validate_open_enum
8
- from pydantic.functional_validators import PlainValidator
9
7
  from typing import Optional
10
- from typing_extensions import Annotated, NotRequired, TypedDict
8
+ from typing_extensions import NotRequired, TypedDict
11
9
 
12
10
 
13
11
  class ToolTypedDict(TypedDict):
@@ -18,6 +16,4 @@ class ToolTypedDict(TypedDict):
18
16
  class Tool(BaseModel):
19
17
  function: Function
20
18
 
21
- type: Annotated[Optional[ToolTypes], PlainValidator(validate_open_enum(False))] = (
22
- None
23
- )
19
+ type: Optional[ToolTypes] = None
@@ -4,10 +4,8 @@ from __future__ import annotations
4
4
  from .functioncall import FunctionCall, FunctionCallTypedDict
5
5
  from .tooltypes import ToolTypes
6
6
  from mistralai_gcp.types import BaseModel
7
- from mistralai_gcp.utils import validate_open_enum
8
- from pydantic.functional_validators import PlainValidator
9
7
  from typing import Optional
10
- from typing_extensions import Annotated, NotRequired, TypedDict
8
+ from typing_extensions import NotRequired, TypedDict
11
9
 
12
10
 
13
11
  class ToolCallTypedDict(TypedDict):
@@ -22,8 +20,6 @@ class ToolCall(BaseModel):
22
20
 
23
21
  id: Optional[str] = "null"
24
22
 
25
- type: Annotated[Optional[ToolTypes], PlainValidator(validate_open_enum(False))] = (
26
- None
27
- )
23
+ type: Optional[ToolTypes] = None
28
24
 
29
25
  index: Optional[int] = 0
@@ -4,10 +4,8 @@ from __future__ import annotations
4
4
  from .functionname import FunctionName, FunctionNameTypedDict
5
5
  from .tooltypes import ToolTypes
6
6
  from mistralai_gcp.types import BaseModel
7
- from mistralai_gcp.utils import validate_open_enum
8
- from pydantic.functional_validators import PlainValidator
9
7
  from typing import Optional
10
- from typing_extensions import Annotated, NotRequired, TypedDict
8
+ from typing_extensions import NotRequired, TypedDict
11
9
 
12
10
 
13
11
  class ToolChoiceTypedDict(TypedDict):
@@ -24,6 +22,4 @@ class ToolChoice(BaseModel):
24
22
  function: FunctionName
25
23
  r"""this restriction of `Function` is used to select a specific function to call"""
26
24
 
27
- type: Annotated[Optional[ToolTypes], PlainValidator(validate_open_enum(False))] = (
28
- None
29
- )
25
+ type: Optional[ToolTypes] = None
@@ -4,4 +4,9 @@ from __future__ import annotations
4
4
  from typing import Literal
5
5
 
6
6
 
7
- ToolChoiceEnum = Literal["auto", "none", "any", "required"]
7
+ ToolChoiceEnum = Literal[
8
+ "auto",
9
+ "none",
10
+ "any",
11
+ "required",
12
+ ]
@@ -22,7 +22,7 @@ ToolMessageContentTypedDict = TypeAliasType(
22
22
  ToolMessageContent = TypeAliasType("ToolMessageContent", Union[str, List[ContentChunk]])
23
23
 
24
24
 
25
- ToolMessageRole = Literal["tool"]
25
+ ToolMessageRole = Literal["tool",]
26
26
 
27
27
 
28
28
  class ToolMessageTypedDict(TypedDict):
@@ -51,7 +51,7 @@ class ToolMessage(BaseModel):
51
51
 
52
52
  m = {}
53
53
 
54
- for n, f in self.model_fields.items():
54
+ for n, f in type(self).model_fields.items():
55
55
  k = f.alias or n
56
56
  val = serialized.get(k)
57
57
  serialized.pop(k, None)
@@ -5,4 +5,4 @@ from mistralai_gcp.types import UnrecognizedStr
5
5
  from typing import Literal, Union
6
6
 
7
7
 
8
- ToolTypes = Union[Literal["function"], UnrecognizedStr]
8
+ ToolTypes = Union[Literal["function",], UnrecognizedStr]
@@ -1,19 +1,82 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
3
  from __future__ import annotations
4
- from mistralai_gcp.types import BaseModel
5
- from typing_extensions import TypedDict
4
+ from mistralai_gcp.types import (
5
+ BaseModel,
6
+ Nullable,
7
+ OptionalNullable,
8
+ UNSET,
9
+ UNSET_SENTINEL,
10
+ )
11
+ import pydantic
12
+ from pydantic import ConfigDict, model_serializer
13
+ from typing import Any, Dict, Optional
14
+ from typing_extensions import NotRequired, TypedDict
6
15
 
7
16
 
8
17
  class UsageInfoTypedDict(TypedDict):
9
- prompt_tokens: int
10
- completion_tokens: int
11
- total_tokens: int
18
+ prompt_tokens: NotRequired[int]
19
+ completion_tokens: NotRequired[int]
20
+ total_tokens: NotRequired[int]
21
+ prompt_audio_seconds: NotRequired[Nullable[int]]
12
22
 
13
23
 
14
24
  class UsageInfo(BaseModel):
15
- prompt_tokens: int
25
+ model_config = ConfigDict(
26
+ populate_by_name=True, arbitrary_types_allowed=True, extra="allow"
27
+ )
28
+ __pydantic_extra__: Dict[str, Any] = pydantic.Field(init=False)
16
29
 
17
- completion_tokens: int
30
+ prompt_tokens: Optional[int] = 0
18
31
 
19
- total_tokens: int
32
+ completion_tokens: Optional[int] = 0
33
+
34
+ total_tokens: Optional[int] = 0
35
+
36
+ prompt_audio_seconds: OptionalNullable[int] = UNSET
37
+
38
+ @property
39
+ def additional_properties(self):
40
+ return self.__pydantic_extra__
41
+
42
+ @additional_properties.setter
43
+ def additional_properties(self, value):
44
+ self.__pydantic_extra__ = value # pyright: ignore[reportIncompatibleVariableOverride]
45
+
46
+ @model_serializer(mode="wrap")
47
+ def serialize_model(self, handler):
48
+ optional_fields = [
49
+ "prompt_tokens",
50
+ "completion_tokens",
51
+ "total_tokens",
52
+ "prompt_audio_seconds",
53
+ ]
54
+ nullable_fields = ["prompt_audio_seconds"]
55
+ null_default_fields = []
56
+
57
+ serialized = handler(self)
58
+
59
+ m = {}
60
+
61
+ for n, f in type(self).model_fields.items():
62
+ k = f.alias or n
63
+ val = serialized.get(k)
64
+ serialized.pop(k, None)
65
+
66
+ optional_nullable = k in optional_fields and k in nullable_fields
67
+ is_set = (
68
+ self.__pydantic_fields_set__.intersection({n})
69
+ or k in null_default_fields
70
+ ) # pylint: disable=no-member
71
+
72
+ if val is not None and val != UNSET_SENTINEL:
73
+ m[k] = val
74
+ elif val != UNSET_SENTINEL and (
75
+ not k in optional_fields or (optional_nullable and is_set)
76
+ ):
77
+ m[k] = val
78
+
79
+ for k, v in serialized.items():
80
+ m[k] = v
81
+
82
+ return m
@@ -16,7 +16,7 @@ UserMessageContentTypedDict = TypeAliasType(
16
16
  UserMessageContent = TypeAliasType("UserMessageContent", Union[str, List[ContentChunk]])
17
17
 
18
18
 
19
- UserMessageRole = Literal["user"]
19
+ UserMessageRole = Literal["user",]
20
20
 
21
21
 
22
22
  class UserMessageTypedDict(TypedDict):
@@ -39,7 +39,7 @@ class UserMessage(BaseModel):
39
39
 
40
40
  m = {}
41
41
 
42
- for n, f in self.model_fields.items():
42
+ for n, f in type(self).model_fields.items():
43
43
  k = f.alias or n
44
44
  val = serialized.get(k)
45
45
  serialized.pop(k, None)
mistralai_gcp/sdk.py CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  import json
4
4
  import weakref
5
- from typing import Any, Optional, cast
5
+ from typing import Any, Optional, Union, cast
6
6
 
7
7
  import google.auth
8
8
  import google.auth.credentials
@@ -67,30 +67,32 @@ class MistralGoogleCloud(BaseSDK):
67
67
  :param timeout_ms: Optional request timeout applied to each operation in milliseconds
68
68
  """
69
69
 
70
+ credentials = None
70
71
  if not access_token:
71
72
  credentials, loaded_project_id = google.auth.default(
72
73
  scopes=["https://www.googleapis.com/auth/cloud-platform"],
73
74
  )
74
- credentials.refresh(google.auth.transport.requests.Request())
75
75
 
76
- if not isinstance(credentials, google.auth.credentials.Credentials):
77
- raise models.SDKError(
78
- "credentials must be an instance of google.auth.credentials.Credentials"
79
- )
76
+ # default will already raise a google.auth.exceptions.DefaultCredentialsError if no credentials are found
77
+ assert isinstance(
78
+ credentials, google.auth.credentials.Credentials
79
+ ), "credentials must be an instance of google.auth.credentials.Credentials"
80
80
 
81
+ credentials.refresh(google.auth.transport.requests.Request())
81
82
  project_id = project_id or loaded_project_id
82
83
 
83
84
  if project_id is None:
84
- raise models.SDKError("project_id must be provided")
85
+ raise ValueError("project_id must be provided")
85
86
 
86
87
  def auth_token() -> str:
87
88
  if access_token:
88
89
  return access_token
89
90
 
91
+ assert credentials is not None, "credentials must be initialized"
90
92
  credentials.refresh(google.auth.transport.requests.Request())
91
93
  token = credentials.token
92
94
  if not token:
93
- raise models.SDKError("Failed to get token from credentials")
95
+ raise Exception("Failed to get token from credentials")
94
96
  return token
95
97
 
96
98
  client_supplied = True
@@ -197,7 +199,7 @@ class GoogleCloudBeforeRequestHook(BeforeRequestHook):
197
199
 
198
200
  def before_request(
199
201
  self, hook_ctx, request: httpx.Request
200
- ) -> httpx.Request | Exception:
202
+ ) -> Union[httpx.Request, Exception]:
201
203
  # The goal of this function is to template in the region, project and model into the URL path
202
204
  # We do this here so that the API remains more user-friendly
203
205
  model_id = None
@@ -210,7 +212,7 @@ class GoogleCloudBeforeRequestHook(BeforeRequestHook):
210
212
  new_content = json.dumps(parsed).encode("utf-8")
211
213
 
212
214
  if model_id == "":
213
- raise models.SDKError("model must be provided")
215
+ raise ValueError("model must be provided")
214
216
 
215
217
  stream = "streamRawPredict" in request.url.path
216
218
  specifier = "streamRawPredict" if stream else "rawPredict"
@@ -1,6 +1,5 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from ._hooks import SDKHooks
4
3
  from ._version import (
5
4
  __gen_version__,
6
5
  __openapi_doc_version__,
@@ -42,9 +41,6 @@ class SDKConfiguration:
42
41
  retry_config: OptionalNullable[RetryConfig] = Field(default_factory=lambda: UNSET)
43
42
  timeout_ms: Optional[int] = None
44
43
 
45
- def __post_init__(self):
46
- self._hooks = SDKHooks()
47
-
48
44
  def get_server_details(self) -> Tuple[str, Dict[str, str]]:
49
45
  if self.server_url is not None and self.server_url:
50
46
  return remove_suffix(self.server_url, "/"), {}
@@ -55,6 +51,3 @@ class SDKConfiguration:
55
51
  raise ValueError(f'Invalid server "{self.server}"')
56
52
 
57
53
  return SERVERS[self.server], {}
58
-
59
- def get_hooks(self) -> SDKHooks:
60
- return self._hooks
@@ -2,7 +2,8 @@
2
2
 
3
3
  from pydantic import ConfigDict, model_serializer
4
4
  from pydantic import BaseModel as PydanticBaseModel
5
- from typing import TYPE_CHECKING, Literal, Optional, TypeVar, Union, NewType
5
+ from pydantic_core import core_schema
6
+ from typing import TYPE_CHECKING, Any, Literal, Optional, TypeVar, Union
6
7
  from typing_extensions import TypeAliasType, TypeAlias
7
8
 
8
9
 
@@ -35,5 +36,42 @@ else:
35
36
  "OptionalNullable", Union[Optional[Nullable[T]], Unset], type_params=(T,)
36
37
  )
37
38
 
38
- UnrecognizedInt = NewType("UnrecognizedInt", int)
39
- UnrecognizedStr = NewType("UnrecognizedStr", str)
39
+
40
+ class UnrecognizedStr(str):
41
+ @classmethod
42
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
43
+ # Make UnrecognizedStr only work in lax mode, not strict mode
44
+ # This makes it a "fallback" option when more specific types (like Literals) don't match
45
+ def validate_lax(v: Any) -> 'UnrecognizedStr':
46
+ if isinstance(v, cls):
47
+ return v
48
+ return cls(str(v))
49
+
50
+ # Use lax_or_strict_schema where strict always fails
51
+ # This forces Pydantic to prefer other union members in strict mode
52
+ # and only fall back to UnrecognizedStr in lax mode
53
+ return core_schema.lax_or_strict_schema(
54
+ lax_schema=core_schema.chain_schema([
55
+ core_schema.str_schema(),
56
+ core_schema.no_info_plain_validator_function(validate_lax)
57
+ ]),
58
+ strict_schema=core_schema.none_schema(), # Always fails in strict mode
59
+ )
60
+
61
+
62
+ class UnrecognizedInt(int):
63
+ @classmethod
64
+ def __get_pydantic_core_schema__(cls, _source_type: Any, _handler: Any) -> core_schema.CoreSchema:
65
+ # Make UnrecognizedInt only work in lax mode, not strict mode
66
+ # This makes it a "fallback" option when more specific types (like Literals) don't match
67
+ def validate_lax(v: Any) -> 'UnrecognizedInt':
68
+ if isinstance(v, cls):
69
+ return v
70
+ return cls(int(v))
71
+ return core_schema.lax_or_strict_schema(
72
+ lax_schema=core_schema.chain_schema([
73
+ core_schema.int_schema(),
74
+ core_schema.no_info_plain_validator_function(validate_lax)
75
+ ]),
76
+ strict_schema=core_schema.none_schema(), # Always fails in strict mode
77
+ )
@@ -1,50 +1,56 @@
1
1
  """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
2
 
3
- from .annotations import get_discriminator
4
- from .enums import OpenEnumMeta
5
- from .headers import get_headers, get_response_headers
6
- from .metadata import (
7
- FieldMetadata,
8
- find_metadata,
9
- FormMetadata,
10
- HeaderMetadata,
11
- MultipartFormMetadata,
12
- PathParamMetadata,
13
- QueryParamMetadata,
14
- RequestMetadata,
15
- SecurityMetadata,
16
- )
17
- from .queryparams import get_query_params
18
- from .retries import BackoffStrategy, Retries, retry, retry_async, RetryConfig
19
- from .requestbodies import serialize_request_body, SerializedRequestBody
20
- from .security import get_security
21
- from .serializers import (
22
- get_pydantic_model,
23
- marshal_json,
24
- unmarshal,
25
- unmarshal_json,
26
- serialize_decimal,
27
- serialize_float,
28
- serialize_int,
29
- stream_to_text,
30
- stream_to_text_async,
31
- stream_to_bytes,
32
- stream_to_bytes_async,
33
- validate_const,
34
- validate_decimal,
35
- validate_float,
36
- validate_int,
37
- validate_open_enum,
38
- )
39
- from .url import generate_url, template_url, remove_suffix
40
- from .values import (
41
- get_global_from_env,
42
- match_content_type,
43
- match_status_codes,
44
- match_response,
45
- cast_partial,
46
- )
47
- from .logger import Logger, get_body_content, get_default_logger
3
+ from typing import TYPE_CHECKING
4
+ from importlib import import_module
5
+ import builtins
6
+ import sys
7
+
8
+ if TYPE_CHECKING:
9
+ from .annotations import get_discriminator
10
+ from .datetimes import parse_datetime
11
+ from .enums import OpenEnumMeta
12
+ from .headers import get_headers, get_response_headers
13
+ from .metadata import (
14
+ FieldMetadata,
15
+ find_metadata,
16
+ FormMetadata,
17
+ HeaderMetadata,
18
+ MultipartFormMetadata,
19
+ PathParamMetadata,
20
+ QueryParamMetadata,
21
+ RequestMetadata,
22
+ SecurityMetadata,
23
+ )
24
+ from .queryparams import get_query_params
25
+ from .retries import BackoffStrategy, Retries, retry, retry_async, RetryConfig
26
+ from .requestbodies import serialize_request_body, SerializedRequestBody
27
+ from .security import get_security
28
+ from .serializers import (
29
+ get_pydantic_model,
30
+ marshal_json,
31
+ unmarshal,
32
+ unmarshal_json,
33
+ serialize_decimal,
34
+ serialize_float,
35
+ serialize_int,
36
+ stream_to_text,
37
+ stream_to_text_async,
38
+ stream_to_bytes,
39
+ stream_to_bytes_async,
40
+ validate_const,
41
+ validate_decimal,
42
+ validate_float,
43
+ validate_int,
44
+ )
45
+ from .url import generate_url, template_url, remove_suffix
46
+ from .values import (
47
+ get_global_from_env,
48
+ match_content_type,
49
+ match_status_codes,
50
+ match_response,
51
+ cast_partial,
52
+ )
53
+ from .logger import Logger, get_body_content, get_default_logger
48
54
 
49
55
  __all__ = [
50
56
  "BackoffStrategy",
@@ -55,6 +61,7 @@ __all__ = [
55
61
  "get_body_content",
56
62
  "get_default_logger",
57
63
  "get_discriminator",
64
+ "parse_datetime",
58
65
  "get_global_from_env",
59
66
  "get_headers",
60
67
  "get_pydantic_model",
@@ -94,6 +101,94 @@ __all__ = [
94
101
  "validate_const",
95
102
  "validate_float",
96
103
  "validate_int",
97
- "validate_open_enum",
98
104
  "cast_partial",
99
105
  ]
106
+
107
+ _dynamic_imports: dict[str, str] = {
108
+ "BackoffStrategy": ".retries",
109
+ "FieldMetadata": ".metadata",
110
+ "find_metadata": ".metadata",
111
+ "FormMetadata": ".metadata",
112
+ "generate_url": ".url",
113
+ "get_body_content": ".logger",
114
+ "get_default_logger": ".logger",
115
+ "get_discriminator": ".annotations",
116
+ "parse_datetime": ".datetimes",
117
+ "get_global_from_env": ".values",
118
+ "get_headers": ".headers",
119
+ "get_pydantic_model": ".serializers",
120
+ "get_query_params": ".queryparams",
121
+ "get_response_headers": ".headers",
122
+ "get_security": ".security",
123
+ "HeaderMetadata": ".metadata",
124
+ "Logger": ".logger",
125
+ "marshal_json": ".serializers",
126
+ "match_content_type": ".values",
127
+ "match_status_codes": ".values",
128
+ "match_response": ".values",
129
+ "MultipartFormMetadata": ".metadata",
130
+ "OpenEnumMeta": ".enums",
131
+ "PathParamMetadata": ".metadata",
132
+ "QueryParamMetadata": ".metadata",
133
+ "remove_suffix": ".url",
134
+ "Retries": ".retries",
135
+ "retry": ".retries",
136
+ "retry_async": ".retries",
137
+ "RetryConfig": ".retries",
138
+ "RequestMetadata": ".metadata",
139
+ "SecurityMetadata": ".metadata",
140
+ "serialize_decimal": ".serializers",
141
+ "serialize_float": ".serializers",
142
+ "serialize_int": ".serializers",
143
+ "serialize_request_body": ".requestbodies",
144
+ "SerializedRequestBody": ".requestbodies",
145
+ "stream_to_text": ".serializers",
146
+ "stream_to_text_async": ".serializers",
147
+ "stream_to_bytes": ".serializers",
148
+ "stream_to_bytes_async": ".serializers",
149
+ "template_url": ".url",
150
+ "unmarshal": ".serializers",
151
+ "unmarshal_json": ".serializers",
152
+ "validate_decimal": ".serializers",
153
+ "validate_const": ".serializers",
154
+ "validate_float": ".serializers",
155
+ "validate_int": ".serializers",
156
+ "cast_partial": ".values",
157
+ }
158
+
159
+
160
+ def dynamic_import(modname, retries=3):
161
+ for attempt in range(retries):
162
+ try:
163
+ return import_module(modname, __package__)
164
+ except KeyError:
165
+ # Clear any half-initialized module and retry
166
+ sys.modules.pop(modname, None)
167
+ if attempt == retries - 1:
168
+ break
169
+ raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
170
+
171
+
172
+ def __getattr__(attr_name: str) -> object:
173
+ module_name = _dynamic_imports.get(attr_name)
174
+ if module_name is None:
175
+ raise AttributeError(
176
+ f"no {attr_name} found in _dynamic_imports, module name -> {__name__} "
177
+ )
178
+
179
+ try:
180
+ module = dynamic_import(module_name)
181
+ return getattr(module, attr_name)
182
+ except ImportError as e:
183
+ raise ImportError(
184
+ f"Failed to import {attr_name} from {module_name}: {e}"
185
+ ) from e
186
+ except AttributeError as e:
187
+ raise AttributeError(
188
+ f"Failed to get {attr_name} from {module_name}: {e}"
189
+ ) from e
190
+
191
+
192
+ def __dir__():
193
+ lazy_attrs = builtins.list(_dynamic_imports.keys())
194
+ return builtins.sorted(lazy_attrs)