mistralai 1.8.2__py3-none-any.whl → 1.9.2__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 (152) hide show
  1. mistralai/_hooks/types.py +7 -0
  2. mistralai/_version.py +3 -3
  3. mistralai/accesses.py +672 -0
  4. mistralai/agents.py +8 -4
  5. mistralai/basesdk.py +12 -20
  6. mistralai/beta.py +4 -0
  7. mistralai/chat.py +8 -4
  8. mistralai/classifiers.py +8 -0
  9. mistralai/conversations.py +34 -14
  10. mistralai/documents.py +2136 -0
  11. mistralai/embeddings.py +2 -0
  12. mistralai/extra/run/context.py +2 -4
  13. mistralai/files.py +14 -2
  14. mistralai/fim.py +4 -0
  15. mistralai/httpclient.py +6 -16
  16. mistralai/jobs.py +10 -0
  17. mistralai/libraries.py +1041 -0
  18. mistralai/mistral_agents.py +10 -0
  19. mistralai/mistral_jobs.py +8 -0
  20. mistralai/models/__init__.py +1578 -721
  21. mistralai/models/agent.py +1 -1
  22. mistralai/models/agentconversation.py +1 -1
  23. mistralai/models/agentcreationrequest.py +1 -1
  24. mistralai/models/agenthandoffentry.py +1 -1
  25. mistralai/models/agents_api_v1_conversations_getop.py +2 -0
  26. mistralai/models/agents_api_v1_conversations_historyop.py +2 -0
  27. mistralai/models/agents_api_v1_conversations_messagesop.py +2 -0
  28. mistralai/models/agents_api_v1_conversations_restart_streamop.py +2 -0
  29. mistralai/models/agents_api_v1_conversations_restartop.py +2 -0
  30. mistralai/models/agentscompletionrequest.py +3 -1
  31. mistralai/models/agentscompletionstreamrequest.py +3 -1
  32. mistralai/models/agentupdaterequest.py +1 -1
  33. mistralai/models/assistantmessage.py +1 -1
  34. mistralai/models/basemodelcard.py +6 -1
  35. mistralai/models/batchjobin.py +1 -1
  36. mistralai/models/batchjobout.py +1 -1
  37. mistralai/models/chatcompletionrequest.py +3 -1
  38. mistralai/models/chatcompletionstreamrequest.py +3 -1
  39. mistralai/models/classifierdetailedjobout.py +1 -1
  40. mistralai/models/classifierftmodelout.py +1 -1
  41. mistralai/models/classifierjobout.py +1 -1
  42. mistralai/models/classifiertargetin.py +1 -1
  43. mistralai/models/classifiertrainingparameters.py +1 -1
  44. mistralai/models/classifiertrainingparametersin.py +1 -1
  45. mistralai/models/completionargs.py +1 -1
  46. mistralai/models/completiondetailedjobout.py +1 -1
  47. mistralai/models/completionftmodelout.py +1 -1
  48. mistralai/models/completionjobout.py +1 -1
  49. mistralai/models/completionresponsestreamchoice.py +1 -1
  50. mistralai/models/completiontrainingparameters.py +1 -1
  51. mistralai/models/completiontrainingparametersin.py +1 -1
  52. mistralai/models/contentchunk.py +3 -0
  53. mistralai/models/conversationevents.py +6 -0
  54. mistralai/models/conversationhistory.py +4 -4
  55. mistralai/models/conversationrequest.py +1 -1
  56. mistralai/models/conversationstreamrequest.py +1 -1
  57. mistralai/models/conversationusageinfo.py +1 -1
  58. mistralai/models/deltamessage.py +1 -1
  59. mistralai/models/documentout.py +105 -0
  60. mistralai/models/documenttextcontent.py +13 -0
  61. mistralai/models/documentupdatein.py +44 -0
  62. mistralai/models/documenturlchunk.py +1 -1
  63. mistralai/models/embeddingrequest.py +1 -1
  64. mistralai/models/entitytype.py +9 -0
  65. mistralai/models/eventout.py +1 -1
  66. mistralai/models/file.py +33 -0
  67. mistralai/models/filechunk.py +23 -0
  68. mistralai/models/files_api_routes_list_filesop.py +1 -1
  69. mistralai/models/files_api_routes_upload_fileop.py +2 -27
  70. mistralai/models/fileschema.py +1 -1
  71. mistralai/models/fimcompletionrequest.py +1 -1
  72. mistralai/models/fimcompletionstreamrequest.py +1 -1
  73. mistralai/models/ftmodelcard.py +6 -1
  74. mistralai/models/functioncallentry.py +1 -1
  75. mistralai/models/functionresultentry.py +1 -1
  76. mistralai/models/githubrepositoryin.py +1 -1
  77. mistralai/models/githubrepositoryout.py +1 -1
  78. mistralai/models/imageurl.py +1 -1
  79. mistralai/models/inputentries.py +21 -2
  80. mistralai/models/jobin.py +1 -1
  81. mistralai/models/jobmetadataout.py +1 -1
  82. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +1 -1
  83. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +1 -1
  84. mistralai/models/jsonschema.py +1 -1
  85. mistralai/models/legacyjobmetadataout.py +1 -1
  86. mistralai/models/libraries_delete_v1op.py +16 -0
  87. mistralai/models/libraries_documents_delete_v1op.py +21 -0
  88. mistralai/models/libraries_documents_get_extracted_text_signed_url_v1op.py +21 -0
  89. mistralai/models/libraries_documents_get_signed_url_v1op.py +21 -0
  90. mistralai/models/libraries_documents_get_status_v1op.py +21 -0
  91. mistralai/models/libraries_documents_get_text_content_v1op.py +21 -0
  92. mistralai/models/libraries_documents_get_v1op.py +21 -0
  93. mistralai/models/libraries_documents_list_v1op.py +78 -0
  94. mistralai/models/libraries_documents_reprocess_v1op.py +21 -0
  95. mistralai/models/libraries_documents_update_v1op.py +28 -0
  96. mistralai/models/libraries_documents_upload_v1op.py +56 -0
  97. mistralai/models/libraries_get_v1op.py +16 -0
  98. mistralai/models/libraries_share_create_v1op.py +22 -0
  99. mistralai/models/libraries_share_delete_v1op.py +23 -0
  100. mistralai/models/libraries_share_list_v1op.py +16 -0
  101. mistralai/models/libraries_update_v1op.py +23 -0
  102. mistralai/models/libraryin.py +50 -0
  103. mistralai/models/libraryinupdate.py +47 -0
  104. mistralai/models/libraryout.py +107 -0
  105. mistralai/models/listdocumentout.py +19 -0
  106. mistralai/models/listlibraryout.py +15 -0
  107. mistralai/models/listsharingout.py +15 -0
  108. mistralai/models/messageinputentry.py +12 -2
  109. mistralai/models/messageoutputentry.py +1 -1
  110. mistralai/models/messageoutputevent.py +1 -1
  111. mistralai/models/metricout.py +1 -1
  112. mistralai/models/modelcapabilities.py +3 -0
  113. mistralai/models/modelconversation.py +1 -1
  114. mistralai/models/ocrimageobject.py +1 -1
  115. mistralai/models/ocrpageobject.py +1 -1
  116. mistralai/models/ocrrequest.py +5 -3
  117. mistralai/models/ocrresponse.py +1 -1
  118. mistralai/models/ocrusageinfo.py +1 -1
  119. mistralai/models/paginationinfo.py +25 -0
  120. mistralai/models/processingstatusout.py +16 -0
  121. mistralai/models/responseformat.py +1 -1
  122. mistralai/models/retrievefileout.py +1 -1
  123. mistralai/models/shareenum.py +8 -0
  124. mistralai/models/sharingdelete.py +26 -0
  125. mistralai/models/sharingin.py +30 -0
  126. mistralai/models/sharingout.py +59 -0
  127. mistralai/models/ssetypes.py +1 -0
  128. mistralai/models/toolexecutiondeltaevent.py +34 -0
  129. mistralai/models/toolexecutionentry.py +4 -1
  130. mistralai/models/toolexecutionstartedevent.py +3 -0
  131. mistralai/models/toolfilechunk.py +1 -1
  132. mistralai/models/toolmessage.py +1 -1
  133. mistralai/models/toolreferencechunk.py +8 -5
  134. mistralai/models/updateftmodelin.py +1 -1
  135. mistralai/models/uploadfileout.py +1 -1
  136. mistralai/models/usermessage.py +1 -1
  137. mistralai/models/wandbintegration.py +1 -1
  138. mistralai/models/wandbintegrationout.py +1 -1
  139. mistralai/models_.py +14 -2
  140. mistralai/ocr.py +2 -0
  141. mistralai/sdk.py +68 -40
  142. mistralai/sdkconfiguration.py +0 -7
  143. mistralai/types/basemodel.py +3 -3
  144. mistralai/utils/__init__.py +131 -45
  145. mistralai/utils/datetimes.py +23 -0
  146. mistralai/utils/enums.py +67 -27
  147. mistralai/utils/forms.py +49 -28
  148. mistralai/utils/serializers.py +32 -3
  149. {mistralai-1.8.2.dist-info → mistralai-1.9.2.dist-info}/METADATA +41 -7
  150. {mistralai-1.8.2.dist-info → mistralai-1.9.2.dist-info}/RECORD +152 -113
  151. {mistralai-1.8.2.dist-info → mistralai-1.9.2.dist-info}/LICENSE +0 -0
  152. {mistralai-1.8.2.dist-info → mistralai-1.9.2.dist-info}/WHEEL +0 -0
