Multimedia Input
Because sometimes words aren't enough—your AI needs to see what's in your fridge too.
Local Files
// Using cross_file for cross-platform support
import 'package:cross_file/cross_file.dart';
final agent = Agent('openai');
// Text file
final bioFile = XFile.fromData(
await File('bio.txt').readAsBytes(),
path: 'bio.txt',
);
final result = await agent.send(
'Can you summarize the attached file?',
attachments: [await DataPart.fromFile(bioFile)],
);
// Image file (the moment of truth)
final fridgeFile = XFile.fromData(
await File('fridge.png').readAsBytes(),
path: 'fridge.png',
);
final result = await agent.send(
'What food do I have on hand?',
attachments: [await DataPart.fromFile(fridgeFile)],
);
// "I see leftover pizza, expired milk, and... is that a science experiment?"
Download from URL
// Download and include file from URL
final urlData = await DataPart.url(
Uri.parse('https://example.com/document.pdf'),
);
final result = await agent.send(
'Summarize this document',
attachments: [urlData],
);
Raw Bytes
// Include raw bytes with mime type
final bytes = Uint8List.fromList([/* your data */]);
final rawData = DataPart(
bytes: bytes,
mimeType: 'application/pdf',
);
final result = await agent.send(
'Process this data',
attachments: [rawData],
);
Web URLs
// Direct URL reference (OpenAI)
final result = await agent.send(
'Describe this image',
attachments: [
LinkPart(Uri.parse('https://example.com/image.jpg')),
],
);
Multiple Attachments
// Mix text and images
final result = await agent.send(
'Based on the bio and fridge contents, suggest a meal',
attachments: [
await DataPart.fromFile(bioFile),
await DataPart.fromFile(fridgeFile),
],
);
Next Steps
- Providers - Check multimedia support
- Streaming Output - Stream with attachments