Class ContentExtensions
- Namespace
- GenerativeAI
- Assembly
- GenerativeAI.dll
Provides extension methods for the Content class, allowing operations such as adding parts, handling inline and remote files, adding text, and extracting code or JSON blocks.
public static class ContentExtensions
- Inheritance
-
ContentExtensions
- Inherited Members
Methods
AddInlineData(Content, string, string)
public static void AddInlineData(this Content content, string data, string mimeType)
Parameters
contentContentThe Content to which the inline data will be added.
datastringThe base64-encoded data to include.
mimeTypestringThe MIME type of the data.
AddInlineFile(Content, string, string)
Adds a file as inline base64-encoded data to the content.
public static void AddInlineFile(this Content content, string filePath, string role)
Parameters
contentContentThe content to add the file to.
filePathstringThe path to the file to add.
rolestringThe role parameter (currently unused but kept for interface compatibility).
Exceptions
- ArgumentException
Thrown when content is null.
AddPart(Content, Part)
public static void AddPart(this Content content, Part part)
Parameters
AddParts(Content, IEnumerable<Part>)
public static void AddParts(this Content content, IEnumerable<Part> parts)
Parameters
contentContentpartsIEnumerable<Part>The collection of Part objects to add.
AddRemoteFile(Content, RemoteFile)
Adds a remote file to the GenerateContentRequest using its URL and MIME type.
public static void AddRemoteFile(this Content request, RemoteFile file)
Parameters
requestContentThe GenerateContentRequest to which the remote file will be added.
fileRemoteFileThe RemoteFile to be added.
AddRemoteFile(Content, string, string)
public static void AddRemoteFile(this Content content, string fileUri, string mimeType)
Parameters
contentContentThe Content to which the remote file reference will be added.
fileUristringThe URL of the remote file.
mimeTypestringThe MIME type of the remote file.
AddText(Content, string)
public static void AddText(this Content content, string text)
Parameters
ExtractCodeBlocks(Content)
public static List<CodeBlock> ExtractCodeBlocks(this Content content)
Parameters
Returns
ExtractJsonBlocks(Content)
public static List<JsonBlock> ExtractJsonBlocks(this Content content)
Parameters
Returns
ToObject<T>(Content, JsonSerializerOptions?)
Converts the JSON content of a Content object into an instance of the specified type.
public static T? ToObject<T>(this Content content, JsonSerializerOptions? options = null) where T : class
Parameters
contentContentThe Content object containing JSON data to be converted.
optionsJsonSerializerOptionsThe JsonSerializerOptions to customize the deserialization process, or null to use default options.
Returns
- T
An instance of type
Tif conversion succeeds, or null if no valid JSON data is found or deserialization fails.
Type Parameters
TThe target type to which the JSON content will be deserialized. Must be a class.
Remarks
For NativeAOT/Trimming JsonSerializerOptions are required, you can ignore it if you have already specified a resolver in