ContentPart class sealed

A part of a multimodal message content.

Content parts allow messages to contain multiple types of content. User messages support text, images, audio, and files. Assistant messages support text and refusal.

Example

final parts = [
  ContentPart.text('What is in this image?'),
  ContentPart.imageUrl(
    'https://example.com/image.jpg',
    detail: ImageDetail.high,
  ),
];

final message = ChatMessage.user(parts);
Implementers
Annotations
  • @immutable

Constructors

ContentPart.fromJson(Map<String, dynamic> json)
Creates a ContentPart from JSON.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
type String
The type of this content part.
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() Map<String, dynamic>
Converts to JSON.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

file({required String fileId, String? filename}) ContentPart
Creates a file content part from an uploaded file ID.
fileData({required String data, required String mediaType, String? filename}) ContentPart
Creates a file content part from base64-encoded file data.
imageBase64({required String data, required String mediaType, ImageDetail? detail}) ContentPart
Creates an image content part from base64-encoded data.
imageUrl(String url, {ImageDetail? detail}) ContentPart
Creates an image URL content part.
inputAudio({required String data, required AudioFormat format}) ContentPart
Creates an audio content part.
refusal(String refusal) ContentPart
Creates a refusal content part.
text(String text) ContentPart
Creates a text content part.