mistralai 1.0.3__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. mistralai/__init__.py +4 -0
  2. mistralai/_hooks/sdkhooks.py +23 -4
  3. mistralai/_hooks/types.py +27 -9
  4. mistralai/_version.py +12 -0
  5. mistralai/agents.py +334 -164
  6. mistralai/basesdk.py +90 -5
  7. mistralai/batch.py +17 -0
  8. mistralai/chat.py +316 -166
  9. mistralai/classifiers.py +396 -0
  10. mistralai/embeddings.py +79 -55
  11. mistralai/files.py +487 -194
  12. mistralai/fim.py +206 -132
  13. mistralai/fine_tuning.py +3 -2
  14. mistralai/jobs.py +392 -263
  15. mistralai/mistral_jobs.py +733 -0
  16. mistralai/models/__init__.py +593 -50
  17. mistralai/models/agentscompletionrequest.py +70 -17
  18. mistralai/models/agentscompletionstreamrequest.py +72 -17
  19. mistralai/models/apiendpoint.py +9 -0
  20. mistralai/models/archiveftmodelout.py +15 -5
  21. mistralai/models/assistantmessage.py +22 -10
  22. mistralai/models/{modelcard.py → basemodelcard.py} +53 -14
  23. mistralai/models/batcherror.py +17 -0
  24. mistralai/models/batchjobin.py +58 -0
  25. mistralai/models/batchjobout.py +117 -0
  26. mistralai/models/batchjobsout.py +30 -0
  27. mistralai/models/batchjobstatus.py +15 -0
  28. mistralai/models/chatclassificationrequest.py +104 -0
  29. mistralai/models/chatcompletionchoice.py +13 -6
  30. mistralai/models/chatcompletionrequest.py +86 -21
  31. mistralai/models/chatcompletionresponse.py +8 -4
  32. mistralai/models/chatcompletionstreamrequest.py +88 -21
  33. mistralai/models/checkpointout.py +4 -3
  34. mistralai/models/classificationobject.py +21 -0
  35. mistralai/models/classificationrequest.py +59 -0
  36. mistralai/models/classificationresponse.py +21 -0
  37. mistralai/models/completionchunk.py +12 -5
  38. mistralai/models/completionevent.py +2 -3
  39. mistralai/models/completionresponsestreamchoice.py +22 -8
  40. mistralai/models/contentchunk.py +13 -10
  41. mistralai/models/delete_model_v1_models_model_id_deleteop.py +5 -5
  42. mistralai/models/deletefileout.py +4 -3
  43. mistralai/models/deletemodelout.py +5 -4
  44. mistralai/models/deltamessage.py +23 -11
  45. mistralai/models/detailedjobout.py +70 -12
  46. mistralai/models/embeddingrequest.py +14 -9
  47. mistralai/models/embeddingresponse.py +7 -3
  48. mistralai/models/embeddingresponsedata.py +5 -4
  49. mistralai/models/eventout.py +11 -6
  50. mistralai/models/filepurpose.py +8 -0
  51. mistralai/models/files_api_routes_delete_fileop.py +5 -5
  52. mistralai/models/files_api_routes_download_fileop.py +16 -0
  53. mistralai/models/files_api_routes_list_filesop.py +96 -0
  54. mistralai/models/files_api_routes_retrieve_fileop.py +5 -5
  55. mistralai/models/files_api_routes_upload_fileop.py +33 -14
  56. mistralai/models/fileschema.py +22 -15
  57. mistralai/models/fimcompletionrequest.py +44 -16
  58. mistralai/models/fimcompletionresponse.py +8 -4
  59. mistralai/models/fimcompletionstreamrequest.py +44 -16
  60. mistralai/models/finetuneablemodel.py +7 -1
  61. mistralai/models/ftmodelcapabilitiesout.py +6 -4
  62. mistralai/models/ftmodelcard.py +121 -0
  63. mistralai/models/ftmodelout.py +39 -9
  64. mistralai/models/function.py +5 -4
  65. mistralai/models/functioncall.py +4 -3
  66. mistralai/models/functionname.py +17 -0
  67. mistralai/models/githubrepositoryin.py +24 -7
  68. mistralai/models/githubrepositoryout.py +24 -7
  69. mistralai/models/httpvalidationerror.py +1 -3
  70. mistralai/models/imageurl.py +47 -0
  71. mistralai/models/imageurlchunk.py +38 -0
  72. mistralai/models/jobin.py +24 -7
  73. mistralai/models/jobmetadataout.py +32 -8
  74. mistralai/models/jobout.py +65 -12
  75. mistralai/models/jobs_api_routes_batch_cancel_batch_jobop.py +16 -0
  76. mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +16 -0
  77. mistralai/models/jobs_api_routes_batch_get_batch_jobsop.py +95 -0
  78. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +5 -5
  79. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +5 -5
  80. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
  81. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +5 -5
  82. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +85 -18
  83. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +5 -5
  84. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +5 -5
  85. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +10 -6
  86. mistralai/models/jobsout.py +13 -5
  87. mistralai/models/legacyjobmetadataout.py +55 -9
  88. mistralai/models/listfilesout.py +7 -3
  89. mistralai/models/metricout.py +12 -8
  90. mistralai/models/modelcapabilities.py +9 -4
  91. mistralai/models/modellist.py +21 -7
  92. mistralai/models/responseformat.py +7 -8
  93. mistralai/models/responseformats.py +8 -0
  94. mistralai/models/retrieve_model_v1_models_model_id_getop.py +25 -6
  95. mistralai/models/retrievefileout.py +25 -15
  96. mistralai/models/sampletype.py +6 -2
  97. mistralai/models/security.py +14 -5
  98. mistralai/models/source.py +3 -2
  99. mistralai/models/systemmessage.py +10 -9
  100. mistralai/models/textchunk.py +14 -5
  101. mistralai/models/tool.py +10 -9
  102. mistralai/models/toolcall.py +10 -8
  103. mistralai/models/toolchoice.py +29 -0
  104. mistralai/models/toolchoiceenum.py +7 -0
  105. mistralai/models/toolmessage.py +13 -6
  106. mistralai/models/tooltypes.py +8 -0
  107. mistralai/models/trainingfile.py +4 -4
  108. mistralai/models/trainingparameters.py +34 -8
  109. mistralai/models/trainingparametersin.py +36 -10
  110. mistralai/models/unarchiveftmodelout.py +15 -5
  111. mistralai/models/updateftmodelin.py +9 -6
  112. mistralai/models/uploadfileout.py +22 -15
  113. mistralai/models/usageinfo.py +4 -3
  114. mistralai/models/usermessage.py +42 -10
  115. mistralai/models/validationerror.py +5 -3
  116. mistralai/models/wandbintegration.py +23 -7
  117. mistralai/models/wandbintegrationout.py +23 -8
  118. mistralai/models_.py +416 -294
  119. mistralai/sdk.py +31 -19
  120. mistralai/sdkconfiguration.py +9 -11
  121. mistralai/utils/__init__.py +14 -1
  122. mistralai/utils/annotations.py +13 -2
  123. mistralai/utils/logger.py +4 -1
  124. mistralai/utils/retries.py +2 -1
  125. mistralai/utils/security.py +13 -6
  126. mistralai/utils/serializers.py +25 -0
  127. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/METADATA +171 -66
  128. mistralai-1.2.0.dist-info/RECORD +276 -0
  129. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/WHEEL +1 -1
  130. mistralai_azure/__init__.py +4 -0
  131. mistralai_azure/_hooks/sdkhooks.py +23 -4
  132. mistralai_azure/_hooks/types.py +27 -9
  133. mistralai_azure/_version.py +12 -0
  134. mistralai_azure/basesdk.py +91 -6
  135. mistralai_azure/chat.py +308 -166
  136. mistralai_azure/models/__init__.py +164 -16
  137. mistralai_azure/models/assistantmessage.py +29 -11
  138. mistralai_azure/models/chatcompletionchoice.py +15 -6
  139. mistralai_azure/models/chatcompletionrequest.py +94 -22
  140. mistralai_azure/models/chatcompletionresponse.py +8 -4
  141. mistralai_azure/models/chatcompletionstreamrequest.py +96 -22
  142. mistralai_azure/models/completionchunk.py +12 -5
  143. mistralai_azure/models/completionevent.py +2 -3
  144. mistralai_azure/models/completionresponsestreamchoice.py +19 -8
  145. mistralai_azure/models/contentchunk.py +4 -11
  146. mistralai_azure/models/deltamessage.py +30 -12
  147. mistralai_azure/models/function.py +5 -4
  148. mistralai_azure/models/functioncall.py +4 -3
  149. mistralai_azure/models/functionname.py +17 -0
  150. mistralai_azure/models/httpvalidationerror.py +1 -3
  151. mistralai_azure/models/responseformat.py +7 -8
  152. mistralai_azure/models/responseformats.py +8 -0
  153. mistralai_azure/models/security.py +13 -5
  154. mistralai_azure/models/systemmessage.py +10 -9
  155. mistralai_azure/models/textchunk.py +14 -5
  156. mistralai_azure/models/tool.py +10 -9
  157. mistralai_azure/models/toolcall.py +10 -8
  158. mistralai_azure/models/toolchoice.py +29 -0
  159. mistralai_azure/models/toolchoiceenum.py +7 -0
  160. mistralai_azure/models/toolmessage.py +20 -7
  161. mistralai_azure/models/tooltypes.py +8 -0
  162. mistralai_azure/models/usageinfo.py +4 -3
  163. mistralai_azure/models/usermessage.py +42 -10
  164. mistralai_azure/models/validationerror.py +5 -3
  165. mistralai_azure/sdkconfiguration.py +9 -11
  166. mistralai_azure/utils/__init__.py +16 -3
  167. mistralai_azure/utils/annotations.py +13 -2
  168. mistralai_azure/utils/forms.py +10 -9
  169. mistralai_azure/utils/headers.py +8 -8
  170. mistralai_azure/utils/logger.py +6 -0
  171. mistralai_azure/utils/queryparams.py +16 -14
  172. mistralai_azure/utils/retries.py +2 -1
  173. mistralai_azure/utils/security.py +12 -6
  174. mistralai_azure/utils/serializers.py +42 -8
  175. mistralai_azure/utils/url.py +13 -8
  176. mistralai_azure/utils/values.py +6 -0
  177. mistralai_gcp/__init__.py +4 -0
  178. mistralai_gcp/_hooks/sdkhooks.py +23 -4
  179. mistralai_gcp/_hooks/types.py +27 -9
  180. mistralai_gcp/_version.py +12 -0
  181. mistralai_gcp/basesdk.py +91 -6
  182. mistralai_gcp/chat.py +308 -166
  183. mistralai_gcp/fim.py +198 -132
  184. mistralai_gcp/models/__init__.py +186 -18
  185. mistralai_gcp/models/assistantmessage.py +29 -11
  186. mistralai_gcp/models/chatcompletionchoice.py +15 -6
  187. mistralai_gcp/models/chatcompletionrequest.py +91 -22
  188. mistralai_gcp/models/chatcompletionresponse.py +8 -4
  189. mistralai_gcp/models/chatcompletionstreamrequest.py +93 -22
  190. mistralai_gcp/models/completionchunk.py +12 -5
  191. mistralai_gcp/models/completionevent.py +2 -3
  192. mistralai_gcp/models/completionresponsestreamchoice.py +19 -8
  193. mistralai_gcp/models/contentchunk.py +4 -11
  194. mistralai_gcp/models/deltamessage.py +30 -12
  195. mistralai_gcp/models/fimcompletionrequest.py +51 -17
  196. mistralai_gcp/models/fimcompletionresponse.py +8 -4
  197. mistralai_gcp/models/fimcompletionstreamrequest.py +51 -17
  198. mistralai_gcp/models/function.py +5 -4
  199. mistralai_gcp/models/functioncall.py +4 -3
  200. mistralai_gcp/models/functionname.py +17 -0
  201. mistralai_gcp/models/httpvalidationerror.py +1 -3
  202. mistralai_gcp/models/responseformat.py +7 -8
  203. mistralai_gcp/models/responseformats.py +8 -0
  204. mistralai_gcp/models/security.py +13 -5
  205. mistralai_gcp/models/systemmessage.py +10 -9
  206. mistralai_gcp/models/textchunk.py +14 -5
  207. mistralai_gcp/models/tool.py +10 -9
  208. mistralai_gcp/models/toolcall.py +10 -8
  209. mistralai_gcp/models/toolchoice.py +29 -0
  210. mistralai_gcp/models/toolchoiceenum.py +7 -0
  211. mistralai_gcp/models/toolmessage.py +20 -7
  212. mistralai_gcp/models/tooltypes.py +8 -0
  213. mistralai_gcp/models/usageinfo.py +4 -3
  214. mistralai_gcp/models/usermessage.py +42 -10
  215. mistralai_gcp/models/validationerror.py +5 -3
  216. mistralai_gcp/sdk.py +6 -7
  217. mistralai_gcp/sdkconfiguration.py +9 -11
  218. mistralai_gcp/utils/__init__.py +16 -3
  219. mistralai_gcp/utils/annotations.py +13 -2
  220. mistralai_gcp/utils/forms.py +10 -9
  221. mistralai_gcp/utils/headers.py +8 -8
  222. mistralai_gcp/utils/logger.py +6 -0
  223. mistralai_gcp/utils/queryparams.py +16 -14
  224. mistralai_gcp/utils/retries.py +2 -1
  225. mistralai_gcp/utils/security.py +12 -6
  226. mistralai_gcp/utils/serializers.py +42 -8
  227. mistralai_gcp/utils/url.py +13 -8
  228. mistralai_gcp/utils/values.py +6 -0
  229. mistralai-1.0.3.dist-info/RECORD +0 -236
  230. {mistralai-1.0.3.dist-info → mistralai-1.2.0.dist-info}/LICENSE +0 -0
