mistralai 1.5.0__py3-none-any.whl → 1.5.2rc1__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 (89) hide show
  1. mistralai/_hooks/types.py +15 -3
  2. mistralai/_version.py +3 -3
  3. mistralai/agents.py +32 -12
  4. mistralai/basesdk.py +8 -0
  5. mistralai/chat.py +37 -17
  6. mistralai/classifiers.py +59 -37
  7. mistralai/embeddings.py +22 -18
  8. mistralai/extra/utils/response_format.py +3 -3
  9. mistralai/files.py +36 -0
  10. mistralai/fim.py +37 -17
  11. mistralai/httpclient.py +4 -2
  12. mistralai/jobs.py +30 -0
  13. mistralai/mistral_jobs.py +24 -0
  14. mistralai/models/__init__.py +43 -16
  15. mistralai/models/assistantmessage.py +2 -0
  16. mistralai/models/chatcompletionrequest.py +3 -10
  17. mistralai/models/chatcompletionstreamrequest.py +3 -10
  18. mistralai/models/chatmoderationrequest.py +86 -0
  19. mistralai/models/classificationrequest.py +7 -36
  20. mistralai/models/contentchunk.py +8 -1
  21. mistralai/models/documenturlchunk.py +56 -0
  22. mistralai/models/embeddingrequest.py +8 -44
  23. mistralai/models/filepurpose.py +1 -1
  24. mistralai/models/fimcompletionrequest.py +2 -3
  25. mistralai/models/fimcompletionstreamrequest.py +2 -3
  26. mistralai/models/ocrimageobject.py +77 -0
  27. mistralai/models/ocrpagedimensions.py +25 -0
  28. mistralai/models/ocrpageobject.py +64 -0
  29. mistralai/models/ocrrequest.py +97 -0
  30. mistralai/models/ocrresponse.py +26 -0
  31. mistralai/models/ocrusageinfo.py +51 -0
  32. mistralai/models/prediction.py +4 -5
  33. mistralai/models_.py +66 -18
  34. mistralai/ocr.py +248 -0
  35. mistralai/sdk.py +23 -3
  36. mistralai/sdkconfiguration.py +4 -2
  37. mistralai/utils/__init__.py +2 -0
  38. mistralai/utils/serializers.py +10 -6
  39. mistralai/utils/values.py +4 -1
  40. {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/METADATA +70 -19
  41. {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/RECORD +88 -76
  42. {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/WHEEL +1 -1
  43. mistralai_azure/__init__.py +10 -1
  44. mistralai_azure/_hooks/types.py +15 -3
  45. mistralai_azure/_version.py +3 -0
  46. mistralai_azure/basesdk.py +8 -0
  47. mistralai_azure/chat.py +88 -20
  48. mistralai_azure/httpclient.py +52 -0
  49. mistralai_azure/models/__init__.py +7 -0
  50. mistralai_azure/models/assistantmessage.py +2 -0
  51. mistralai_azure/models/chatcompletionrequest.py +8 -10
  52. mistralai_azure/models/chatcompletionstreamrequest.py +8 -10
  53. mistralai_azure/models/function.py +3 -0
  54. mistralai_azure/models/jsonschema.py +61 -0
  55. mistralai_azure/models/prediction.py +25 -0
  56. mistralai_azure/models/responseformat.py +42 -1
  57. mistralai_azure/models/responseformats.py +1 -1
  58. mistralai_azure/models/toolcall.py +3 -0
  59. mistralai_azure/sdk.py +56 -14
  60. mistralai_azure/sdkconfiguration.py +14 -6
  61. mistralai_azure/utils/__init__.py +2 -0
  62. mistralai_azure/utils/serializers.py +10 -6
  63. mistralai_azure/utils/values.py +4 -1
  64. mistralai_gcp/__init__.py +10 -1
  65. mistralai_gcp/_hooks/types.py +15 -3
  66. mistralai_gcp/_version.py +3 -0
  67. mistralai_gcp/basesdk.py +8 -0
  68. mistralai_gcp/chat.py +89 -21
  69. mistralai_gcp/fim.py +61 -21
  70. mistralai_gcp/httpclient.py +52 -0
  71. mistralai_gcp/models/__init__.py +7 -0
  72. mistralai_gcp/models/assistantmessage.py +2 -0
  73. mistralai_gcp/models/chatcompletionrequest.py +8 -10
  74. mistralai_gcp/models/chatcompletionstreamrequest.py +8 -10
  75. mistralai_gcp/models/fimcompletionrequest.py +2 -3
  76. mistralai_gcp/models/fimcompletionstreamrequest.py +2 -3
  77. mistralai_gcp/models/function.py +3 -0
  78. mistralai_gcp/models/jsonschema.py +61 -0
  79. mistralai_gcp/models/prediction.py +25 -0
  80. mistralai_gcp/models/responseformat.py +42 -1
  81. mistralai_gcp/models/responseformats.py +1 -1
  82. mistralai_gcp/models/toolcall.py +3 -0
  83. mistralai_gcp/sdk.py +63 -19
  84. mistralai_gcp/sdkconfiguration.py +14 -6
  85. mistralai_gcp/utils/__init__.py +2 -0
  86. mistralai_gcp/utils/serializers.py +10 -6
  87. mistralai_gcp/utils/values.py +4 -1
  88. mistralai/models/chatclassificationrequest.py +0 -113
  89. {mistralai-1.5.0.dist-info → mistralai-1.5.2rc1.dist-info}/LICENSE +0 -0
@@ -63,7 +63,7 @@ ChatCompletionStreamRequestToolChoice = TypeAliasType(
63
63
 
64
64
 
65
65
  class ChatCompletionStreamRequestTypedDict(TypedDict):
66
- model: Nullable[str]
66
+ model: str
67
67
  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."""
68
68
  messages: List[ChatCompletionStreamRequestMessagesTypedDict]
69
69
  r"""The prompt(s) to generate completions for, encoded as a list of dict with role and content."""
@@ -93,7 +93,7 @@ class ChatCompletionStreamRequestTypedDict(TypedDict):
93
93
 
94
94
 
95
95
  class ChatCompletionStreamRequest(BaseModel):
96
- model: Nullable[str]
96
+ model: str
97
97
  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."""
98
98
 
99
99
  messages: List[ChatCompletionStreamRequestMessages]
@@ -154,14 +154,7 @@ class ChatCompletionStreamRequest(BaseModel):
154
154
  "prediction",
155
155
  "safe_prompt",
156
156
  ]
157
- nullable_fields = [
158
- "model",
159
- "temperature",
160
- "max_tokens",
161
- "random_seed",
162
- "tools",
163
- "n",
164
- ]
157
+ nullable_fields = ["temperature", "max_tokens", "random_seed", "tools", "n"]
165
158
  null_default_fields = []
166
159
 
167
160
  serialized = handler(self)
@@ -0,0 +1,86 @@
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
9
+ from mistralai.utils import get_discriminator
10
+ import pydantic
11
+ from pydantic import Discriminator, Tag
12
+ from typing import List, Optional, Union
13
+ from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
14
+
15
+
16
+ TwoTypedDict = TypeAliasType(
17
+ "TwoTypedDict",
18
+ Union[
19
+ SystemMessageTypedDict,
20
+ UserMessageTypedDict,
21
+ AssistantMessageTypedDict,
22
+ ToolMessageTypedDict,
23
+ ],
24
+ )
25
+
26
+
27
+ Two = Annotated[
28
+ Union[
29
+ Annotated[AssistantMessage, Tag("assistant")],
30
+ Annotated[SystemMessage, Tag("system")],
31
+ Annotated[ToolMessage, Tag("tool")],
32
+ Annotated[UserMessage, Tag("user")],
33
+ ],
34
+ Discriminator(lambda m: get_discriminator(m, "role", "role")),
35
+ ]
36
+
37
+
38
+ OneTypedDict = TypeAliasType(
39
+ "OneTypedDict",
40
+ Union[
41
+ SystemMessageTypedDict,
42
+ UserMessageTypedDict,
43
+ AssistantMessageTypedDict,
44
+ ToolMessageTypedDict,
45
+ ],
46
+ )
47
+
48
+
49
+ One = Annotated[
50
+ Union[
51
+ Annotated[AssistantMessage, Tag("assistant")],
52
+ Annotated[SystemMessage, Tag("system")],
53
+ Annotated[ToolMessage, Tag("tool")],
54
+ Annotated[UserMessage, Tag("user")],
55
+ ],
56
+ Discriminator(lambda m: get_discriminator(m, "role", "role")),
57
+ ]
58
+
59
+
60
+ ChatModerationRequestInputsTypedDict = TypeAliasType(
61
+ "ChatModerationRequestInputsTypedDict",
62
+ Union[List[OneTypedDict], List[List[TwoTypedDict]]],
63
+ )
64
+ r"""Chat to classify"""
65
+
66
+
67
+ ChatModerationRequestInputs = TypeAliasType(
68
+ "ChatModerationRequestInputs", Union[List[One], List[List[Two]]]
69
+ )
70
+ r"""Chat to classify"""
71
+
72
+
73
+ class ChatModerationRequestTypedDict(TypedDict):
74
+ model: str
75
+ inputs: ChatModerationRequestInputsTypedDict
76
+ r"""Chat to classify"""
77
+ truncate_for_context_length: NotRequired[bool]
78
+
79
+
80
+ class ChatModerationRequest(BaseModel):
81
+ model: str
82
+
83
+ inputs: Annotated[ChatModerationRequestInputs, pydantic.Field(alias="input")]
84
+ r"""Chat to classify"""
85
+
86
+ truncate_for_context_length: Optional[bool] = False
@@ -1,11 +1,10 @@
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, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
4
+ from mistralai.types import BaseModel
5
5
  import pydantic
6
- from pydantic import model_serializer
7
6
  from typing import List, Union
8
- from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
7
+ from typing_extensions import Annotated, TypeAliasType, TypedDict
9
8
 
10
9
 
11
10
  ClassificationRequestInputsTypedDict = TypeAliasType(
@@ -21,43 +20,15 @@ r"""Text to classify."""
21
20
 
22
21
 
23
22
  class ClassificationRequestTypedDict(TypedDict):
23
+ model: str
24
+ r"""ID of the model to use."""
24
25
  inputs: ClassificationRequestInputsTypedDict
25
26
  r"""Text to classify."""
26
- model: NotRequired[Nullable[str]]
27
27
 
28
28
 
29
29
  class ClassificationRequest(BaseModel):
30
+ model: str
31
+ r"""ID of the model to use."""
32
+
30
33
  inputs: Annotated[ClassificationRequestInputs, pydantic.Field(alias="input")]
31
34
  r"""Text to classify."""
32
-
33
- model: OptionalNullable[str] = UNSET
34
-
35
- @model_serializer(mode="wrap")
36
- def serialize_model(self, handler):
37
- optional_fields = ["model"]
38
- nullable_fields = ["model"]
39
- null_default_fields = []
40
-
41
- serialized = handler(self)
42
-
43
- m = {}
44
-
45
- for n, f in self.model_fields.items():
46
- k = f.alias or n
47
- val = serialized.get(k)
48
- serialized.pop(k, None)
49
-
50
- optional_nullable = k in optional_fields and k in nullable_fields
51
- is_set = (
52
- self.__pydantic_fields_set__.intersection({n})
53
- or k in null_default_fields
54
- ) # pylint: disable=no-member
55
-
56
- if val is not None and val != UNSET_SENTINEL:
57
- m[k] = val
58
- elif val != UNSET_SENTINEL and (
59
- not k in optional_fields or (optional_nullable and is_set)
60
- ):
61
- m[k] = val
62
-
63
- return m
@@ -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[TextChunkTypedDict, ImageURLChunkTypedDict, ReferenceChunkTypedDict],
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,56 @@
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 import Literal, Optional
7
+ from typing_extensions import NotRequired, TypedDict
8
+
9
+
10
+ DocumentURLChunkType = Literal["document_url"]
11
+
12
+
13
+ class DocumentURLChunkTypedDict(TypedDict):
14
+ document_url: str
15
+ document_name: NotRequired[Nullable[str]]
16
+ r"""The filename of the document"""
17
+ type: NotRequired[DocumentURLChunkType]
18
+
19
+
20
+ class DocumentURLChunk(BaseModel):
21
+ document_url: str
22
+
23
+ document_name: OptionalNullable[str] = UNSET
24
+ r"""The filename of the document"""
25
+
26
+ type: Optional[DocumentURLChunkType] = "document_url"
27
+
28
+ @model_serializer(mode="wrap")
29
+ def serialize_model(self, handler):
30
+ optional_fields = ["document_name", "type"]
31
+ nullable_fields = ["document_name"]
32
+ null_default_fields = []
33
+
34
+ serialized = handler(self)
35
+
36
+ m = {}
37
+
38
+ for n, f in self.model_fields.items():
39
+ k = f.alias or n
40
+ val = serialized.get(k)
41
+ serialized.pop(k, None)
42
+
43
+ optional_nullable = k in optional_fields and k in nullable_fields
44
+ is_set = (
45
+ self.__pydantic_fields_set__.intersection({n})
46
+ or k in null_default_fields
47
+ ) # pylint: disable=no-member
48
+
49
+ if val is not None and val != UNSET_SENTINEL:
50
+ m[k] = val
51
+ elif val != UNSET_SENTINEL and (
52
+ not k in optional_fields or (optional_nullable and is_set)
53
+ ):
54
+ m[k] = val
55
+
56
+ return m
@@ -1,11 +1,10 @@
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, Nullable, OptionalNullable, UNSET, UNSET_SENTINEL
4
+ from mistralai.types import BaseModel
5
5
  import pydantic
6
- from pydantic import model_serializer
7
- from typing import List, Optional, Union
8
- from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
6
+ from typing import List, Union
7
+ from typing_extensions import Annotated, TypeAliasType, TypedDict
9
8
 
10
9
 
11
10
  InputsTypedDict = TypeAliasType("InputsTypedDict", Union[str, List[str]])
@@ -17,50 +16,15 @@ r"""Text to embed."""
17
16
 
18
17
 
19
18
  class EmbeddingRequestTypedDict(TypedDict):
19
+ model: str
20
+ r"""ID of the model to use."""
20
21
  inputs: InputsTypedDict
21
22
  r"""Text to embed."""
22
- model: NotRequired[str]
23
- 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):
29
- inputs: Annotated[Inputs, pydantic.Field(alias="input")]
30
- r"""Text to embed."""
31
-
32
- model: Optional[str] = "mistral-embed"
26
+ model: str
33
27
  r"""ID of the model to use."""
34
28
 
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
29
+ inputs: Annotated[Inputs, pydantic.Field(alias="input")]
30
+ r"""Text to embed."""
@@ -5,4 +5,4 @@ from mistralai.types import UnrecognizedStr
5
5
  from typing import Literal, Union
6
6
 
7
7
 
8
- FilePurpose = Union[Literal["fine-tune", "batch"], UnrecognizedStr]
8
+ FilePurpose = Union[Literal["fine-tune", "batch", "ocr"], UnrecognizedStr]
@@ -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: Nullable[str]
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: Nullable[str]
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: Nullable[str]
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: Nullable[str]
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,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