Multi-media Input

Dartantic supports the inclusion of files, images, and other media as attachments to your prompts. Both OpenAI and Gemini providers can process multimedia content alongside text.

DataPart - Local Files, URL Downloads and Raw Bytes

Use DataPart.file() to include local files (text, images, etc.):

import 'dart:io';
import 'package:dartantic_ai/dartantic_ai.dart';

void main() async {
  final agent = Agent('google');

  // Text file
  final response1 = await agent.run(
    'Can you summarize the attached file?',
    attachments: [await DataPart.file(File('bio.txt'))],
  );
  print(response1.output);

  // Image file
  final response2 = await agent.run(
    'What food do I have on hand?',
    attachments: [await DataPart.file(File('cupboard.jpg'))],
  );
  print(response2.output);
}

In addition, you can use DataPart.url() to download a file from a URL and the standard DataPart constructor to pass in raw bytes and a mime type.

Different providers have different limits on the size of data that you can upload, depending on the model, your billing plan and, of course, royal station (Dukes? large files. Earls? Not so much...)

LinkPart - Web URLs

Use LinkPart() to reference web images:

import 'package:dartantic_ai/dartantic_ai.dart';

void main() async {
  final agent = Agent('openai:gpt-4o');

  final imageUrl = Uri.parse(
    'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/'
    'Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-'
    'Gfp-wisconsin-madison-the-nature-boardwalk.jpg'
  );

  final response = await agent.run(
    'Can you describe this image?',
    attachments: [LinkPart(imageUrl)],
  );
  print(response.output);
}

Different providers may have varying support for specific file types and web URLs. At the time of this writing, Gemini requires files uploaded to Google AI File Service for LinkPart URLs.

You can find a working example in multimedia.dart.