| import base64 | |
| import unittest | |
| from deepseek_vision.api import decode_image_data_url, extract_multimodal_message | |
| class ApiPayloadTests(unittest.TestCase): | |
| def test_openai_multimodal_message_is_extracted(self): | |
| image = b"fake-png" | |
| encoded = base64.b64encode(image).decode() | |
| prompt, decoded, suffix = extract_multimodal_message( | |
| { | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": [ | |
| {"type": "text", "text": "What is this?"}, | |
| { | |
| "type": "image_url", | |
| "image_url": {"url": f"data:image/png;base64,{encoded}"}, | |
| }, | |
| ], | |
| } | |
| ] | |
| } | |
| ) | |
| self.assertEqual(prompt, "What is this?") | |
| self.assertEqual(decoded, image) | |
| self.assertEqual(suffix, ".png") | |
| def test_remote_image_urls_are_rejected(self): | |
| with self.assertRaisesRegex(ValueError, "base64 data:image URL"): | |
| decode_image_data_url("https://example.com/image.png") | |
| def test_exactly_one_image_is_required(self): | |
| with self.assertRaisesRegex(ValueError, "exactly one image_url"): | |
| extract_multimodal_message( | |
| { | |
| "messages": [ | |
| { | |
| "role": "user", | |
| "content": [{"type": "text", "text": "What is this?"}], | |
| } | |
| ] | |
| } | |
| ) | |
| if __name__ == "__main__": | |
| unittest.main() | |
Xet Storage Details
- Size:
- 1.69 kB
- Xet hash:
- 535e705cc12adb6758401634650e1b2486da3201df1f4a6805b73e8e4edf5303
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.