mistralai 1.0.2__py3-none-any.whl → 1.1.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.
- mistralai/_hooks/sdkhooks.py +23 -4
- mistralai/_hooks/types.py +27 -9
- mistralai/agents.py +286 -150
- mistralai/basesdk.py +90 -5
- mistralai/chat.py +260 -144
- mistralai/embeddings.py +73 -53
- mistralai/files.py +252 -192
- mistralai/fim.py +174 -110
- mistralai/fine_tuning.py +3 -2
- mistralai/jobs.py +372 -263
- mistralai/models/__init__.py +499 -46
- mistralai/models/agentscompletionrequest.py +47 -11
- mistralai/models/agentscompletionstreamrequest.py +49 -11
- mistralai/models/archiveftmodelout.py +6 -2
- mistralai/models/assistantmessage.py +11 -4
- mistralai/models/{modelcard.py → basemodelcard.py} +37 -14
- mistralai/models/chatcompletionchoice.py +4 -2
- mistralai/models/chatcompletionrequest.py +57 -11
- mistralai/models/chatcompletionresponse.py +6 -2
- mistralai/models/chatcompletionstreamrequest.py +59 -11
- mistralai/models/checkpointout.py +3 -2
- mistralai/models/completionchunk.py +10 -3
- mistralai/models/completionevent.py +1 -2
- mistralai/models/completionresponsestreamchoice.py +13 -5
- mistralai/models/contentchunk.py +13 -10
- mistralai/models/delete_model_v1_models_model_id_deleteop.py +4 -3
- mistralai/models/deletefileout.py +3 -2
- mistralai/models/deletemodelout.py +3 -2
- mistralai/models/deltamessage.py +9 -4
- mistralai/models/detailedjobout.py +59 -7
- mistralai/models/embeddingrequest.py +9 -4
- mistralai/models/embeddingresponse.py +5 -2
- mistralai/models/embeddingresponsedata.py +3 -2
- mistralai/models/eventout.py +9 -4
- mistralai/models/files_api_routes_delete_fileop.py +4 -3
- mistralai/models/files_api_routes_retrieve_fileop.py +4 -3
- mistralai/models/files_api_routes_upload_fileop.py +27 -8
- mistralai/models/fileschema.py +26 -5
- mistralai/models/fimcompletionrequest.py +26 -5
- mistralai/models/fimcompletionresponse.py +6 -2
- mistralai/models/fimcompletionstreamrequest.py +26 -5
- mistralai/models/finetuneablemodel.py +7 -1
- mistralai/models/ftmodelcapabilitiesout.py +4 -2
- mistralai/models/ftmodelcard.py +103 -0
- mistralai/models/ftmodelout.py +32 -6
- mistralai/models/function.py +3 -2
- mistralai/models/functioncall.py +2 -2
- mistralai/models/functionname.py +17 -0
- mistralai/models/githubrepositoryin.py +15 -4
- mistralai/models/githubrepositoryout.py +15 -4
- mistralai/models/httpvalidationerror.py +2 -2
- mistralai/models/imageurl.py +48 -0
- mistralai/models/imageurlchunk.py +32 -0
- mistralai/models/jobin.py +22 -5
- mistralai/models/jobmetadataout.py +31 -6
- mistralai/models/jobout.py +55 -7
- mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +83 -16
- mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +9 -4
- mistralai/models/jobsout.py +6 -2
- mistralai/models/legacyjobmetadataout.py +45 -6
- mistralai/models/listfilesout.py +2 -2
- mistralai/models/metricout.py +11 -6
- mistralai/models/modelcapabilities.py +7 -2
- mistralai/models/modellist.py +21 -7
- mistralai/models/responseformat.py +6 -7
- mistralai/models/responseformats.py +8 -0
- mistralai/models/retrieve_model_v1_models_model_id_getop.py +24 -5
- mistralai/models/retrievefileout.py +26 -5
- mistralai/models/security.py +12 -3
- mistralai/models/systemmessage.py +6 -5
- mistralai/models/textchunk.py +9 -4
- mistralai/models/tool.py +9 -8
- mistralai/models/toolcall.py +9 -7
- mistralai/models/toolchoice.py +29 -0
- mistralai/models/toolchoiceenum.py +7 -0
- mistralai/models/toolmessage.py +11 -4
- mistralai/models/tooltypes.py +8 -0
- mistralai/models/trainingfile.py +2 -2
- mistralai/models/trainingparameters.py +27 -6
- mistralai/models/trainingparametersin.py +29 -8
- mistralai/models/unarchiveftmodelout.py +6 -2
- mistralai/models/updateftmodelin.py +8 -4
- mistralai/models/uploadfileout.py +26 -5
- mistralai/models/usageinfo.py +3 -2
- mistralai/models/usermessage.py +6 -5
- mistralai/models/validationerror.py +3 -2
- mistralai/models/wandbintegration.py +14 -4
- mistralai/models/wandbintegrationout.py +13 -4
- mistralai/models_.py +392 -294
- mistralai/sdk.py +24 -19
- mistralai/sdkconfiguration.py +6 -8
- mistralai/utils/__init__.py +6 -1
- mistralai/utils/logger.py +4 -1
- mistralai/utils/retries.py +2 -1
- mistralai/utils/security.py +13 -6
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/METADATA +103 -74
- mistralai-1.1.0.dist-info/RECORD +254 -0
- mistralai_azure/_hooks/sdkhooks.py +23 -4
- mistralai_azure/_hooks/types.py +27 -9
- mistralai_azure/basesdk.py +91 -6
- mistralai_azure/chat.py +252 -144
- mistralai_azure/models/__init__.py +157 -15
- mistralai_azure/models/assistantmessage.py +18 -5
- mistralai_azure/models/chatcompletionchoice.py +7 -3
- mistralai_azure/models/chatcompletionrequest.py +65 -12
- mistralai_azure/models/chatcompletionresponse.py +6 -2
- mistralai_azure/models/chatcompletionstreamrequest.py +67 -12
- mistralai_azure/models/completionchunk.py +10 -3
- mistralai_azure/models/completionevent.py +1 -2
- mistralai_azure/models/completionresponsestreamchoice.py +10 -4
- mistralai_azure/models/contentchunk.py +4 -11
- mistralai_azure/models/deltamessage.py +16 -5
- mistralai_azure/models/function.py +3 -2
- mistralai_azure/models/functioncall.py +2 -2
- mistralai_azure/models/functionname.py +17 -0
- mistralai_azure/models/httpvalidationerror.py +2 -2
- mistralai_azure/models/responseformat.py +6 -7
- mistralai_azure/models/responseformats.py +8 -0
- mistralai_azure/models/security.py +12 -3
- mistralai_azure/models/systemmessage.py +6 -5
- mistralai_azure/models/textchunk.py +9 -4
- mistralai_azure/models/tool.py +9 -8
- mistralai_azure/models/toolcall.py +9 -7
- mistralai_azure/models/toolchoice.py +29 -0
- mistralai_azure/models/toolchoiceenum.py +7 -0
- mistralai_azure/models/toolmessage.py +18 -5
- mistralai_azure/models/tooltypes.py +8 -0
- mistralai_azure/models/usageinfo.py +3 -2
- mistralai_azure/models/usermessage.py +6 -5
- mistralai_azure/models/validationerror.py +3 -2
- mistralai_azure/sdkconfiguration.py +6 -8
- mistralai_azure/utils/__init__.py +8 -3
- mistralai_azure/utils/forms.py +10 -9
- mistralai_azure/utils/headers.py +8 -8
- mistralai_azure/utils/logger.py +6 -0
- mistralai_azure/utils/queryparams.py +16 -14
- mistralai_azure/utils/retries.py +2 -1
- mistralai_azure/utils/security.py +12 -6
- mistralai_azure/utils/serializers.py +17 -8
- mistralai_azure/utils/url.py +13 -8
- mistralai_azure/utils/values.py +6 -0
- mistralai_gcp/_hooks/sdkhooks.py +23 -4
- mistralai_gcp/_hooks/types.py +27 -9
- mistralai_gcp/basesdk.py +91 -6
- mistralai_gcp/chat.py +252 -144
- mistralai_gcp/fim.py +166 -110
- mistralai_gcp/models/__init__.py +179 -17
- mistralai_gcp/models/assistantmessage.py +18 -5
- mistralai_gcp/models/chatcompletionchoice.py +7 -3
- mistralai_gcp/models/chatcompletionrequest.py +62 -12
- mistralai_gcp/models/chatcompletionresponse.py +6 -2
- mistralai_gcp/models/chatcompletionstreamrequest.py +64 -12
- mistralai_gcp/models/completionchunk.py +10 -3
- mistralai_gcp/models/completionevent.py +1 -2
- mistralai_gcp/models/completionresponsestreamchoice.py +10 -4
- mistralai_gcp/models/contentchunk.py +4 -11
- mistralai_gcp/models/deltamessage.py +16 -5
- mistralai_gcp/models/fimcompletionrequest.py +33 -6
- mistralai_gcp/models/fimcompletionresponse.py +6 -2
- mistralai_gcp/models/fimcompletionstreamrequest.py +33 -6
- mistralai_gcp/models/function.py +3 -2
- mistralai_gcp/models/functioncall.py +2 -2
- mistralai_gcp/models/functionname.py +17 -0
- mistralai_gcp/models/httpvalidationerror.py +2 -2
- mistralai_gcp/models/responseformat.py +6 -7
- mistralai_gcp/models/responseformats.py +8 -0
- mistralai_gcp/models/security.py +12 -3
- mistralai_gcp/models/systemmessage.py +6 -5
- mistralai_gcp/models/textchunk.py +9 -4
- mistralai_gcp/models/tool.py +9 -8
- mistralai_gcp/models/toolcall.py +9 -7
- mistralai_gcp/models/toolchoice.py +29 -0
- mistralai_gcp/models/toolchoiceenum.py +7 -0
- mistralai_gcp/models/toolmessage.py +18 -5
- mistralai_gcp/models/tooltypes.py +8 -0
- mistralai_gcp/models/usageinfo.py +3 -2
- mistralai_gcp/models/usermessage.py +6 -5
- mistralai_gcp/models/validationerror.py +3 -2
- mistralai_gcp/sdk.py +14 -10
- mistralai_gcp/sdkconfiguration.py +6 -8
- mistralai_gcp/utils/__init__.py +8 -3
- mistralai_gcp/utils/forms.py +10 -9
- mistralai_gcp/utils/headers.py +8 -8
- mistralai_gcp/utils/logger.py +6 -0
- mistralai_gcp/utils/queryparams.py +16 -14
- mistralai_gcp/utils/retries.py +2 -1
- mistralai_gcp/utils/security.py +12 -6
- mistralai_gcp/utils/serializers.py +17 -8
- mistralai_gcp/utils/url.py +13 -8
- mistralai_gcp/utils/values.py +6 -0
- mistralai-1.0.2.dist-info/RECORD +0 -236
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/LICENSE +0 -0
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/WHEEL +0 -0
|
@@ -4,12 +4,14 @@ from __future__ import annotations
|
|
|
4
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
5
5
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
6
6
|
from .tool import Tool, ToolTypedDict
|
|
7
|
+
from .toolchoice import ToolChoice, ToolChoiceTypedDict
|
|
8
|
+
from .toolchoiceenum import ToolChoiceEnum
|
|
7
9
|
from .toolmessage import ToolMessage, ToolMessageTypedDict
|
|
8
10
|
from .usermessage import UserMessage, UserMessageTypedDict
|
|
9
11
|
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
10
12
|
from mistralai.utils import get_discriminator
|
|
11
13
|
from pydantic import Discriminator, Tag, model_serializer
|
|
12
|
-
from typing import List,
|
|
14
|
+
from typing import List, Optional, TypedDict, Union
|
|
13
15
|
from typing_extensions import Annotated, NotRequired
|
|
14
16
|
|
|
15
17
|
|
|
@@ -21,13 +23,26 @@ AgentsCompletionRequestStop = Union[str, List[str]]
|
|
|
21
23
|
r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
AgentsCompletionRequestMessagesTypedDict = Union[
|
|
26
|
+
AgentsCompletionRequestMessagesTypedDict = Union[
|
|
27
|
+
UserMessageTypedDict, AssistantMessageTypedDict, ToolMessageTypedDict
|
|
28
|
+
]
|
|
25
29
|
|
|
26
30
|
|
|
27
|
-
AgentsCompletionRequestMessages = Annotated[
|
|
31
|
+
AgentsCompletionRequestMessages = Annotated[
|
|
32
|
+
Union[
|
|
33
|
+
Annotated[AssistantMessage, Tag("assistant")],
|
|
34
|
+
Annotated[ToolMessage, Tag("tool")],
|
|
35
|
+
Annotated[UserMessage, Tag("user")],
|
|
36
|
+
],
|
|
37
|
+
Discriminator(lambda m: get_discriminator(m, "role", "role")),
|
|
38
|
+
]
|
|
28
39
|
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
AgentsCompletionRequestToolChoiceTypedDict = Union[ToolChoiceTypedDict, ToolChoiceEnum]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
AgentsCompletionRequestToolChoice = Union[ToolChoice, ToolChoiceEnum]
|
|
45
|
+
|
|
31
46
|
|
|
32
47
|
class AgentsCompletionRequestTypedDict(TypedDict):
|
|
33
48
|
messages: List[AgentsCompletionRequestMessagesTypedDict]
|
|
@@ -46,31 +61,49 @@ class AgentsCompletionRequestTypedDict(TypedDict):
|
|
|
46
61
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
47
62
|
response_format: NotRequired[ResponseFormatTypedDict]
|
|
48
63
|
tools: NotRequired[Nullable[List[ToolTypedDict]]]
|
|
49
|
-
tool_choice: NotRequired[
|
|
50
|
-
|
|
64
|
+
tool_choice: NotRequired[AgentsCompletionRequestToolChoiceTypedDict]
|
|
65
|
+
|
|
51
66
|
|
|
52
67
|
class AgentsCompletionRequest(BaseModel):
|
|
53
68
|
messages: List[AgentsCompletionRequestMessages]
|
|
54
69
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
70
|
+
|
|
55
71
|
agent_id: str
|
|
56
72
|
r"""The ID of the agent to use for this completion."""
|
|
73
|
+
|
|
57
74
|
max_tokens: OptionalNullable[int] = UNSET
|
|
58
75
|
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."""
|
|
76
|
+
|
|
59
77
|
min_tokens: OptionalNullable[int] = UNSET
|
|
60
78
|
r"""The minimum number of tokens to generate in the completion."""
|
|
79
|
+
|
|
61
80
|
stream: Optional[bool] = False
|
|
62
81
|
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."""
|
|
82
|
+
|
|
63
83
|
stop: Optional[AgentsCompletionRequestStop] = None
|
|
64
84
|
r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
|
|
85
|
+
|
|
65
86
|
random_seed: OptionalNullable[int] = UNSET
|
|
66
87
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
88
|
+
|
|
67
89
|
response_format: Optional[ResponseFormat] = None
|
|
90
|
+
|
|
68
91
|
tools: OptionalNullable[List[Tool]] = UNSET
|
|
69
|
-
|
|
70
|
-
|
|
92
|
+
|
|
93
|
+
tool_choice: Optional[AgentsCompletionRequestToolChoice] = None
|
|
94
|
+
|
|
71
95
|
@model_serializer(mode="wrap")
|
|
72
96
|
def serialize_model(self, handler):
|
|
73
|
-
optional_fields = [
|
|
97
|
+
optional_fields = [
|
|
98
|
+
"max_tokens",
|
|
99
|
+
"min_tokens",
|
|
100
|
+
"stream",
|
|
101
|
+
"stop",
|
|
102
|
+
"random_seed",
|
|
103
|
+
"response_format",
|
|
104
|
+
"tools",
|
|
105
|
+
"tool_choice",
|
|
106
|
+
]
|
|
74
107
|
nullable_fields = ["max_tokens", "min_tokens", "random_seed", "tools"]
|
|
75
108
|
null_default_fields = []
|
|
76
109
|
|
|
@@ -81,9 +114,13 @@ class AgentsCompletionRequest(BaseModel):
|
|
|
81
114
|
for n, f in self.model_fields.items():
|
|
82
115
|
k = f.alias or n
|
|
83
116
|
val = serialized.get(k)
|
|
117
|
+
serialized.pop(k, None)
|
|
84
118
|
|
|
85
119
|
optional_nullable = k in optional_fields and k in nullable_fields
|
|
86
|
-
is_set = (
|
|
120
|
+
is_set = (
|
|
121
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
122
|
+
or k in null_default_fields
|
|
123
|
+
) # pylint: disable=no-member
|
|
87
124
|
|
|
88
125
|
if val is not None and val != UNSET_SENTINEL:
|
|
89
126
|
m[k] = val
|
|
@@ -93,4 +130,3 @@ class AgentsCompletionRequest(BaseModel):
|
|
|
93
130
|
m[k] = val
|
|
94
131
|
|
|
95
132
|
return m
|
|
96
|
-
|
|
@@ -4,12 +4,14 @@ from __future__ import annotations
|
|
|
4
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
5
5
|
from .responseformat import ResponseFormat, ResponseFormatTypedDict
|
|
6
6
|
from .tool import Tool, ToolTypedDict
|
|
7
|
+
from .toolchoice import ToolChoice, ToolChoiceTypedDict
|
|
8
|
+
from .toolchoiceenum import ToolChoiceEnum
|
|
7
9
|
from .toolmessage import ToolMessage, ToolMessageTypedDict
|
|
8
10
|
from .usermessage import UserMessage, UserMessageTypedDict
|
|
9
11
|
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
10
12
|
from mistralai.utils import get_discriminator
|
|
11
13
|
from pydantic import Discriminator, Tag, model_serializer
|
|
12
|
-
from typing import List,
|
|
14
|
+
from typing import List, Optional, TypedDict, Union
|
|
13
15
|
from typing_extensions import Annotated, NotRequired
|
|
14
16
|
|
|
15
17
|
|
|
@@ -21,13 +23,28 @@ AgentsCompletionStreamRequestStop = Union[str, List[str]]
|
|
|
21
23
|
r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
|
|
22
24
|
|
|
23
25
|
|
|
24
|
-
AgentsCompletionStreamRequestMessagesTypedDict = Union[
|
|
26
|
+
AgentsCompletionStreamRequestMessagesTypedDict = Union[
|
|
27
|
+
UserMessageTypedDict, AssistantMessageTypedDict, ToolMessageTypedDict
|
|
28
|
+
]
|
|
25
29
|
|
|
26
30
|
|
|
27
|
-
AgentsCompletionStreamRequestMessages = Annotated[
|
|
31
|
+
AgentsCompletionStreamRequestMessages = Annotated[
|
|
32
|
+
Union[
|
|
33
|
+
Annotated[AssistantMessage, Tag("assistant")],
|
|
34
|
+
Annotated[ToolMessage, Tag("tool")],
|
|
35
|
+
Annotated[UserMessage, Tag("user")],
|
|
36
|
+
],
|
|
37
|
+
Discriminator(lambda m: get_discriminator(m, "role", "role")),
|
|
38
|
+
]
|
|
28
39
|
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
AgentsCompletionStreamRequestToolChoiceTypedDict = Union[
|
|
42
|
+
ToolChoiceTypedDict, ToolChoiceEnum
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
AgentsCompletionStreamRequestToolChoice = Union[ToolChoice, ToolChoiceEnum]
|
|
47
|
+
|
|
31
48
|
|
|
32
49
|
class AgentsCompletionStreamRequestTypedDict(TypedDict):
|
|
33
50
|
messages: List[AgentsCompletionStreamRequestMessagesTypedDict]
|
|
@@ -45,30 +62,48 @@ class AgentsCompletionStreamRequestTypedDict(TypedDict):
|
|
|
45
62
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
46
63
|
response_format: NotRequired[ResponseFormatTypedDict]
|
|
47
64
|
tools: NotRequired[Nullable[List[ToolTypedDict]]]
|
|
48
|
-
tool_choice: NotRequired[
|
|
49
|
-
|
|
65
|
+
tool_choice: NotRequired[AgentsCompletionStreamRequestToolChoiceTypedDict]
|
|
66
|
+
|
|
50
67
|
|
|
51
68
|
class AgentsCompletionStreamRequest(BaseModel):
|
|
52
69
|
messages: List[AgentsCompletionStreamRequestMessages]
|
|
53
70
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
71
|
+
|
|
54
72
|
agent_id: str
|
|
55
73
|
r"""The ID of the agent to use for this completion."""
|
|
74
|
+
|
|
56
75
|
max_tokens: OptionalNullable[int] = UNSET
|
|
57
76
|
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."""
|
|
77
|
+
|
|
58
78
|
min_tokens: OptionalNullable[int] = UNSET
|
|
59
79
|
r"""The minimum number of tokens to generate in the completion."""
|
|
80
|
+
|
|
60
81
|
stream: Optional[bool] = True
|
|
82
|
+
|
|
61
83
|
stop: Optional[AgentsCompletionStreamRequestStop] = None
|
|
62
84
|
r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
|
|
85
|
+
|
|
63
86
|
random_seed: OptionalNullable[int] = UNSET
|
|
64
87
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
88
|
+
|
|
65
89
|
response_format: Optional[ResponseFormat] = None
|
|
90
|
+
|
|
66
91
|
tools: OptionalNullable[List[Tool]] = UNSET
|
|
67
|
-
|
|
68
|
-
|
|
92
|
+
|
|
93
|
+
tool_choice: Optional[AgentsCompletionStreamRequestToolChoice] = None
|
|
94
|
+
|
|
69
95
|
@model_serializer(mode="wrap")
|
|
70
96
|
def serialize_model(self, handler):
|
|
71
|
-
optional_fields = [
|
|
97
|
+
optional_fields = [
|
|
98
|
+
"max_tokens",
|
|
99
|
+
"min_tokens",
|
|
100
|
+
"stream",
|
|
101
|
+
"stop",
|
|
102
|
+
"random_seed",
|
|
103
|
+
"response_format",
|
|
104
|
+
"tools",
|
|
105
|
+
"tool_choice",
|
|
106
|
+
]
|
|
72
107
|
nullable_fields = ["max_tokens", "min_tokens", "random_seed", "tools"]
|
|
73
108
|
null_default_fields = []
|
|
74
109
|
|
|
@@ -79,9 +114,13 @@ class AgentsCompletionStreamRequest(BaseModel):
|
|
|
79
114
|
for n, f in self.model_fields.items():
|
|
80
115
|
k = f.alias or n
|
|
81
116
|
val = serialized.get(k)
|
|
117
|
+
serialized.pop(k, None)
|
|
82
118
|
|
|
83
119
|
optional_nullable = k in optional_fields and k in nullable_fields
|
|
84
|
-
is_set = (
|
|
120
|
+
is_set = (
|
|
121
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
122
|
+
or k in null_default_fields
|
|
123
|
+
) # pylint: disable=no-member
|
|
85
124
|
|
|
86
125
|
if val is not None and val != UNSET_SENTINEL:
|
|
87
126
|
m[k] = val
|
|
@@ -91,4 +130,3 @@ class AgentsCompletionStreamRequest(BaseModel):
|
|
|
91
130
|
m[k] = val
|
|
92
131
|
|
|
93
132
|
return m
|
|
94
|
-
|
|
@@ -9,13 +9,17 @@ from typing_extensions import Annotated, NotRequired
|
|
|
9
9
|
|
|
10
10
|
ArchiveFTModelOutObject = Literal["model"]
|
|
11
11
|
|
|
12
|
+
|
|
12
13
|
class ArchiveFTModelOutTypedDict(TypedDict):
|
|
13
14
|
id: str
|
|
14
15
|
archived: NotRequired[bool]
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
|
|
17
18
|
class ArchiveFTModelOut(BaseModel):
|
|
18
19
|
id: str
|
|
20
|
+
|
|
21
|
+
# fmt: off
|
|
19
22
|
OBJECT: Annotated[Final[Optional[ArchiveFTModelOutObject]], pydantic.Field(alias="object")] = "model" # type: ignore
|
|
23
|
+
# fmt: on
|
|
24
|
+
|
|
20
25
|
archived: Optional[bool] = True
|
|
21
|
-
|
|
@@ -10,21 +10,25 @@ from typing_extensions import NotRequired
|
|
|
10
10
|
|
|
11
11
|
AssistantMessageRole = Literal["assistant"]
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
class AssistantMessageTypedDict(TypedDict):
|
|
14
15
|
content: NotRequired[Nullable[str]]
|
|
15
16
|
tool_calls: NotRequired[Nullable[List[ToolCallTypedDict]]]
|
|
16
17
|
prefix: NotRequired[bool]
|
|
17
18
|
r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
|
|
18
19
|
role: NotRequired[AssistantMessageRole]
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
|
|
21
22
|
class AssistantMessage(BaseModel):
|
|
22
23
|
content: OptionalNullable[str] = UNSET
|
|
24
|
+
|
|
23
25
|
tool_calls: OptionalNullable[List[ToolCall]] = UNSET
|
|
26
|
+
|
|
24
27
|
prefix: Optional[bool] = False
|
|
25
28
|
r"""Set this to `true` when adding an assistant message as prefix to condition the model response. The role of the prefix message is to force the model to start its answer by the content of the message."""
|
|
29
|
+
|
|
26
30
|
role: Optional[AssistantMessageRole] = "assistant"
|
|
27
|
-
|
|
31
|
+
|
|
28
32
|
@model_serializer(mode="wrap")
|
|
29
33
|
def serialize_model(self, handler):
|
|
30
34
|
optional_fields = ["content", "tool_calls", "prefix", "role"]
|
|
@@ -38,9 +42,13 @@ class AssistantMessage(BaseModel):
|
|
|
38
42
|
for n, f in self.model_fields.items():
|
|
39
43
|
k = f.alias or n
|
|
40
44
|
val = serialized.get(k)
|
|
45
|
+
serialized.pop(k, None)
|
|
41
46
|
|
|
42
47
|
optional_nullable = k in optional_fields and k in nullable_fields
|
|
43
|
-
is_set = (
|
|
48
|
+
is_set = (
|
|
49
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
50
|
+
or k in null_default_fields
|
|
51
|
+
) # pylint: disable=no-member
|
|
44
52
|
|
|
45
53
|
if val is not None and val != UNSET_SENTINEL:
|
|
46
54
|
m[k] = val
|
|
@@ -50,4 +58,3 @@ class AssistantMessage(BaseModel):
|
|
|
50
58
|
m[k] = val
|
|
51
59
|
|
|
52
60
|
return m
|
|
53
|
-
|
|
@@ -4,44 +4,64 @@ from __future__ import annotations
|
|
|
4
4
|
from .modelcapabilities import ModelCapabilities, ModelCapabilitiesTypedDict
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
7
|
+
import pydantic
|
|
7
8
|
from pydantic import model_serializer
|
|
8
|
-
from typing import List, Optional, TypedDict
|
|
9
|
-
from typing_extensions import NotRequired
|
|
9
|
+
from typing import Final, List, Optional, TypedDict
|
|
10
|
+
from typing_extensions import Annotated, NotRequired
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
class
|
|
13
|
+
class BaseModelCardTypedDict(TypedDict):
|
|
13
14
|
id: str
|
|
14
15
|
capabilities: ModelCapabilitiesTypedDict
|
|
15
16
|
object: NotRequired[str]
|
|
16
17
|
created: NotRequired[int]
|
|
17
18
|
owned_by: NotRequired[str]
|
|
18
|
-
root: NotRequired[Nullable[str]]
|
|
19
|
-
archived: NotRequired[bool]
|
|
20
19
|
name: NotRequired[Nullable[str]]
|
|
21
20
|
description: NotRequired[Nullable[str]]
|
|
22
21
|
max_context_length: NotRequired[int]
|
|
23
22
|
aliases: NotRequired[List[str]]
|
|
24
23
|
deprecation: NotRequired[Nullable[datetime]]
|
|
25
|
-
|
|
26
24
|
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
class BaseModelCard(BaseModel):
|
|
28
27
|
id: str
|
|
28
|
+
|
|
29
29
|
capabilities: ModelCapabilities
|
|
30
|
+
|
|
30
31
|
object: Optional[str] = "model"
|
|
32
|
+
|
|
31
33
|
created: Optional[int] = None
|
|
34
|
+
|
|
32
35
|
owned_by: Optional[str] = "mistralai"
|
|
33
|
-
|
|
34
|
-
archived: Optional[bool] = False
|
|
36
|
+
|
|
35
37
|
name: OptionalNullable[str] = UNSET
|
|
38
|
+
|
|
36
39
|
description: OptionalNullable[str] = UNSET
|
|
40
|
+
|
|
37
41
|
max_context_length: Optional[int] = 32768
|
|
42
|
+
|
|
38
43
|
aliases: Optional[List[str]] = None
|
|
44
|
+
|
|
39
45
|
deprecation: OptionalNullable[datetime] = UNSET
|
|
40
|
-
|
|
46
|
+
|
|
47
|
+
# fmt: off
|
|
48
|
+
TYPE: Annotated[Final[Optional[str]], pydantic.Field(alias="type")] = "base" # type: ignore
|
|
49
|
+
# fmt: on
|
|
50
|
+
|
|
41
51
|
@model_serializer(mode="wrap")
|
|
42
52
|
def serialize_model(self, handler):
|
|
43
|
-
optional_fields = [
|
|
44
|
-
|
|
53
|
+
optional_fields = [
|
|
54
|
+
"object",
|
|
55
|
+
"created",
|
|
56
|
+
"owned_by",
|
|
57
|
+
"name",
|
|
58
|
+
"description",
|
|
59
|
+
"max_context_length",
|
|
60
|
+
"aliases",
|
|
61
|
+
"deprecation",
|
|
62
|
+
"type",
|
|
63
|
+
]
|
|
64
|
+
nullable_fields = ["name", "description", "deprecation"]
|
|
45
65
|
null_default_fields = []
|
|
46
66
|
|
|
47
67
|
serialized = handler(self)
|
|
@@ -51,9 +71,13 @@ class ModelCard(BaseModel):
|
|
|
51
71
|
for n, f in self.model_fields.items():
|
|
52
72
|
k = f.alias or n
|
|
53
73
|
val = serialized.get(k)
|
|
74
|
+
serialized.pop(k, None)
|
|
54
75
|
|
|
55
76
|
optional_nullable = k in optional_fields and k in nullable_fields
|
|
56
|
-
is_set = (
|
|
77
|
+
is_set = (
|
|
78
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
79
|
+
or k in null_default_fields
|
|
80
|
+
) # pylint: disable=no-member
|
|
57
81
|
|
|
58
82
|
if val is not None and val != UNSET_SENTINEL:
|
|
59
83
|
m[k] = val
|
|
@@ -63,4 +87,3 @@ class ModelCard(BaseModel):
|
|
|
63
87
|
m[k] = val
|
|
64
88
|
|
|
65
89
|
return m
|
|
66
|
-
|
|
@@ -8,14 +8,16 @@ from typing import Literal, TypedDict
|
|
|
8
8
|
|
|
9
9
|
FinishReason = Literal["stop", "length", "model_length", "error", "tool_calls"]
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
class ChatCompletionChoiceTypedDict(TypedDict):
|
|
12
13
|
index: int
|
|
13
14
|
message: AssistantMessageTypedDict
|
|
14
15
|
finish_reason: FinishReason
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
|
|
17
18
|
class ChatCompletionChoice(BaseModel):
|
|
18
19
|
index: int
|
|
20
|
+
|
|
19
21
|
message: AssistantMessage
|
|
22
|
+
|
|
20
23
|
finish_reason: FinishReason
|
|
21
|
-
|
|
@@ -5,12 +5,14 @@ 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,
|
|
15
|
+
from typing import List, Optional, TypedDict, Union
|
|
14
16
|
from typing_extensions import Annotated, NotRequired
|
|
15
17
|
|
|
16
18
|
|
|
@@ -22,13 +24,30 @@ 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[
|
|
27
|
+
MessagesTypedDict = Union[
|
|
28
|
+
SystemMessageTypedDict,
|
|
29
|
+
UserMessageTypedDict,
|
|
30
|
+
AssistantMessageTypedDict,
|
|
31
|
+
ToolMessageTypedDict,
|
|
32
|
+
]
|
|
26
33
|
|
|
27
34
|
|
|
28
|
-
Messages = Annotated[
|
|
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
|
-
|
|
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]
|
|
@@ -51,39 +70,63 @@ class ChatCompletionRequestTypedDict(TypedDict):
|
|
|
51
70
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
52
71
|
response_format: NotRequired[ResponseFormatTypedDict]
|
|
53
72
|
tools: NotRequired[Nullable[List[ToolTypedDict]]]
|
|
54
|
-
tool_choice: NotRequired[
|
|
73
|
+
tool_choice: NotRequired[ChatCompletionRequestToolChoiceTypedDict]
|
|
55
74
|
safe_prompt: NotRequired[bool]
|
|
56
75
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
57
|
-
|
|
76
|
+
|
|
58
77
|
|
|
59
78
|
class ChatCompletionRequest(BaseModel):
|
|
60
79
|
model: Nullable[str]
|
|
61
80
|
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."""
|
|
81
|
+
|
|
62
82
|
messages: List[Messages]
|
|
63
83
|
r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
|
|
84
|
+
|
|
64
85
|
temperature: Optional[float] = 0.7
|
|
65
86
|
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."""
|
|
87
|
+
|
|
66
88
|
top_p: Optional[float] = 1
|
|
67
89
|
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."""
|
|
90
|
+
|
|
68
91
|
max_tokens: OptionalNullable[int] = UNSET
|
|
69
92
|
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."""
|
|
93
|
+
|
|
70
94
|
min_tokens: OptionalNullable[int] = UNSET
|
|
71
95
|
r"""The minimum number of tokens to generate in the completion."""
|
|
96
|
+
|
|
72
97
|
stream: Optional[bool] = False
|
|
73
98
|
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."""
|
|
99
|
+
|
|
74
100
|
stop: Optional[Stop] = None
|
|
75
101
|
r"""Stop generation if this token is detected. Or if one of these tokens is detected when providing an array"""
|
|
102
|
+
|
|
76
103
|
random_seed: OptionalNullable[int] = UNSET
|
|
77
104
|
r"""The seed to use for random sampling. If set, different calls will generate deterministic results."""
|
|
105
|
+
|
|
78
106
|
response_format: Optional[ResponseFormat] = None
|
|
107
|
+
|
|
79
108
|
tools: OptionalNullable[List[Tool]] = UNSET
|
|
80
|
-
|
|
109
|
+
|
|
110
|
+
tool_choice: Optional[ChatCompletionRequestToolChoice] = None
|
|
111
|
+
|
|
81
112
|
safe_prompt: Optional[bool] = False
|
|
82
113
|
r"""Whether to inject a safety prompt before all conversations."""
|
|
83
|
-
|
|
114
|
+
|
|
84
115
|
@model_serializer(mode="wrap")
|
|
85
116
|
def serialize_model(self, handler):
|
|
86
|
-
optional_fields = [
|
|
117
|
+
optional_fields = [
|
|
118
|
+
"temperature",
|
|
119
|
+
"top_p",
|
|
120
|
+
"max_tokens",
|
|
121
|
+
"min_tokens",
|
|
122
|
+
"stream",
|
|
123
|
+
"stop",
|
|
124
|
+
"random_seed",
|
|
125
|
+
"response_format",
|
|
126
|
+
"tools",
|
|
127
|
+
"tool_choice",
|
|
128
|
+
"safe_prompt",
|
|
129
|
+
]
|
|
87
130
|
nullable_fields = ["model", "max_tokens", "min_tokens", "random_seed", "tools"]
|
|
88
131
|
null_default_fields = []
|
|
89
132
|
|
|
@@ -94,9 +137,13 @@ class ChatCompletionRequest(BaseModel):
|
|
|
94
137
|
for n, f in self.model_fields.items():
|
|
95
138
|
k = f.alias or n
|
|
96
139
|
val = serialized.get(k)
|
|
140
|
+
serialized.pop(k, None)
|
|
97
141
|
|
|
98
142
|
optional_nullable = k in optional_fields and k in nullable_fields
|
|
99
|
-
is_set = (
|
|
143
|
+
is_set = (
|
|
144
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
145
|
+
or k in null_default_fields
|
|
146
|
+
) # pylint: disable=no-member
|
|
100
147
|
|
|
101
148
|
if val is not None and val != UNSET_SENTINEL:
|
|
102
149
|
m[k] = val
|
|
@@ -106,4 +153,3 @@ class ChatCompletionRequest(BaseModel):
|
|
|
106
153
|
m[k] = val
|
|
107
154
|
|
|
108
155
|
return m
|
|
109
|
-
|
|
@@ -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
|
-
|