@@ -0,0 +1,16 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai.types import BaseModel
5
+ from typing_extensions import TypedDict
6
+
7
+
8
+ class ProcessingStatusOutTypedDict(TypedDict):
9
+ document_id: str
10
+ processing_status: str
11
+
12
+
13
+ class ProcessingStatusOut(BaseModel):
14
+ document_id: str
15
+
16
+ processing_status: str
@@ -31,7 +31,7 @@ class ResponseFormat(BaseModel):
31
31
 
32
32
  m = {}
33
33
 
34
- for n, f in self.model_fields.items():
34
+ for n, f in type(self).model_fields.items():
35
35
  k = f.alias or n
36
36
  val = serialized.get(k)
37
37
  serialized.pop(k, None)
@@ -66,7 +66,7 @@ class RetrieveFileOut(BaseModel):
66
66
 
67
67
  m = {}
68
68
 
69
- for n, f in self.model_fields.items():
69
+ for n, f in type(self).model_fields.items():
70
70
  k = f.alias or n
71
71
  val = serialized.get(k)
72
72
  serialized.pop(k, None)
@@ -0,0 +1,8 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai.types import UnrecognizedStr
5
+ from typing import Literal, Union
6
+
7
+
8
+ ShareEnum = Union[Literal["Viewer", "Editor"], UnrecognizedStr]
@@ -0,0 +1,26 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .entitytype import EntityType
5
+ from mistralai.types import BaseModel
6
+ from mistralai.utils import validate_open_enum
7
+ from pydantic.functional_validators import PlainValidator
8
+ from typing_extensions import Annotated, TypedDict
9
+
10
+
11
+ class SharingDeleteTypedDict(TypedDict):
12
+ org_id: str
13
+ share_with_uuid: str
14
+ r"""The id of the entity (user, workspace or organization) to share with"""
15
+ share_with_type: EntityType
16
+ r"""The type of entity, used to share a library."""
17
+
18
+
19
+ class SharingDelete(BaseModel):
20
+ org_id: str
21
+
22
+ share_with_uuid: str
23
+ r"""The id of the entity (user, workspace or organization) to share with"""
24
+
25
+ share_with_type: Annotated[EntityType, PlainValidator(validate_open_enum(False))]
26
+ r"""The type of entity, used to share a library."""
@@ -0,0 +1,30 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .entitytype import EntityType
5
+ from .shareenum import ShareEnum
6
+ from mistralai.types import BaseModel
7
+ from mistralai.utils import validate_open_enum
8
+ from pydantic.functional_validators import PlainValidator
9
+ from typing_extensions import Annotated, TypedDict
10
+
11
+
12
+ class SharingInTypedDict(TypedDict):
13
+ org_id: str
14
+ level: ShareEnum
15
+ share_with_uuid: str
16
+ r"""The id of the entity (user, workspace or organization) to share with"""
17
+ share_with_type: EntityType
18
+ r"""The type of entity, used to share a library."""
19
+
20
+
21
+ class SharingIn(BaseModel):
22
+ org_id: str
23
+
24
+ level: Annotated[ShareEnum, PlainValidator(validate_open_enum(False))]
25
+
26
+ share_with_uuid: str
27
+ r"""The id of the entity (user, workspace or organization) to share with"""
28
+
29
+ share_with_type: Annotated[EntityType, PlainValidator(validate_open_enum(False))]
30
+ r"""The type of entity, used to share a library."""
@@ -0,0 +1,59 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
5
+ from pydantic import model_serializer
6
+ from typing_extensions import NotRequired, TypedDict
7
+
8
+
9
+ class SharingOutTypedDict(TypedDict):
10
+ library_id: str
11
+ org_id: str
12
+ role: str
13
+ share_with_type: str
14
+ share_with_uuid: str
15
+ user_id: NotRequired[Nullable[str]]
16
+
17
+
18
+ class SharingOut(BaseModel):
19
+ library_id: str
20
+
21
+ org_id: str
22
+
23
+ role: str
24
+
25
+ share_with_type: str
26
+
27
+ share_with_uuid: str
28
+
29
+ user_id: OptionalNullable[str] = UNSET
30
+
31
+ @model_serializer(mode="wrap")
32
+ def serialize_model(self, handler):
33
+ optional_fields = ["user_id"]
34
+ nullable_fields = ["user_id"]
35
+ null_default_fields = []
36
+
37
+ serialized = handler(self)
38
+
39
+ m = {}
40
+
41
+ for n, f in type(self).model_fields.items():
42
+ k = f.alias or n
43
+ val = serialized.get(k)
44
+ serialized.pop(k, None)
45
+
46
+ optional_nullable = k in optional_fields and k in nullable_fields
47
+ is_set = (
48
+ self.__pydantic_fields_set__.intersection({n})
49
+ or k in null_default_fields
50
+ ) # pylint: disable=no-member
51
+
52
+ if val is not None and val != UNSET_SENTINEL:
53
+ m[k] = val
54
+ elif val != UNSET_SENTINEL and (
55
+ not k in optional_fields or (optional_nullable and is_set)
56
+ ):
57
+ m[k] = val
58
+
59
+ return m
@@ -10,6 +10,7 @@ SSETypes = Literal[
10
10
  "conversation.response.error",
11
11
  "message.output.delta",
12
12
  "tool.execution.started",
13
+ "tool.execution.delta",
13
14
  "tool.execution.done",
14
15
  "agent.handoff.started",
15
16
  "agent.handoff.done",
@@ -0,0 +1,34 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .builtinconnectors import BuiltInConnectors
5
+ from datetime import datetime
6
+ from mistralai.types import BaseModel
7
+ from typing import Literal, Optional
8
+ from typing_extensions import NotRequired, TypedDict
9
+
10
+
11
+ ToolExecutionDeltaEventType = Literal["tool.execution.delta"]
12
+
13
+
14
+ class ToolExecutionDeltaEventTypedDict(TypedDict):
15
+ id: str
16
+ name: BuiltInConnectors
17
+ arguments: str
18
+ type: NotRequired[ToolExecutionDeltaEventType]
19
+ created_at: NotRequired[datetime]
20
+ output_index: NotRequired[int]
21
+
22
+
23
+ class ToolExecutionDeltaEvent(BaseModel):
24
+ id: str
25
+
26
+ name: BuiltInConnectors
27
+
28
+ arguments: str
29
+
30
+ type: Optional[ToolExecutionDeltaEventType] = "tool.execution.delta"
31
+
32
+ created_at: Optional[datetime] = None
33
+
34
+ output_index: Optional[int] = 0
@@ -16,6 +16,7 @@ ToolExecutionEntryType = Literal["tool.execution"]
16
16
 
17
17
  class ToolExecutionEntryTypedDict(TypedDict):
18
18
  name: BuiltInConnectors
19
+ arguments: str
19
20
  object: NotRequired[ToolExecutionEntryObject]
20
21
  type: NotRequired[ToolExecutionEntryType]
21
22
  created_at: NotRequired[datetime]
@@ -27,6 +28,8 @@ class ToolExecutionEntryTypedDict(TypedDict):
27
28
  class ToolExecutionEntry(BaseModel):
28
29
  name: BuiltInConnectors
29
30
 
31
+ arguments: str
32
+
30
33
  object: Optional[ToolExecutionEntryObject] = "entry"
31
34
 
32
35
  type: Optional[ToolExecutionEntryType] = "tool.execution"
@@ -49,7 +52,7 @@ class ToolExecutionEntry(BaseModel):
49
52
 
50
53
  m = {}
51
54
 
52
- for n, f in self.model_fields.items():
55
+ for n, f in type(self).model_fields.items():
53
56
  k = f.alias or n
54
57
  val = serialized.get(k)
55
58
  serialized.pop(k, None)
@@ -14,6 +14,7 @@ ToolExecutionStartedEventType = Literal["tool.execution.started"]
14
14
  class ToolExecutionStartedEventTypedDict(TypedDict):
15
15
  id: str
16
16
  name: BuiltInConnectors
17
+ arguments: str
17
18
  type: NotRequired[ToolExecutionStartedEventType]
18
19
  created_at: NotRequired[datetime]
19
20
  output_index: NotRequired[int]
@@ -24,6 +25,8 @@ class ToolExecutionStartedEvent(BaseModel):
24
25
 
25
26
  name: BuiltInConnectors
26
27
 
28
+ arguments: str
29
+
27
30
  type: Optional[ToolExecutionStartedEventType] = "tool.execution.started"
28
31
 
29
32
  created_at: Optional[datetime] = None
@@ -40,7 +40,7 @@ class ToolFileChunk(BaseModel):
40
40
 
41
41
  m = {}
42
42
 
43
- for n, f in self.model_fields.items():
43
+ for n, f in type(self).model_fields.items():
44
44
  k = f.alias or n
45
45
  val = serialized.get(k)
46
46
  serialized.pop(k, None)
@@ -45,7 +45,7 @@ class ToolMessage(BaseModel):
45
45
 
46
46
  m = {}
47
47
 
48
- for n, f in self.model_fields.items():
48
+ for n, f in type(self).model_fields.items():
49
49
  k = f.alias or n
50
50
  val = serialized.get(k)
51
51
  serialized.pop(k, None)
@@ -16,7 +16,8 @@ class ToolReferenceChunkTypedDict(TypedDict):
16
16
  title: str
17
17
  type: NotRequired[ToolReferenceChunkType]
18
18
  url: NotRequired[Nullable[str]]
19
- source: NotRequired[Nullable[str]]
19
+ favicon: NotRequired[Nullable[str]]
20
+ description: NotRequired[Nullable[str]]
20
21
 
21
22
 
22
23
  class ToolReferenceChunk(BaseModel):
@@ -28,19 +29,21 @@ class ToolReferenceChunk(BaseModel):
28
29
 
29
30
  url: OptionalNullable[str] = UNSET
30
31
 
31
- source: OptionalNullable[str] = UNSET
32
+ favicon: OptionalNullable[str] = UNSET
33
+
34
+ description: OptionalNullable[str] = UNSET
32
35
 
33
36
  @model_serializer(mode="wrap")
34
37
  def serialize_model(self, handler):
35
- optional_fields = ["type", "url", "source"]
36
- nullable_fields = ["url", "source"]
38
+ optional_fields = ["type", "url", "favicon", "description"]
39
+ nullable_fields = ["url", "favicon", "description"]
37
40
  null_default_fields = []
38
41
 
39
42
  serialized = handler(self)
40
43
 
41
44
  m = {}
42
45
 
43
- for n, f in self.model_fields.items():
46
+ for n, f in type(self).model_fields.items():
44
47
  k = f.alias or n
45
48
  val = serialized.get(k)
46
49
  serialized.pop(k, None)
@@ -26,7 +26,7 @@ class UpdateFTModelIn(BaseModel):
26
26
 
27
27
  m = {}
28
28
 
29
- for n, f in self.model_fields.items():
29
+ for n, f in type(self).model_fields.items():
30
30
  k = f.alias or n
31
31
  val = serialized.get(k)
32
32
  serialized.pop(k, None)
@@ -63,7 +63,7 @@ class UploadFileOut(BaseModel):
63
63
 
64
64
  m = {}
65
65
 
66
- for n, f in self.model_fields.items():
66
+ for n, f in type(self).model_fields.items():
67
67
  k = f.alias or n
68
68
  val = serialized.get(k)
69
69
  serialized.pop(k, None)
@@ -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)
@@ -45,7 +45,7 @@ class WandbIntegration(BaseModel):
45
45
 