@@ -0,0 +1,117 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .batcherror import BatchError, BatchErrorTypedDict
5
+ from .batchjobstatus import BatchJobStatus
6
+ from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
7
+ from mistralai.utils import validate_const
8
+ import pydantic
9
+ from pydantic import model_serializer
10
+ from pydantic.functional_validators import AfterValidator
11
+ from typing import Any, Dict, List, Literal, Optional
12
+ from typing_extensions import Annotated, NotRequired, TypedDict
13
+
14
+
15
+ BatchJobOutObject = Literal["batch"]
16
+
17
+
18
+ class BatchJobOutTypedDict(TypedDict):
19
+ id: str
20
+ input_files: List[str]
21
+ endpoint: str
22
+ model: str
23
+ errors: List[BatchErrorTypedDict]
24
+ status: BatchJobStatus
25
+ created_at: int
26
+ total_requests: int
27
+ completed_requests: int
28
+ succeeded_requests: int
29
+ failed_requests: int
30
+ object: BatchJobOutObject
31
+ metadata: NotRequired[Nullable[Dict[str, Any]]]
32
+ output_file: NotRequired[Nullable[str]]
33
+ error_file: NotRequired[Nullable[str]]
34
+ started_at: NotRequired[Nullable[int]]
35
+ completed_at: NotRequired[Nullable[int]]
36
+
37
+
38
+ class BatchJobOut(BaseModel):
39
+ id: str
40
+
41
+ input_files: List[str]
42
+
43
+ endpoint: str
44
+
45
+ model: str
46
+
47
+ errors: List[BatchError]
48
+
49
+ status: BatchJobStatus
50
+
51
+ created_at: int
52
+
53
+ total_requests: int
54
+
55
+ completed_requests: int
56
+
57
+ succeeded_requests: int
58
+
59
+ failed_requests: int
60
+
61
+ OBJECT: Annotated[
62
+ Annotated[Optional[BatchJobOutObject], AfterValidator(validate_const("batch"))],
63
+ pydantic.Field(alias="object"),
64
+ ] = "batch"
65
+
66
+ metadata: OptionalNullable[Dict[str, Any]] = UNSET
67
+
68
+ output_file: OptionalNullable[str] = UNSET
69
+
70
+ error_file: OptionalNullable[str] = UNSET
71
+
72
+ started_at: OptionalNullable[int] = UNSET
73
+
74
+ completed_at: OptionalNullable[int] = UNSET
75
+
76
+ @model_serializer(mode="wrap")
77
+ def serialize_model(self, handler):
78
+ optional_fields = [
79
+ "object",
80
+ "metadata",
81
+ "output_file",
82
+ "error_file",
83
+ "started_at",
84
+ "completed_at",
85
+ ]
86
+ nullable_fields = [
87
+ "metadata",
88
+ "output_file",
89
+ "error_file",
90
+ "started_at",
91
+ "completed_at",
92
+ ]
93
+ null_default_fields = []
94
+
95
+ serialized = handler(self)
96
+
97
+ m = {}
98
+
99
+ for n, f in self.model_fields.items():
100
+ k = f.alias or n
101
+ val = serialized.get(k)
102
+ serialized.pop(k, None)
103
+
104
+ optional_nullable = k in optional_fields and k in nullable_fields
105
+ is_set = (
106
+ self.__pydantic_fields_set__.intersection({n})
107
+ or k in null_default_fields
108
+ ) # pylint: disable=no-member
109
+
110
+ if val is not None and val != UNSET_SENTINEL:
111
+ m[k] = val
112
+ elif val != UNSET_SENTINEL and (
113
+ not k in optional_fields or (optional_nullable and is_set)
114
+ ):
115
+ m[k] = val
116
+
117
+ return m
@@ -0,0 +1,30 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .batchjobout import BatchJobOut, BatchJobOutTypedDict
5
+ from mistralai.types import BaseModel
6
+ from mistralai.utils import validate_const
7
+ import pydantic
8
+ from pydantic.functional_validators import AfterValidator
9
+ from typing import List, Literal, Optional
10
+ from typing_extensions import Annotated, NotRequired, TypedDict
11
+
12
+
13
+ BatchJobsOutObject = Literal["list"]
14
+
15
+
16
+ class BatchJobsOutTypedDict(TypedDict):
17
+ total: int
18
+ data: NotRequired[List[BatchJobOutTypedDict]]
19
+ object: BatchJobsOutObject
20
+
21
+
22
+ class BatchJobsOut(BaseModel):
23
+ total: int
24
+
25
+ data: Optional[List[BatchJobOut]] = None
26
+
27
+ OBJECT: Annotated[
28
+ Annotated[Optional[BatchJobsOutObject], AfterValidator(validate_const("list"))],
29
+ pydantic.Field(alias="object"),
30
+ ] = "list"
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Literal
5
+
6
+
7
+ BatchJobStatus = Literal[
8
+ "QUEUED",
9
+ "RUNNING",
10
+ "SUCCESS",
11
+ "FAILED",
12
+ "TIMEOUT_EXCEEDED",
13
+ "CANCELLATION_REQUESTED",
14
+ "CANCELLED",
15
+ ]
@@ -0,0 +1,104 @@
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.types import BaseModel, Nullable, UNSET_SENTINEL
9
+ from mistralai.utils import get_discriminator
10
+ import pydantic
11
+ from pydantic import Discriminator, Tag, model_serializer
12
+ from typing import List, Union
13
+ from typing_extensions import Annotated, TypedDict
14
+
15
+
16
+ TwoTypedDict = Union[
17
+ SystemMessageTypedDict,
18
+ UserMessageTypedDict,
19
+ AssistantMessageTypedDict,
20
+ ToolMessageTypedDict,
21
+ ]
22
+
23
+
24
+ Two = Annotated[
25
+ Union[
26
+ Annotated[AssistantMessage, Tag("assistant")],
27
+ Annotated[SystemMessage, Tag("system")],
28
+ Annotated[ToolMessage, Tag("tool")],
29
+ Annotated[UserMessage, Tag("user")],
30
+ ],
31
+ Discriminator(lambda m: get_discriminator(m, "role", "role")),
32
+ ]
33
+
34
+
35
+ OneTypedDict = Union[
36
+ SystemMessageTypedDict,
37
+ UserMessageTypedDict,
38
+ AssistantMessageTypedDict,
39
+ ToolMessageTypedDict,
40
+ ]
41
+
42
+
43
+ One = Annotated[
44
+ Union[
45
+ Annotated[AssistantMessage, Tag("assistant")],
46
+ Annotated[SystemMessage, Tag("system")],
47
+ Annotated[ToolMessage, Tag("tool")],
48
+ Annotated[UserMessage, Tag("user")],
49
+ ],
50
+ Discriminator(lambda m: get_discriminator(m, "role", "role")),
51
+ ]
52
+
53
+
54
+ ChatClassificationRequestInputsTypedDict = Union[
55
+ List[OneTypedDict], List[List[TwoTypedDict]]
56
+ ]
57
+ r"""Chat to classify"""
58
+
59
+
60
+ ChatClassificationRequestInputs = Union[List[One], List[List[Two]]]
61
+ r"""Chat to classify"""
62
+
63
+
64
+ class ChatClassificationRequestTypedDict(TypedDict):
65
+ inputs: ChatClassificationRequestInputsTypedDict
66
+ r"""Chat to classify"""
67
+ model: Nullable[str]
68
+
69
+
70
+ class ChatClassificationRequest(BaseModel):
71
+ inputs: Annotated[ChatClassificationRequestInputs, pydantic.Field(alias="input")]
72
+ r"""Chat to classify"""
73
+
74
+ model: Nullable[str]
75
+
76
+ @model_serializer(mode="wrap")
77
+ def serialize_model(self, handler):
78
+ optional_fields = []
79
+ nullable_fields = ["model"]
80
+ null_default_fields = []
81
+
82
+ serialized = handler(self)
83
+
84
+ m = {}
85
+
86
+ for n, f in self.model_fields.items():
87
+ k = f.alias or n
88
+ val = serialized.get(k)
89
+ serialized.pop(k, None)
90
+
91
+ optional_nullable = k in optional_fields and k in nullable_fields
92
+ is_set = (
93
+ self.__pydantic_fields_set__.intersection({n})
94
+ or k in null_default_fields
95
+ ) # pylint: disable=no-member
96
+
97
+ if val is not None and val != UNSET_SENTINEL:
98
+ m[k] = val
99
+ elif val != UNSET_SENTINEL and (
100
+ not k in optional_fields or (optional_nullable and is_set)
101
+ ):
102
+ m[k] = val
103
+
104
+ return m
@@ -2,20 +2,27 @@
2
2
 
