2020
2121
2222class PixtralImageSource (BaseModel ):
23- """Raw bytes payload for an image."""
23+ """Raw bytes payload for an image.
24+
25+ Attributes:
26+ bytes_ (bytes): Raw image bytes.
27+ """
2428
2529 bytes_ : bytes = Field (alias = "bytes" )
2630
2731
2832class PixtralImage (BaseModel ):
29- """Image content block containing its format and raw bytes source."""
33+ """Image content block containing its format and raw bytes source.
34+
35+ Attributes:
36+ format_ (str): Image format (e.g., 'jpeg').
37+ source (PixtralImageSource): Container for image bytes.
38+ """
3039
3140 format_ : str = Field (alias = "format" )
3241 source : PixtralImageSource
3342
3443
3544class PixtralMessage (BaseModel ):
36- """A single content block in a Pixtral conversation, either text or image."""
45+ """A single content block in a Pixtral conversation, either text or image.
46+
47+ Attributes:
48+ text (str | None): Text content, or None if image is provided.
49+ image (PixtralImage | None): Image content, or None if text is provided.
50+ """
3751
3852 text : str | None = None
3953 image : PixtralImage | None = None
@@ -47,20 +61,33 @@ def at_least_one_field(self):
4761
4862
4963class PixtralMessageStack (BaseModel ):
50- """A full conversation turn with a role (e.g. 'user') and a list of content blocks."""
64+ """A full conversation turn with a role and a list of content blocks.
65+
66+ Attributes:
67+ role (str): Role identifier (e.g., 'user').
68+ content (list[PixtralMessage]): List of content blocks in this turn.
69+ """
5170
5271 role : str
5372 content : list [PixtralMessage ]
5473
5574
5675class PixtralResponseOutput (BaseModel ):
57- """The output field of response, wrapping the assistant message."""
76+ """The output field of a response, wrapping the assistant message.
77+
78+ Attributes:
79+ message (PixtralMessageStack): The assistant's response message.
80+ """
5881
5982 message : PixtralMessageStack
6083
6184
6285class PixtralResponse (BaseModel ):
63- """Top-level response, containing the model output."""
86+ """Top-level response containing the model output.
87+
88+ Attributes:
89+ output (PixtralResponseOutput): Response output wrapper.
90+ """
6491
6592 output : PixtralResponseOutput
6693
@@ -92,8 +119,15 @@ def acquire(self):
92119 time .sleep (0.01 )
93120
94121
95- def is_throttle_error (e ) -> bool :
96- """Determine whether a boto3 ClientError is a throttling or overload error."""
122+ def is_throttle_error (e : ClientError ) -> bool :
123+ """Determine whether a boto3 ClientError is a throttling or overload error.
124+
125+ Args:
126+ e (ClientError): A boto3 ClientError exception.
127+
128+ Returns:
129+ bool: True if the error is a throttling/overload error, False otherwise.
130+ """
97131 try :
98132 code = e .response ["Error" ]["Code" ]
99133 if code in {
@@ -145,6 +179,9 @@ def _send_conversation(self, message: PixtralMessageStack, system: PixtralMessag
145179
146180 Returns:
147181 PixtralResponse: The validated model response.
182+
183+ Raises:
184+ ClientError: If API call fails after max retries.
148185 """
149186 attempt = 0
150187 while True :
@@ -221,15 +258,15 @@ def __init__(
221258 def determine_class (
222259 self , page : pymupdf .Page , page_number : int , context_builder : Callable [[], PageContext ] = None , ** kwargs
223260 ) -> PageClasses :
224- """Determines the class of a document page using the Pixtral model.
261+ """Determine the page class using Pixtral vision model.
225262
226- Falls back to treebased classifier if output is malformed or ClientError .
263+ Falls back to fallback classifier if output is malformed or API error occurs .
227264
228265 Args:
229- page (pymupdf.Page): The page of the document that should be classified
230- page_number (int): the Page number of the page that should be classified
266+ page (pymupdf.Page): The PDF page to classify.
267+ page_number (int): The page number.
231268 context_builder (Callable): Builds page context (e.g., text blocks, lines) for fallback classifier.
232- **kwargs: Additionally passed unused arguments
269+ **kwargs: Additionally passed arguments if needed.
233270
234271 Returns:
235272 PageClasses: The predicted page class.
@@ -272,10 +309,10 @@ def _build_conversation(self, image_bytes: bytes) -> PixtralMessageStack:
272309 """Build the user message containing few-shot examples and the target image.
273310
274311 Args:
275- image_bytes: Encoded bytes of the page to classify.
312+ image_bytes (bytes): JPEG-encoded bytes of the page to classify.
276313
277314 Returns:
278- PixtralMessageStack: A user turn ready to send.
315+ PixtralMessageStack: A user turn ready to send to the model .
279316 """
280317 # List of examples for pixtral model
281318 content_examples = [
0 commit comments