Skip to content

Commit a31feec

Browse files
pintafLoïc POISOT
authored andcommitted
Enable URL and binary PDF for Mistral
I tried to use DocumentURLChunk as it was done for Image, but contrarily to Images where ImageUrl is exported by Mistral sdk, there is no export of DocumentUrl... This has been properly tested with both kinds of PDFs (binary and URL) Happy to change to [Mistral]DocumentURLChunk if you tell me how to make it work because I did not succeed... update mistral deps Update to use MistralDocumentUrlChunk fix linting added document_type fix linting again Update uv.lock
1 parent 7d50564 commit a31feec

File tree

3 files changed

+123
-123
lines changed

3 files changed

+123
-123
lines changed

pydantic_ai_slim/pydantic_ai/models/mistral.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
CompletionChunk as MistralCompletionChunk,
5353
Content as MistralContent,
5454
ContentChunk as MistralContentChunk,
55+
DocumentURLChunk as MistralDocumentURLChunk,
5556
FunctionCall as MistralFunctionCall,
5657
ImageURL as MistralImageURL,
5758
ImageURLChunk as MistralImageURLChunk,
@@ -539,10 +540,19 @@ def _map_user_prompt(self, part: UserPromptPart) -> MistralUserMessage:
539540
if item.is_image:
540541
image_url = MistralImageURL(url=f'data:{item.media_type};base64,{base64_encoded}')
541542
content.append(MistralImageURLChunk(image_url=image_url, type='image_url'))
543+
elif item.media_type == 'application/pdf':
544+
content.append(
545+
MistralDocumentURLChunk(
546+
document_url=f'data:application/pdf;base64,{base64_encoded}', type='document_url'
547+
)
548+
)
542549
else:
543-
raise RuntimeError('Only image binary content is supported for Mistral.')
550+
raise RuntimeError('BinaryContent other than image or PDF is not supported in Mistral.')
544551
elif isinstance(item, DocumentUrl):
545-
raise RuntimeError('DocumentUrl is not supported in Mistral.') # pragma: no cover
552+
if item.media_type == 'application/pdf':
553+
content.append(MistralDocumentURLChunk(document_url=item.url, type='document_url'))
554+
else:
555+
raise RuntimeError('DocumentUrl other than PDF is not supported in Mistral.')
546556
elif isinstance(item, VideoUrl):
547557
raise RuntimeError('VideoUrl is not supported in Mistral.')
548558
else: # pragma: no cover

pydantic_ai_slim/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ vertexai = ["google-auth>=2.36.0", "requests>=2.32.2"]
6868
google = ["google-genai>=1.24.0"]
6969
anthropic = ["anthropic>=0.52.0"]
7070
groq = ["groq>=0.19.0"]
71-
mistral = ["mistralai>=1.2.5"]
71+
mistral = ["mistralai>=1.9.2"]
7272
bedrock = ["boto3>=1.37.24"]
7373
huggingface = ["huggingface-hub[inference]>=0.33.2"]
7474
# Tools

0 commit comments

Comments
 (0)