3
3
  from __future__ import annotations
4
4
  from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
5
- from mistralai.types import BaseModel
6
- from typing import Literal, TypedDict
5
+ from mistralai.types import BaseModel, UnrecognizedStr
6
+ from mistralai.utils import validate_open_enum
7
+ from pydantic.functional_validators import PlainValidator
8
+ from typing import Literal, Union
9
+ from typing_extensions import Annotated, TypedDict
7
10
 
8
11
 
9
- FinishReason = Literal["stop", "length", "model_length", "error", "tool_calls"]
12
+ FinishReason = Union[
13
+ Literal["stop", "length", "model_length", "error", "tool_calls"], UnrecognizedStr
14
+ ]
15
+
10
16
 
11
17
  class ChatCompletionChoiceTypedDict(TypedDict):
12
18
  index: int
13
19
  message: AssistantMessageTypedDict
14
20
  finish_reason: FinishReason
15
-
21
+
16
22
 
17
23
  class ChatCompletionChoice(BaseModel):
18
24
  index: int
25
+
19
26
  message: AssistantMessage
20
- finish_reason: FinishReason
21
-
27
+
28
+ finish_reason: Annotated[FinishReason, PlainValidator(validate_open_enum(False))]
@@ -5,13 +5,15 @@ from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
5
5
  from .responseformat import ResponseFormat, ResponseFormatTypedDict