46
46
  m = {}
47
47
 
48
- for n, f in self.model_fields.items():
48
+ for n, f in type(self).model_fields.items():
49
49
  k = f.alias or n
50
50
  val = serialized.get(k)
51
51
  serialized.pop(k, None)
@@ -43,7 +43,7 @@ class WandbIntegrationOut(BaseModel):
43
43
 
44
44
  m = {}
45
45
 
46
- for n, f in self.model_fields.items():
46
+ for n, f in type(self).model_fields.items():
47
47
  k = f.alias or n
48
48
  val = serialized.get(k)
49
49
  serialized.pop(k, None)
mistralai/models_.py CHANGED
@@ -63,6 +63,7 @@ class Models(BaseSDK):
63
63
 
64
64
  http_res = self.do_request(
65
65
  hook_ctx=HookContext(
66
+ config=self.sdk_configuration,
66
67
  base_url=base_url or "",
67
68
  operation_id="list_models_v1_models_get",
68
69
  oauth2_scopes=[],
@@ -155,6 +156,7 @@ class Models(BaseSDK):
155
156
 
156
157
  http_res = await self.do_request_async(
157
158
  hook_ctx=HookContext(
159
+ config=self.sdk_configuration,
158
160
  base_url=base_url or "",
159
161
  operation_id="list_models_v1_models_get",
160
162
  oauth2_scopes=[],
@@ -206,7 +208,7 @@ class Models(BaseSDK):
206
208
  ) -> models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet:
207
209
  r"""Retrieve Model
208
210
 
209
- Retrieve a model information.
211
+ Retrieve information about a model.
210
212
 
211
213
  :param model_id: The ID of the model to retrieve.
212
214
  :param retries: Override the default retry configuration for this method
@@ -254,6 +256,7 @@ class Models(BaseSDK):
254
256
 
255
257
  http_res = self.do_request(
256
258
  hook_ctx=HookContext(
259
+ config=self.sdk_configuration,
257
260
  base_url=base_url or "",
258
261
  operation_id="retrieve_model_v1_models__model_id__get",
259
262
  oauth2_scopes=[],
@@ -308,7 +311,7 @@ class Models(BaseSDK):
308
311
  ) -> models.RetrieveModelV1ModelsModelIDGetResponseRetrieveModelV1ModelsModelIDGet:
309
312
  r"""Retrieve Model
310
313
 
311
- Retrieve a model information.
314
+ Retrieve information about a model.
312
315
 
313
316
  :param model_id: The ID of the model to retrieve.
314
317
  :param retries: Override the default retry configuration for this method
@@ -356,6 +359,7 @@ class Models(BaseSDK):
356
359
 
357
360
  http_res = await self.do_request_async(
358
361
  hook_ctx=HookContext(
362
+ config=self.sdk_configuration,
359
363
  base_url=base_url or "",
360
364
  operation_id="retrieve_model_v1_models__model_id__get",
361
365
  oauth2_scopes=[],
@@ -458,6 +462,7 @@ class Models(BaseSDK):
458
462
 
459
463
  http_res = self.do_request(
460
464
  hook_ctx=HookContext(
465
+ config=self.sdk_configuration,
461
466
  base_url=base_url or "",
462
467
  operation_id="delete_model_v1_models__model_id__delete",
463
468
  oauth2_scopes=[],
@@ -557,6 +562,7 @@ class Models(BaseSDK):
557
562
 
558
563
  http_res = await self.do_request_async(
559
564
  hook_ctx=HookContext(
565
+ config=self.sdk_configuration,
560
566
  base_url=base_url or "",
561
567
  operation_id="delete_model_v1_models__model_id__delete",
562
568
  oauth2_scopes=[],
@@ -667,6 +673,7 @@ class Models(BaseSDK):
667
673
 
668
674
  http_res = self.do_request(
669
675
  hook_ctx=HookContext(
676
+ config=self.sdk_configuration,
670
677
  base_url=base_url or "",
671
678
  operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
672
679
  oauth2_scopes=[],
@@ -774,6 +781,7 @@ class Models(BaseSDK):
774
781
 
775
782
  http_res = await self.do_request_async(
776
783
  hook_ctx=HookContext(
784
+ config=self.sdk_configuration,
777
785
  base_url=base_url or "",
778
786
  operation_id="jobs_api_routes_fine_tuning_update_fine_tuned_model",
779
787
  oauth2_scopes=[],
@@ -870,6 +878,7 @@ class Models(BaseSDK):
870
878
 
871
879
  http_res = self.do_request(
872
880
  hook_ctx=HookContext(
881
+ config=self.sdk_configuration,
873
882
  base_url=base_url or "",
874
883
  operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
875
884
  oauth2_scopes=[],
@@ -963,6 +972,7 @@ class Models(BaseSDK):
963
972
 
964
973
  http_res = await self.do_request_async(
965
974
  hook_ctx=HookContext(
975
+ config=self.sdk_configuration,
966
976
  base_url=base_url or "",
967
977
  operation_id="jobs_api_routes_fine_tuning_archive_fine_tuned_model",
968
978
  oauth2_scopes=[],
@@ -1056,6 +1066,7 @@ class Models(BaseSDK):
1056
1066
 
1057
1067
  http_res = self.do_request(
1058
1068
  hook_ctx=HookContext(
1069
+ config=self.sdk_configuration,
1059
1070
  base_url=base_url or "",
1060
1071
  operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
1061
1072
  oauth2_scopes=[],
@@ -1149,6 +1160,7 @@ class Models(BaseSDK):
1149
1160
 
1150
1161
  http_res = await self.do_request_async(
1151
1162
  hook_ctx=HookContext(
1163
+ config=self.sdk_configuration,
1152
1164
  base_url=base_url or "",
1153
1165
  operation_id="jobs_api_routes_fine_tuning_unarchive_fine_tuned_model",
1154
1166
  oauth2_scopes=[],
mistralai/ocr.py CHANGED
@@ -103,6 +103,7 @@ class Ocr(BaseSDK):
103
103
 
104
104
  http_res = self.do_request(
105
105
  hook_ctx=HookContext(
106
+ config=self.sdk_configuration,
106
107
  base_url=base_url or "",
107
108
  operation_id="ocr_v1_ocr_post",
108
109
  oauth2_scopes=[],
@@ -235,6 +236,7 @@ class Ocr(BaseSDK):
235
236
 
236
237
  http_res = await self.do_request_async(
237
238
  hook_ctx=HookContext(
239
+ config=self.sdk_configuration,
238
240
  base_url=base_url or "",
239
241
  operation_id="ocr_v1_ocr_post",
240
242
  oauth2_scopes=[],
mistralai/sdk.py CHANGED
@@ -6,46 +6,62 @@ from .sdkconfiguration import SDKConfiguration
6
6
  from .utils.logger import Logger, get_default_logger
7
7
  from .utils.retries import RetryConfig
8
8
  import httpx
9
+ import importlib
9
10
  from mistralai import models, utils
10
11
  from mistralai._hooks import SDKHooks
11
- from mistralai.agents import Agents
12
- from mistralai.batch import Batch
13
- from mistralai.beta import Beta
14
- from mistralai.chat import Chat
15
- from mistralai.classifiers import Classifiers
16
- from mistralai.embeddings import Embeddings
17
- from mistralai.files import Files
18
- from mistralai.fim import Fim
19
- from mistralai.fine_tuning import FineTuning
20
- from mistralai.models_ import Models
21
- from mistralai.ocr import Ocr
22
12
  from mistralai.types import OptionalNullable, UNSET
23
- from typing import Any, Callable, Dict, Optional, Union, cast
13
+ from typing import Any, Callable, Dict, Optional, TYPE_CHECKING, Union, cast
24
14
  import weakref
25
15
 
16
+ if TYPE_CHECKING:
17
+ from mistralai.agents import Agents
18
+ from mistralai.batch import Batch
19
+ from mistralai.beta import Beta
20
+ from mistralai.chat import Chat
21
+ from mistralai.classifiers import Classifiers
22
+ from mistralai.embeddings import Embeddings
23
+ from mistralai.files import Files
24
+ from mistralai.fim import Fim
25
+ from mistralai.fine_tuning import FineTuning
26
+ from mistralai.models_ import Models
27
+ from mistralai.ocr import Ocr
28
+
26
29
 
27
30
  class Mistral(BaseSDK):
28
31
  r"""Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it."""
29
32
 
30
- models: Models
33
+ models: "Models"
31
34
  r"""Model Management API"""
32
- beta: Beta
33
- files: Files
35
+ beta: "Beta"
36
+ files: "Files"
34
37
  r"""Files API"""
35
- fine_tuning: FineTuning
36
- batch: Batch
37
- chat: Chat
38
+ fine_tuning: "FineTuning"
39
+ batch: "Batch"
40
+ chat: "Chat"
38
41
  r"""Chat Completion API."""
39
- fim: Fim
42
+ fim: "Fim"
40
43
  r"""Fill-in-the-middle API."""
41
- agents: Agents
44
+ agents: "Agents"
42
45
  r"""Agents API."""
43
- embeddings: Embeddings
46
+ embeddings: "Embeddings"
44
47
  r"""Embeddings API."""
45
- classifiers: Classifiers
48
+ classifiers: "Classifiers"
46
49
  r"""Classifiers API."""
47
- ocr: Ocr
50
+ ocr: "Ocr"
48
51
  r"""OCR API"""
52
+ _sub_sdk_map = {
53
+ "models": ("mistralai.models_", "Models"),
54
+ "beta": ("mistralai.beta", "Beta"),
55
+ "files": ("mistralai.files", "Files"),
56
+ "fine_tuning": ("mistralai.fine_tuning", "FineTuning"),
57
+ "batch": ("mistralai.batch", "Batch"),
58
+ "chat": ("mistralai.chat", "Chat"),
59
+ "fim": ("mistralai.fim", "Fim"),
60
+ "agents": ("mistralai.agents", "Agents"),
61
+ "embeddings": ("mistralai.embeddings", "Embeddings"),
62
+ "classifiers": ("mistralai.classifiers", "Classifiers"),
63
+ "ocr": ("mistralai.ocr", "Ocr"),
64
+ }
49
65
 
50
66
  def __init__(
51
67
  self,
@@ -120,6 +136,9 @@ class Mistral(BaseSDK):
120
136
 
121
137
  hooks = SDKHooks()
122
138
 
139
+ # pylint: disable=protected-access
140
+ self.sdk_configuration.__dict__["_hooks"] = hooks
141
+
123
142
  current_server_url, *_ = self.sdk_configuration.get_server_details()
124
143
  server_url, self.sdk_configuration.client = hooks.sdk_init(
125
144
  current_server_url, client
@@ -127,9 +146,6 @@ class Mistral(BaseSDK):
127
146
  if current_server_url != server_url:
128
147
  self.sdk_configuration.server_url = server_url
129
148
 
130
- # pylint: disable=protected-access
131
- self.sdk_configuration.__dict__["_hooks"] = hooks
132
-
133
149
  weakref.finalize(
134
150
  self,
135
151
  close_clients,
@@ -140,20 +156,32 @@ class Mistral(BaseSDK):
140
156
  self.sdk_configuration.async_client_supplied,
141
157
  )
142
158
 
143
- self._init_sdks()
144
-
145
- def _init_sdks(self):
146
- self.models = Models(self.sdk_configuration)
147
- self.beta = Beta(self.sdk_configuration)
148
- self.files = Files(self.sdk_configuration)
149
- self.fine_tuning = FineTuning(self.sdk_configuration)
150
- self.batch = Batch(self.sdk_configuration)
151
- self.chat = Chat(self.sdk_configuration)
152
- self.fim = Fim(self.sdk_configuration)
153
- self.agents = Agents(self.sdk_configuration)
154
- self.embeddings = Embeddings(self.sdk_configuration)
155
- self.classifiers = Classifiers(self.sdk_configuration)
156
- self.ocr = Ocr(self.sdk_configuration)
159
+ def __getattr__(self, name: str):
160
+ if name in self._sub_sdk_map:
161
+ module_path, class_name = self._sub_sdk_map[name]
162
+ try:
163
+ module = importlib.import_module(module_path)
164
+ klass = getattr(module, class_name)
165
+ instance = klass(self.sdk_configuration)
166
+ setattr(self, name, instance)
167
+ return instance
168
+ except ImportError as e:
169
+ raise AttributeError(
170
+ f"Failed to import module {module_path} for attribute {name}: {e}"
171
+ ) from e
172
+ except AttributeError as e:
173
+ raise AttributeError(
174
+ f"Failed to find class {class_name} in module {module_path} for attribute {name}: {e}"
175
+ ) from e
176
+
177
+ raise AttributeError(
178
+ f"'{type(self).__name__}' object has no attribute '{name}'"
179
+ )
180
+
181
+ def __dir__(self):
182
+ default_attrs = list(super().__dir__())
183
+ lazy_attrs = list(self._sub_sdk_map.keys())
184
+ return sorted(list(set(default_attrs + lazy_attrs)))
157
185
 
158
186
  def __enter__(self):
159
187
  return self
@@ -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