mistralai 1.4.0__py3-none-any.whl → 1.5.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mistralai/_version.py +3 -3
- mistralai/chat.py +87 -5
- mistralai/classifiers.py +27 -25
- mistralai/embeddings.py +2 -8
- mistralai/extra/README.md +56 -0
- mistralai/extra/__init__.py +5 -0
- mistralai/extra/struct_chat.py +41 -0
- mistralai/extra/tests/__init__.py +0 -0
- mistralai/extra/tests/test_struct_chat.py +103 -0
- mistralai/extra/tests/test_utils.py +162 -0
- mistralai/extra/utils/__init__.py +3 -0
- mistralai/extra/utils/_pydantic_helper.py +20 -0
- mistralai/extra/utils/response_format.py +24 -0
- mistralai/fim.py +5 -5
- mistralai/httpclient.py +50 -0
- mistralai/models/__init__.py +41 -16
- mistralai/models/assistantmessage.py +2 -0
- mistralai/models/chatcompletionrequest.py +3 -10
- mistralai/models/chatcompletionstreamrequest.py +3 -10
- mistralai/models/chatmoderationrequest.py +86 -0
- mistralai/models/classificationrequest.py +7 -36
- mistralai/models/contentchunk.py +8 -1
- mistralai/models/documenturlchunk.py +62 -0
- mistralai/models/embeddingrequest.py +1 -37
- mistralai/models/fimcompletionrequest.py +2 -3
- mistralai/models/fimcompletionstreamrequest.py +2 -3
- mistralai/models/jsonschema.py +55 -0
- mistralai/models/ocrimageobject.py +77 -0
- mistralai/models/ocrpagedimensions.py +25 -0
- mistralai/models/ocrpageobject.py +64 -0
- mistralai/models/ocrrequest.py +97 -0
- mistralai/models/ocrresponse.py +26 -0
- mistralai/models/ocrusageinfo.py +51 -0
- mistralai/models/prediction.py +4 -5
- mistralai/models/responseformat.py +36 -1
- mistralai/models/responseformats.py +1 -1
- mistralai/ocr.py +238 -0
- mistralai/sdk.py +15 -2
- {mistralai-1.4.0.dist-info → mistralai-1.5.1.dist-info}/METADATA +37 -1
- {mistralai-1.4.0.dist-info → mistralai-1.5.1.dist-info}/RECORD +42 -24
- {mistralai-1.4.0.dist-info → mistralai-1.5.1.dist-info}/WHEEL +1 -1
- mistralai/models/chatclassificationrequest.py +0 -113
- {mistralai-1.4.0.dist-info → mistralai-1.5.1.dist-info}/LICENSE +0 -0
mistralai/models/contentchunk.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from .documenturlchunk import DocumentURLChunk, DocumentURLChunkTypedDict
|
|
4
5
|
from .imageurlchunk import ImageURLChunk, ImageURLChunkTypedDict
|
|
5
6
|
from .referencechunk import ReferenceChunk, ReferenceChunkTypedDict
|
|
6
7
|
from .textchunk import TextChunk, TextChunkTypedDict
|
|
@@ -12,13 +13,19 @@ from typing_extensions import Annotated, TypeAliasType
|
|
|
12
13
|
|
|
13
14
|
ContentChunkTypedDict = TypeAliasType(
|
|
14
15
|
"ContentChunkTypedDict",
|
|
15
|
-
Union[
|
|
16
|
+
Union[
|
|
17
|
+
TextChunkTypedDict,
|
|
18
|
+
ImageURLChunkTypedDict,
|
|
19
|
+
ReferenceChunkTypedDict,
|
|
20
|
+
DocumentURLChunkTypedDict,
|
|
21
|
+
],
|
|
16
22
|
)
|
|
17
23
|
|
|
18
24
|
|
|
19
25
|
ContentChunk = Annotated[
|
|
20
26
|
Union[
|
|
21
27
|
Annotated[ImageURLChunk, Tag("image_url")],
|
|
28
|
+
Annotated[DocumentURLChunk, Tag("document_url")],
|
|
22
29
|
Annotated[TextChunk, Tag("text")],
|
|
23
30
|
Annotated[ReferenceChunk, Tag("reference")],
|
|
24
31
|
],
|
|
@@ -0,0 +1,62 @@
|
|
|
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 mistralai.utils import validate_const
|
|
6
|
+
import pydantic
|
|
7
|
+
from pydantic import model_serializer
|
|
8
|
+
from pydantic.functional_validators import AfterValidator
|
|
9
|
+
from typing import Literal, Optional
|
|
10
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DocumentURLChunkTypedDict(TypedDict):
|
|
14
|
+
document_url: str
|
|
15
|
+
type: Literal["document_url"]
|
|
16
|
+
document_name: NotRequired[Nullable[str]]
|
|
17
|
+
r"""The filename of the document"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class DocumentURLChunk(BaseModel):
|
|
21
|
+
document_url: str
|
|
22
|
+
|
|
23
|
+
TYPE: Annotated[
|
|
24
|
+
Annotated[
|
|
25
|
+
Optional[Literal["document_url"]],
|
|
26
|
+
AfterValidator(validate_const("document_url")),
|
|
27
|
+
],
|
|
28
|
+
pydantic.Field(alias="type"),
|
|
29
|
+
] = "document_url"
|
|
30
|
+
|
|
31
|
+
document_name: OptionalNullable[str] = UNSET
|
|
32
|
+
r"""The filename of the document"""
|
|
33
|
+
|
|
34
|
+
@model_serializer(mode="wrap")
|
|
35
|
+
def serialize_model(self, handler):
|
|
36
|
+
optional_fields = ["type", "document_name"]
|
|
37
|
+
nullable_fields = ["document_name"]
|
|
38
|
+
null_default_fields = []
|
|
39
|
+
|
|
40
|
+
serialized = handler(self)
|
|
41
|
+
|
|
42
|
+
m = {}
|
|
43
|
+
|
|
44
|
+
for n, f in self.model_fields.items():
|
|
45
|
+
k = f.alias or n
|
|
46
|
+
val = serialized.get(k)
|
|
47
|
+
serialized.pop(k, None)
|
|
48
|
+
|
|
49
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
50
|
+
is_set = (
|
|
51
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
52
|
+
or k in null_default_fields
|
|
53
|
+
) # pylint: disable=no-member
|
|
54
|
+
|
|
55
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
56
|
+
m[k] = val
|
|
57
|
+
elif val != UNSET_SENTINEL and (
|
|
58
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
59
|
+
):
|
|
60
|
+
m[k] = val
|
|
61
|
+
|
|
62
|
+
return m
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from mistralai.types import BaseModel
|
|
4
|
+
from mistralai.types import BaseModel
|
|
5
5
|
import pydantic
|
|
6
|
-
from pydantic import model_serializer
|
|
7
6
|
from typing import List, Optional, Union
|
|
8
7
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
9
8
|
|
|
@@ -21,8 +20,6 @@ class EmbeddingRequestTypedDict(TypedDict):
|
|
|
21
20
|
r"""Text to embed."""
|
|
22
21
|
model: NotRequired[str]
|
|
23
22
|
r"""ID of the model to use."""
|
|
24
|
-
encoding_format: NotRequired[Nullable[str]]
|
|
25
|
-
r"""The format to return the embeddings in."""
|
|
26
23
|
|
|
27
24
|
|
|
28
25
|
class EmbeddingRequest(BaseModel):
|
|
@@ -31,36 +28,3 @@ class EmbeddingRequest(BaseModel):
|
|
|
31
28
|
|
|
32
29
|
model: Optional[str] = "mistral-embed"
|
|
33
30
|
r"""ID of the model to use."""
|
|
34
|
-
|
|
35
|
-
encoding_format: OptionalNullable[str] = UNSET
|
|
36
|
-
r"""The format to return the embeddings in."""
|
|
37
|
-
|
|
38
|
-
@model_serializer(mode="wrap")
|
|
39
|
-
def serialize_model(self, handler):
|
|
40
|
-
optional_fields = ["model", "encoding_format"]
|
|
41
|
-
nullable_fields = ["encoding_format"]
|
|
42
|
-
null_default_fields = []
|
|
43
|
-
|
|
44
|
-
serialized = handler(self)
|
|
45
|
-
|
|
46
|
-
m = {}
|
|
47
|
-
|
|
48
|
-
for n, f in self.model_fields.items():
|
|
49
|
-
k = f.alias or n
|
|
50
|
-
val = serialized.get(k)
|
|
51
|
-
serialized.pop(k, None)
|
|
52
|
-
|
|
53
|
-
optional_nullable = k in optional_fields and k in nullable_fields
|
|
54
|
-
is_set = (
|
|
55
|
-
self.__pydantic_fields_set__.intersection({n})
|
|
56
|
-
or k in null_default_fields
|
|
57
|
-
) # pylint: disable=no-member
|
|
58
|
-
|
|
59
|
-
if val is not None and val != UNSET_SENTINEL:
|
|
60
|
-
m[k] = val
|
|
61
|
-
elif val != UNSET_SENTINEL and (
|
|
62
|
-
not k in optional_fields or (optional_nullable and is_set)
|
|
63
|
-
):
|
|
64
|
-
m[k] = val
|
|
65
|
-
|
|
66
|
-
return m
|
|
@@ -20,7 +20,7 @@ r"""Stop generation if this token is detected. Or if one of these tokens is dete
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class FIMCompletionRequestTypedDict(TypedDict):
|
|
23
|
-
model:
|
|
23
|
+
model: str
|
|
24
24
|
r"""ID of the model to use. Only compatible for now with:
|
|
25
25
|
- `codestral-2405`
|
|
26
26
|
- `codestral-latest`
|
|
@@ -46,7 +46,7 @@ class FIMCompletionRequestTypedDict(TypedDict):
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
class FIMCompletionRequest(BaseModel):
|
|
49
|
-
model:
|
|
49
|
+
model: str
|
|
50
50
|
r"""ID of the model to use. Only compatible for now with:
|
|
51
51
|
- `codestral-2405`
|
|
52
52
|
- `codestral-latest`
|
|
@@ -92,7 +92,6 @@ class FIMCompletionRequest(BaseModel):
|
|
|
92
92
|
"min_tokens",
|
|
93
93
|
]
|
|
94
94
|
nullable_fields = [
|
|
95
|
-
"model",
|
|
96
95
|
"temperature",
|
|
97
96
|
"max_tokens",
|
|
98
97
|
"random_seed",
|
|
@@ -20,7 +20,7 @@ r"""Stop generation if this token is detected. Or if one of these tokens is dete
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class FIMCompletionStreamRequestTypedDict(TypedDict):
|
|
23
|
-
model:
|
|
23
|
+
model: str
|
|
24
24
|
r"""ID of the model to use. Only compatible for now with:
|
|
25
25
|
- `codestral-2405`
|
|
26
26
|
- `codestral-latest`
|
|
@@ -45,7 +45,7 @@ class FIMCompletionStreamRequestTypedDict(TypedDict):
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
class FIMCompletionStreamRequest(BaseModel):
|
|
48
|
-
model:
|
|
48
|
+
model: str
|
|
49
49
|
r"""ID of the model to use. Only compatible for now with:
|
|
50
50
|
- `codestral-2405`
|
|
51
51
|
- `codestral-latest`
|
|
@@ -90,7 +90,6 @@ class FIMCompletionStreamRequest(BaseModel):
|
|
|
90
90
|
"min_tokens",
|
|
91
91
|
]
|
|
92
92
|
nullable_fields = [
|
|
93
|
-
"model",
|
|
94
93
|
"temperature",
|
|
95
94
|
"max_tokens",
|
|
96
95
|
"random_seed",
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import pydantic
|
|
6
|
+
from pydantic import model_serializer
|
|
7
|
+
from typing import Any, Dict, Optional
|
|
8
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class JSONSchemaTypedDict(TypedDict):
|
|
12
|
+
name: str
|
|
13
|
+
schema_definition: Dict[str, Any]
|
|
14
|
+
description: NotRequired[Nullable[str]]
|
|
15
|
+
strict: NotRequired[bool]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class JSONSchema(BaseModel):
|
|
19
|
+
name: str
|
|
20
|
+
|
|
21
|
+
schema_definition: Annotated[Dict[str, Any], pydantic.Field(alias="schema")]
|
|
22
|
+
|
|
23
|
+
description: OptionalNullable[str] = UNSET
|
|
24
|
+
|
|
25
|
+
strict: Optional[bool] = False
|
|
26
|
+
|
|
27
|
+
@model_serializer(mode="wrap")
|
|
28
|
+
def serialize_model(self, handler):
|
|
29
|
+
optional_fields = ["description", "strict"]
|
|
30
|
+
nullable_fields = ["description"]
|
|
31
|
+
null_default_fields = []
|
|
32
|
+
|
|
33
|
+
serialized = handler(self)
|
|
34
|
+
|
|
35
|
+
m = {}
|
|
36
|
+
|
|
37
|
+
for n, f in self.model_fields.items():
|
|
38
|
+
k = f.alias or n
|
|
39
|
+
val = serialized.get(k)
|
|
40
|
+
serialized.pop(k, None)
|
|
41
|
+
|
|
42
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
43
|
+
is_set = (
|
|
44
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
45
|
+
or k in null_default_fields
|
|
46
|
+
) # pylint: disable=no-member
|
|
47
|
+
|
|
48
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
49
|
+
m[k] = val
|
|
50
|
+
elif val != UNSET_SENTINEL and (
|
|
51
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
52
|
+
):
|
|
53
|
+
m[k] = val
|
|
54
|
+
|
|
55
|
+
return m
|
|
@@ -0,0 +1,77 @@
|
|
|
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 OCRImageObjectTypedDict(TypedDict):
|
|
10
|
+
id: str
|
|
11
|
+
r"""Image ID for extracted image in a page"""
|
|
12
|
+
top_left_x: Nullable[int]
|
|
13
|
+
r"""X coordinate of top-left corner of the extracted image"""
|
|
14
|
+
top_left_y: Nullable[int]
|
|
15
|
+
r"""Y coordinate of top-left corner of the extracted image"""
|
|
16
|
+
bottom_right_x: Nullable[int]
|
|
17
|
+
r"""X coordinate of bottom-right corner of the extracted image"""
|
|
18
|
+
bottom_right_y: Nullable[int]
|
|
19
|
+
r"""Y coordinate of bottom-right corner of the extracted image"""
|
|
20
|
+
image_base64: NotRequired[Nullable[str]]
|
|
21
|
+
r"""Base64 string of the extracted image"""
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class OCRImageObject(BaseModel):
|
|
25
|
+
id: str
|
|
26
|
+
r"""Image ID for extracted image in a page"""
|
|
27
|
+
|
|
28
|
+
top_left_x: Nullable[int]
|
|
29
|
+
r"""X coordinate of top-left corner of the extracted image"""
|
|
30
|
+
|
|
31
|
+
top_left_y: Nullable[int]
|
|
32
|
+
r"""Y coordinate of top-left corner of the extracted image"""
|
|
33
|
+
|
|
34
|
+
bottom_right_x: Nullable[int]
|
|
35
|
+
r"""X coordinate of bottom-right corner of the extracted image"""
|
|
36
|
+
|
|
37
|
+
bottom_right_y: Nullable[int]
|
|
38
|
+
r"""Y coordinate of bottom-right corner of the extracted image"""
|
|
39
|
+
|
|
40
|
+
image_base64: OptionalNullable[str] = UNSET
|
|
41
|
+
r"""Base64 string of the extracted image"""
|
|
42
|
+
|
|
43
|
+
@model_serializer(mode="wrap")
|
|
44
|
+
def serialize_model(self, handler):
|
|
45
|
+
optional_fields = ["image_base64"]
|
|
46
|
+
nullable_fields = [
|
|
47
|
+
"top_left_x",
|
|
48
|
+
"top_left_y",
|
|
49
|
+
"bottom_right_x",
|
|
50
|
+
"bottom_right_y",
|
|
51
|
+
"image_base64",
|
|
52
|
+
]
|
|
53
|
+
null_default_fields = []
|
|
54
|
+
|
|
55
|
+
serialized = handler(self)
|
|
56
|
+
|
|
57
|
+
m = {}
|
|
58
|
+
|
|
59
|
+
for n, f in self.model_fields.items():
|
|
60
|
+
k = f.alias or n
|
|
61
|
+
val = serialized.get(k)
|
|
62
|
+
serialized.pop(k, None)
|
|
63
|
+
|
|
64
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
65
|
+
is_set = (
|
|
66
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
67
|
+
or k in null_default_fields
|
|
68
|
+
) # pylint: disable=no-member
|
|
69
|
+
|
|
70
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
71
|
+
m[k] = val
|
|
72
|
+
elif val != UNSET_SENTINEL and (
|
|
73
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
74
|
+
):
|
|
75
|
+
m[k] = val
|
|
76
|
+
|
|
77
|
+
return m
|
|
@@ -0,0 +1,25 @@
|
|
|
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 OCRPageDimensionsTypedDict(TypedDict):
|
|
9
|
+
dpi: int
|
|
10
|
+
r"""Dots per inch of the page-image"""
|
|
11
|
+
height: int
|
|
12
|
+
r"""Height of the image in pixels"""
|
|
13
|
+
width: int
|
|
14
|
+
r"""Width of the image in pixels"""
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class OCRPageDimensions(BaseModel):
|
|
18
|
+
dpi: int
|
|
19
|
+
r"""Dots per inch of the page-image"""
|
|
20
|
+
|
|
21
|
+
height: int
|
|
22
|
+
r"""Height of the image in pixels"""
|
|
23
|
+
|
|
24
|
+
width: int
|
|
25
|
+
r"""Width of the image in pixels"""
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from .ocrimageobject import OCRImageObject, OCRImageObjectTypedDict
|
|
5
|
+
from .ocrpagedimensions import OCRPageDimensions, OCRPageDimensionsTypedDict
|
|
6
|
+
from mistralai.types import BaseModel, Nullable, UNSET_SENTINEL
|
|
7
|
+
from pydantic import model_serializer
|
|
8
|
+
from typing import List
|
|
9
|
+
from typing_extensions import TypedDict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class OCRPageObjectTypedDict(TypedDict):
|
|
13
|
+
index: int
|
|
14
|
+
r"""The page index in a pdf document starting from 0"""
|
|
15
|
+
markdown: str
|
|
16
|
+
r"""The markdown string response of the page"""
|
|
17
|
+
images: List[OCRImageObjectTypedDict]
|
|
18
|
+
r"""List of all extracted images in the page"""
|
|
19
|
+
dimensions: Nullable[OCRPageDimensionsTypedDict]
|
|
20
|
+
r"""The dimensions of the PDF Page's screenshot image"""
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class OCRPageObject(BaseModel):
|
|
24
|
+
index: int
|
|
25
|
+
r"""The page index in a pdf document starting from 0"""
|
|
26
|
+
|
|
27
|
+
markdown: str
|
|
28
|
+
r"""The markdown string response of the page"""
|
|
29
|
+
|
|
30
|
+
images: List[OCRImageObject]
|
|
31
|
+
r"""List of all extracted images in the page"""
|
|
32
|
+
|
|
33
|
+
dimensions: Nullable[OCRPageDimensions]
|
|
34
|
+
r"""The dimensions of the PDF Page's screenshot image"""
|
|
35
|
+
|
|
36
|
+
@model_serializer(mode="wrap")
|
|
37
|
+
def serialize_model(self, handler):
|
|
38
|
+
optional_fields = []
|
|
39
|
+
nullable_fields = ["dimensions"]
|
|
40
|
+
null_default_fields = []
|
|
41
|
+
|
|
42
|
+
serialized = handler(self)
|
|
43
|
+
|
|
44
|
+
m = {}
|
|
45
|
+
|
|
46
|
+
for n, f in self.model_fields.items():
|
|
47
|
+
k = f.alias or n
|
|
48
|
+
val = serialized.get(k)
|
|
49
|
+
serialized.pop(k, None)
|
|
50
|
+
|
|
51
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
52
|
+
is_set = (
|
|
53
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
54
|
+
or k in null_default_fields
|
|
55
|
+
) # pylint: disable=no-member
|
|
56
|
+
|
|
57
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
58
|
+
m[k] = val
|
|
59
|
+
elif val != UNSET_SENTINEL and (
|
|
60
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
61
|
+
):
|
|
62
|
+
m[k] = val
|
|
63
|
+
|
|
64
|
+
return m
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from .documenturlchunk import DocumentURLChunk, DocumentURLChunkTypedDict
|
|
5
|
+
from .imageurlchunk import ImageURLChunk, ImageURLChunkTypedDict
|
|
6
|
+
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
7
|
+
from pydantic import model_serializer
|
|
8
|
+
from typing import List, Optional, Union
|
|
9
|
+
from typing_extensions import NotRequired, TypeAliasType, TypedDict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
DocumentTypedDict = TypeAliasType(
|
|
13
|
+
"DocumentTypedDict", Union[ImageURLChunkTypedDict, DocumentURLChunkTypedDict]
|
|
14
|
+
)
|
|
15
|
+
r"""Document to run OCR on"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Document = TypeAliasType("Document", Union[ImageURLChunk, DocumentURLChunk])
|
|
19
|
+
r"""Document to run OCR on"""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class OCRRequestTypedDict(TypedDict):
|
|
23
|
+
model: Nullable[str]
|
|
24
|
+
document: DocumentTypedDict
|
|
25
|
+
r"""Document to run OCR on"""
|
|
26
|
+
id: NotRequired[str]
|
|
27
|
+
pages: NotRequired[Nullable[List[int]]]
|
|
28
|
+
r"""Specific pages user wants to process in various formats: single number, range, or list of both. Starts from 0"""
|
|
29
|
+
include_image_base64: NotRequired[Nullable[bool]]
|
|
30
|
+
r"""Include image URLs in response"""
|
|
31
|
+
image_limit: NotRequired[Nullable[int]]
|
|
32
|
+
r"""Max images to extract"""
|
|
33
|
+
image_min_size: NotRequired[Nullable[int]]
|
|
34
|
+
r"""Minimum height and width of image to extract"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class OCRRequest(BaseModel):
|
|
38
|
+
model: Nullable[str]
|
|
39
|
+
|
|
40
|
+
document: Document
|
|
41
|
+
r"""Document to run OCR on"""
|
|
42
|
+
|
|
43
|
+
id: Optional[str] = None
|
|
44
|
+
|
|
45
|
+
pages: OptionalNullable[List[int]] = UNSET
|
|
46
|
+
r"""Specific pages user wants to process in various formats: single number, range, or list of both. Starts from 0"""
|
|
47
|
+
|
|
48
|
+
include_image_base64: OptionalNullable[bool] = UNSET
|
|
49
|
+
r"""Include image URLs in response"""
|
|
50
|
+
|
|
51
|
+
image_limit: OptionalNullable[int] = UNSET
|
|
52
|
+
r"""Max images to extract"""
|
|
53
|
+
|
|
54
|
+
image_min_size: OptionalNullable[int] = UNSET
|
|
55
|
+
r"""Minimum height and width of image to extract"""
|
|
56
|
+
|
|
57
|
+
@model_serializer(mode="wrap")
|
|
58
|
+
def serialize_model(self, handler):
|
|
59
|
+
optional_fields = [
|
|
60
|
+
"id",
|
|
61
|
+
"pages",
|
|
62
|
+
"include_image_base64",
|
|
63
|
+
"image_limit",
|
|
64
|
+
"image_min_size",
|
|
65
|
+
]
|
|
66
|
+
nullable_fields = [
|
|
67
|
+
"model",
|
|
68
|
+
"pages",
|
|
69
|
+
"include_image_base64",
|
|
70
|
+
"image_limit",
|
|
71
|
+
"image_min_size",
|
|
72
|
+
]
|
|
73
|
+
null_default_fields = []
|
|
74
|
+
|
|
75
|
+
serialized = handler(self)
|
|
76
|
+
|
|
77
|
+
m = {}
|
|
78
|
+
|
|
79
|
+
for n, f in self.model_fields.items():
|
|
80
|
+
k = f.alias or n
|
|
81
|
+
val = serialized.get(k)
|
|
82
|
+
serialized.pop(k, None)
|
|
83
|
+
|
|
84
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
85
|
+
is_set = (
|
|
86
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
87
|
+
or k in null_default_fields
|
|
88
|
+
) # pylint: disable=no-member
|
|
89
|
+
|
|
90
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
91
|
+
m[k] = val
|
|
92
|
+
elif val != UNSET_SENTINEL and (
|
|
93
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
94
|
+
):
|
|
95
|
+
m[k] = val
|
|
96
|
+
|
|
97
|
+
return m
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from .ocrpageobject import OCRPageObject, OCRPageObjectTypedDict
|
|
5
|
+
from .ocrusageinfo import OCRUsageInfo, OCRUsageInfoTypedDict
|
|
6
|
+
from mistralai.types import BaseModel
|
|
7
|
+
from typing import List
|
|
8
|
+
from typing_extensions import TypedDict
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class OCRResponseTypedDict(TypedDict):
|
|
12
|
+
pages: List[OCRPageObjectTypedDict]
|
|
13
|
+
r"""List of OCR info for pages."""
|
|
14
|
+
model: str
|
|
15
|
+
r"""The model used to generate the OCR."""
|
|
16
|
+
usage_info: OCRUsageInfoTypedDict
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class OCRResponse(BaseModel):
|
|
20
|
+
pages: List[OCRPageObject]
|
|
21
|
+
r"""List of OCR info for pages."""
|
|
22
|
+
|
|
23
|
+
model: str
|
|
24
|
+
r"""The model used to generate the OCR."""
|
|
25
|
+
|
|
26
|
+
usage_info: OCRUsageInfo
|
|
@@ -0,0 +1,51 @@
|
|
|
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 OCRUsageInfoTypedDict(TypedDict):
|
|
10
|
+
pages_processed: int
|
|
11
|
+
r"""Number of pages processed"""
|
|
12
|
+
doc_size_bytes: NotRequired[Nullable[int]]
|
|
13
|
+
r"""Document size in bytes"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class OCRUsageInfo(BaseModel):
|
|
17
|
+
pages_processed: int
|
|
18
|
+
r"""Number of pages processed"""
|
|
19
|
+
|
|
20
|
+
doc_size_bytes: OptionalNullable[int] = UNSET
|
|
21
|
+
r"""Document size in bytes"""
|
|
22
|
+
|
|
23
|
+
@model_serializer(mode="wrap")
|
|
24
|
+
def serialize_model(self, handler):
|
|
25
|
+
optional_fields = ["doc_size_bytes"]
|
|
26
|
+
nullable_fields = ["doc_size_bytes"]
|
|
27
|
+
null_default_fields = []
|
|
28
|
+
|
|
29
|
+
serialized = handler(self)
|
|
30
|
+
|
|
31
|
+
m = {}
|
|
32
|
+
|
|
33
|
+
for n, f in self.model_fields.items():
|
|
34
|
+
k = f.alias or n
|
|
35
|
+
val = serialized.get(k)
|
|
36
|
+
serialized.pop(k, None)
|
|
37
|
+
|
|
38
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
39
|
+
is_set = (
|
|
40
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
41
|
+
or k in null_default_fields
|
|
42
|
+
) # pylint: disable=no-member
|
|
43
|
+
|
|
44
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
45
|
+
m[k] = val
|
|
46
|
+
elif val != UNSET_SENTINEL and (
|
|
47
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
48
|
+
):
|
|
49
|
+
m[k] = val
|
|
50
|
+
|
|
51
|
+
return m
|
mistralai/models/prediction.py
CHANGED
|
@@ -9,17 +9,16 @@ from typing import Literal, Optional
|
|
|
9
9
|
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
PredictionType = Literal["content"]
|
|
13
|
-
|
|
14
|
-
|
|
15
12
|
class PredictionTypedDict(TypedDict):
|
|
16
|
-
type:
|
|
13
|
+
type: Literal["content"]
|
|
17
14
|
content: NotRequired[str]
|
|
18
15
|
|
|
19
16
|
|
|
20
17
|
class Prediction(BaseModel):
|
|
21
18
|
TYPE: Annotated[
|
|
22
|
-
Annotated[
|
|
19
|
+
Annotated[
|
|
20
|
+
Optional[Literal["content"]], AfterValidator(validate_const("content"))
|
|
21
|
+
],
|
|
23
22
|
pydantic.Field(alias="type"),
|
|
24
23
|
] = "content"
|
|
25
24
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
+
from .jsonschema import JSONSchema, JSONSchemaTypedDict
|
|
4
5
|
from .responseformats import ResponseFormats
|
|
5
|
-
from mistralai.types import BaseModel
|
|
6
|
+
from mistralai.types import BaseModel, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
|
|
7
|
+
from pydantic import model_serializer
|
|
6
8
|
from typing import Optional
|
|
7
9
|
from typing_extensions import NotRequired, TypedDict
|
|
8
10
|
|
|
@@ -10,8 +12,41 @@ from typing_extensions import NotRequired, TypedDict
|
|
|
10
12
|
class ResponseFormatTypedDict(TypedDict):
|
|
11
13
|
type: NotRequired[ResponseFormats]
|
|
12
14
|
r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
|
|
15
|
+
json_schema: NotRequired[Nullable[JSONSchemaTypedDict]]
|
|
13
16
|
|
|
14
17
|
|
|
15
18
|
class ResponseFormat(BaseModel):
|
|
16
19
|
type: Optional[ResponseFormats] = None
|
|
17
20
|
r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
|
|
21
|
+
|
|
22
|
+
json_schema: OptionalNullable[JSONSchema] = UNSET
|
|
23
|
+
|
|
24
|
+
@model_serializer(mode="wrap")
|
|
25
|
+
def serialize_model(self, handler):
|
|
26
|
+
optional_fields = ["type", "json_schema"]
|
|
27
|
+
nullable_fields = ["json_schema"]
|
|
28
|
+
null_default_fields = []
|
|
29
|
+
|
|
30
|
+
serialized = handler(self)
|
|
31
|
+
|
|
32
|
+
m = {}
|
|
33
|
+
|
|
34
|
+
for n, f in self.model_fields.items():
|
|
35
|
+
k = f.alias or n
|
|
36
|
+
val = serialized.get(k)
|
|
37
|
+
serialized.pop(k, None)
|
|
38
|
+
|
|
39
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
40
|
+
is_set = (
|
|
41
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
42
|
+
or k in null_default_fields
|
|
43
|
+
) # pylint: disable=no-member
|
|
44
|
+
|
|
45
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
46
|
+
m[k] = val
|
|
47
|
+
elif val != UNSET_SENTINEL and (
|
|
48
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
49
|
+
):
|
|
50
|
+
m[k] = val
|
|
51
|
+
|
|
52
|
+
return m
|
|
@@ -4,5 +4,5 @@ from __future__ import annotations
|
|
|
4
4
|
from typing import Literal
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
ResponseFormats = Literal["text", "json_object"]
|
|
7
|
+
ResponseFormats = Literal["text", "json_object", "json_schema"]
|
|
8
8
|
r"""An object specifying the format that the model must output. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message."""
|