6
6
  from .systemmessage import SystemMessage, SystemMessageTypedDict
7
7
  from .tool import Tool, ToolTypedDict
8
+ from .toolchoice import ToolChoice, ToolChoiceTypedDict
9
+ from .toolchoiceenum import ToolChoiceEnum
8
10
  from .toolmessage import ToolMessage, ToolMessageTypedDict
9
11
  from .usermessage import UserMessage, UserMessageTypedDict
10
12
  from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
11
13
  from mistralai.utils import get_discriminator
12
14
  from pydantic import Discriminator, Tag, model_serializer
13
- from typing import List, Literal, Optional, TypedDict, Union
14
- from typing_extensions import Annotated, NotRequired
15
+ from typing import List, Optional, Union
16
+ from typing_extensions import Annotated, NotRequired, TypedDict
15
17
 
16
18
 
17
19
  StopTypedDict = Union[str, List[str]]
@@ -22,27 +24,42 @@ Stop = Union[str, List[str]]
22
24
  r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
23
25
 
24
26
 
25
- MessagesTypedDict = Union[SystemMessageTypedDict, UserMessageTypedDict, AssistantMessageTypedDict, ToolMessageTypedDict]
27
+ MessagesTypedDict = Union[
28
+ SystemMessageTypedDict,
29
+ UserMessageTypedDict,
30
+ AssistantMessageTypedDict,
31
+ ToolMessageTypedDict,
32
+ ]
26
33
 
