Table of Contents

Class ContentRequestExtensions

Namespace
GenerativeAI
Assembly
GenerativeAI.dll

Contains extension methods for working with objects implementing IContentsRequest.

public static class ContentRequestExtensions
Inheritance
ContentRequestExtensions
Inherited Members

Methods

AddContent(IContentsRequest, Content)

Adds a new Content object to the IContentsRequest.

public static void AddContent(this IContentsRequest request, Content content)

Parameters

request IContentsRequest

The IContentsRequest instance to which the Content will be added.

content Content

The Content object to add to the request.

AddInlineData(IContentsRequest, string, string, bool, string)

Adds inline data such as an image or audio file into the latest Content in the IContentsRequest and associates it with the specified role.

public static void AddInlineData(this IContentsRequest request, string data, string mimeType, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the inline data will be added.

data string

The inline data to include, represented as a base64-encoded string.

mimeType string

The MIME type of the inline data.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the inline data. Defaults to User.

AddInlineFile(IContentsRequest, string, bool, string)

Adds a new Content that includes an inline file as a Part to the IContentsRequest.

public static void AddInlineFile(this IContentsRequest request, string filePath, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the inline file will be added.

filePath string

The file path of the inline file to be added.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the inline file. Defaults to User.

AddPart(IContentsRequest, Part, bool, string)

Adds a specific Part to the latest Content in the IContentsRequest. If no Content exists, a new one is created with the provided Part.

public static void AddPart(this IContentsRequest request, Part part, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the Part is added.

part Part

The Part to add.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the Part. Defaults to User.

AddParts(IContentsRequest, IEnumerable<Part>, bool, string)

Adds a collection of Part objects to the latest Content in the IContentsRequest with the specified role. If no Content exists, a new one is created with the provided Part collection.

public static void AddParts(this IContentsRequest request, IEnumerable<Part> parts, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the Part objects will be added.

parts IEnumerable<Part>

The collection of Part objects to add.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the Part objects. Defaults to User.

AddRemoteFile(GenerateContentRequest, RemoteFile, bool, string)

Adds a remote file to the IContentsRequest using a RemoteFile object.

public static void AddRemoteFile(this GenerateContentRequest request, RemoteFile file, bool appendToLastContent = true, string role = "user")

Parameters

request GenerateContentRequest

The IContentsRequest instance to which the remote file will be added.

file RemoteFile

The RemoteFile object to be added.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the remote file. Defaults to User.

AddRemoteFile(IContentsRequest, RemoteFile, bool, string)

Adds a remote file to the IContentsRequest using a RemoteFile object.

public static void AddRemoteFile(this IContentsRequest request, RemoteFile file, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the remote file will be added.

file RemoteFile

The RemoteFile object to be added.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the remote file. Defaults to User.

AddRemoteFile(IContentsRequest, string, string, bool, string)

Adds a remote file to the IContentsRequest using a URL and MIME type.

public static void AddRemoteFile(this IContentsRequest request, string url, string mimeType, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the remote file will be added.

url string

The URL of the remote file to be added.

mimeType string

The MIME type of the remote file. Must be one of the supported formats defined in SupportedMimeTypes.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the remote file. Defaults to User.

AddText(IContentsRequest, string, bool, string)

Adds a single text Part to the IContentsRequest with the specified role.

public static void AddText(this IContentsRequest request, string text, bool appendToLastContent = true, string role = "user")

Parameters

request IContentsRequest

The IContentsRequest instance to which the text Part will be added.

text string

The text content to add as a Part.

appendToLastContent bool

Indicates whether to append the Part to the latest Content or Create a new Content

role string

The role associated with the text Part. Defaults to User.