27
34
 
28
- Messages = 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"))]
35
+ Messages = Annotated[
36
+ Union[
37
+ Annotated[AssistantMessage, Tag("assistant")],
38
+ Annotated[SystemMessage, Tag("system")],
39
+ Annotated[ToolMessage, Tag("tool")],
40
+ Annotated[UserMessage, Tag("user")],
41
+ ],
42
+ Discriminator(lambda m: get_discriminator(m, "role", "role")),
43
+ ]
29
44
 
30
45
 
31
- ToolChoice = Literal["auto", "none", "any"]
46
+ ChatCompletionRequestToolChoiceTypedDict = Union[ToolChoiceTypedDict, ToolChoiceEnum]
47
+
48
+
49
+ ChatCompletionRequestToolChoice = Union[ToolChoice, ToolChoiceEnum]
50
+
32
51
 
33
52
  class ChatCompletionRequestTypedDict(TypedDict):
34
53
  model: Nullable[str]
35
54
  r"""ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions."""
36
55
  messages: List[MessagesTypedDict]
37
56
  r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
38
- temperature: NotRequired[float]
39
- r"""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."""
57
+ temperature: NotRequired[Nullable[float]]
58
+ r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 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. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value."""
40
59
  top_p: NotRequired[float]
41
60
  r"""Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both."""
42
61
  max_tokens: NotRequired[Nullable[int]]
43
62
  r"""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."""
44
- min_tokens: NotRequired[Nullable[int]]
45
- r"""The minimum number of tokens to generate in the completion."""
46
63
  stream: NotRequired[bool]
47
64
  r"""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."""
48
65
  stop: NotRequired[StopTypedDict]
@@ -51,40 +68,85 @@ class ChatCompletionRequestTypedDict(TypedDict):
51
68
  r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
52
69
  response_format: NotRequired[ResponseFormatTypedDict]
53
70
  tools: NotRequired[Nullable[List[ToolTypedDict]]]
54
- tool_choice: NotRequired[ToolChoice]
71
+ tool_choice: NotRequired[ChatCompletionRequestToolChoiceTypedDict]
72
+ presence_penalty: NotRequired[float]
73
+ r"""presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative."""
74
+ frequency_penalty: NotRequired[float]
75
+ r"""frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition."""
76
+ n: NotRequired[Nullable[int]]
77
+ r"""Number of completions to return for each request, input tokens are only billed once."""
55
78
  safe_prompt: NotRequired[bool]
56
79
  r"""Whether to inject a safety prompt before all conversations."""
57
-
80
+
58
81
 
59
82
  class ChatCompletionRequest(BaseModel):
60
83
  model: Nullable[str]
61
84
  r"""ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions."""
85
+
62
86
  messages: List[Messages]
63
87
  r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
64
- temperature: Optional[float] = 0.7
65
- r"""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."""
88
+
89
+ temperature: OptionalNullable[float] = UNSET
90
+ r"""What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 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. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value."""
91
+
66
92
  top_p: Optional[float] = 1
67
93
  r"""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."""
94
+
68
95
  max_tokens: OptionalNullable[int] = UNSET
69
96
  r"""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."""
70
- min_tokens: OptionalNullable[int] = UNSET
71
- r"""The minimum number of tokens to generate in the completion."""
97
+
72
98
  stream: Optional[bool] = False
73
99
  r"""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."""
100
+
74
101
  stop: Optional[Stop] = None
75
102
  r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
103
+
76
104
  random_seed: OptionalNullable[int] = UNSET
77
105
  r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
106
+
78
107
  response_format: Optional[ResponseFormat] = None
108
+
79
109
  tools: OptionalNullable[List[Tool]] = UNSET
80
- tool_choice: Optional[ToolChoice] = "auto"
110
+
111
+ tool_choice: Optional[ChatCompletionRequestToolChoice] = None
112
+
113
+ presence_penalty: Optional[float] = 0
114
+ r"""presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative."""
115
+
116
+ frequency_penalty: Optional[float] = 0
117
+ r"""frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition."""
118
+
119
+ n: OptionalNullable[int] = UNSET
120
+ r"""Number of completions to return for each request, input tokens are only billed once."""
121
+
81
122
  safe_prompt: Optional[bool] = False
82
123
  r"""Whether to inject a safety prompt before all conversations."""
83
-
124
+
84
125
  @model_serializer(mode="wrap")
85
126
  def serialize_model(self, handler):
86
- optional_fields = ["temperature", "top_p", "max_tokens", "min_tokens", "stream", "stop", "random_seed", "response_format", "tools", "tool_choice", "safe_prompt"]
87
- nullable_fields = ["model", "max_tokens", "min_tokens", "random_seed", "tools"]
127
+ optional_fields = [
128
+ "temperature",
129
+ "top_p",
130
+ "max_tokens",
131
+ "stream",
132
+ "stop",
133
+ "random_seed",
134
+ "response_format",
135
+ "tools",
136
+ "tool_choice",
137
+ "presence_penalty",
138
+ "frequency_penalty",
139
+ "n",
140
+ "safe_prompt",
141
+ ]
142
+ nullable_fields = [
143
+ "model",
144
+ "temperature",
145
+ "max_tokens",
146
+ "random_seed",
147
+ "tools",
148
+ "n",
149
+ ]
88
150
  null_default_fields = []
89
151
 
90
152
  serialized = handler(self)
@@ -94,9 +156,13 @@ class ChatCompletionRequest(BaseModel):
94
156
  for n, f in self.model_fields.items():
95
157
  k = f.alias or n
96
158
  val = serialized.get(k)
159
+ serialized.pop(k, None)
97
160
 
98
161
  optional_nullable = k in optional_fields and k in nullable_fields
99
- is_set = (self.__pydantic_fields_set__.intersection({n}) or k in null_default_fields) # pylint: disable=no-member
162
+ is_set = (
163
+ self.__pydantic_fields_set__.intersection({n})
164
+ or k in null_default_fields
165
+ ) # pylint: disable=no-member
100
166
 
101
167
  if val is not None and val != UNSET_SENTINEL:
102
168
  m[k] = val
@@ -106,4 +172,3 @@ class ChatCompletionRequest(BaseModel):
106
172
  m[k] = val
107
173
 
108
174
  return m
109
-
@@ -4,8 +4,8 @@ from __future__ import annotations
4
4
  from .chatcompletionchoice import ChatCompletionChoice, ChatCompletionChoiceTypedDict
5
5
  from .usageinfo import UsageInfo, UsageInfoTypedDict
6
6
  from mistralai.types import BaseModel
7
- from typing import List, Optional, TypedDict
8
- from typing_extensions import NotRequired
7
+ from typing import List, Optional
8
+ from typing_extensions import NotRequired, TypedDict
9
9
 
10
10
 
11
11
  class ChatCompletionResponseTypedDict(TypedDict):
@@ -15,13 +15,17 @@ class ChatCompletionResponseTypedDict(TypedDict):
15
15
  usage: UsageInfoTypedDict
16
16
  created: NotRequired[int]
17
17
  choices: NotRequired[List[ChatCompletionChoiceTypedDict]]
18
-
18
+
19
19
 
20
20
  class ChatCompletionResponse(BaseModel):
21
21
  id: str
22
+
22
23
  object: str
24
+
23
25
  model: str
26
+
24
27
  usage: UsageInfo
28
+
25
29
  created: Optional[int] = None
30
+
26
31
  choices: Optional[List[ChatCompletionChoice]] = None
27
-