Interface IGenerativeModel
- Namespace
- GenerativeAI
- Assembly
- GenerativeAI.dll
Defines the contract for a generative AI model. This interface provides methods for generating answers and content, streaming content, and counting tokens within inputs or outputs. It also includes properties for configuring behavior related to grounding, external tools, and advanced options such as JSON mode or function calling.
public interface IGenerativeModel
- Extension Methods
Properties
FunctionCallingBehaviour
Defines the behavior for function calling within the generative model.
FunctionCallingBehaviour FunctionCallingBehaviour { get; set; }
Property Value
UseCodeExecutionTool
Indicates whether the code execution tool is enabled.
bool UseCodeExecutionTool { get; set; }
Property Value
UseGoogleSearch
Specifies whether the Google Search integration is enabled.
bool UseGoogleSearch { get; set; }
Property Value
UseGrounding
Determines whether grounding is enabled.
bool UseGrounding { get; set; }
Property Value
UseJsonMode
Determines whether JSON mode is enabled. Incompatible with grounding, Google Search, and code execution tools.
bool UseJsonMode { get; set; }
Property Value
Methods
CountTokensAsync(CountTokensRequest, CancellationToken)
Counts tokens asynchronously based on the provided request.
Task<CountTokensResponse> CountTokensAsync(CountTokensRequest request, CancellationToken cancellationToken = default)
Parameters
requestCountTokensRequestAn instance of CountTokensRequest containing the content or parameters for token counting.
cancellationTokenCancellationTokenA cancellation token for monitoring cancellation requests.
Returns
- Task<CountTokensResponse>
Returns a CountTokensResponse containing details of the token count.
CountTokensAsync(GenerateContentRequest, CancellationToken)
Counts the number of tokens in the specified content asynchronously.
Task<CountTokensResponse> CountTokensAsync(GenerateContentRequest generateContentRequest, CancellationToken cancellationToken = default)
Parameters
generateContentRequestGenerateContentRequestAn instance of GenerateContentRequest containing the details of the content for which tokens are to be counted.
cancellationTokenCancellationTokenA cancellation token that can be used to observe while waiting for the asynchronous operation to complete.
Returns
- Task<CountTokensResponse>
A CountTokensResponse containing the result of the token count operation.
CountTokensAsync(IEnumerable<Content>, CancellationToken)
Asynchronously counts the tokens in the given contents.
Task<CountTokensResponse> CountTokensAsync(IEnumerable<Content> contents, CancellationToken cancellationToken = default)
Parameters
contentsIEnumerable<Content>A collection of Content objects representing the input for which tokens need to be counted.
cancellationTokenCancellationTokenA cancellation token to observe while waiting for the task to complete.
Returns
- Task<CountTokensResponse>
A task that represents the asynchronous operation. The task result contains the CountTokensResponse with the resulting token count.
CountTokensAsync(IEnumerable<Part>, CancellationToken)
Asynchronously counts the tokens in the provided collection of parts.
Task<CountTokensResponse> CountTokensAsync(IEnumerable<Part> parts, CancellationToken cancellationToken = default)
Parameters
partsIEnumerable<Part>A collection of Part objects representing the input data for token counting.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the token counting operation.
Returns
- Task<CountTokensResponse>
A task representing the asynchronous operation, containing a CountTokensResponse with the token counting results.
GenerateAnswerAsync(GenerateAnswerRequest, CancellationToken)
Generates an answer asynchronously based on the provided request.
Task<GenerateAnswerResponse> GenerateAnswerAsync(GenerateAnswerRequest request, CancellationToken cancellationToken = default)
Parameters
requestGenerateAnswerRequestThe request containing the input details for generating an answer.
cancellationTokenCancellationTokenA cancellation token that can be used by other objects or threads to receive notice of cancellation.
Returns
- Task<GenerateAnswerResponse>
Returns a GenerateAnswerResponse containing the generated answer and additional context.
- See Also
GenerateContentAsync(GenerateContentRequest, CancellationToken)
Generates content asynchronously based on the given input parameters.
Task<GenerateContentResponse> GenerateContentAsync(GenerateContentRequest request, CancellationToken cancellationToken = default)
Parameters
requestGenerateContentRequestAn instance of GenerateContentRequest containing the input configuration and settings for content generation.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<GenerateContentResponse>
A task that represents the asynchronous operation, containing the GenerateContentResponse with the generated content.
- See Also
GenerateContentAsync(IEnumerable<Part>, CancellationToken)
Generate content based on a sequence of Part objects.
Task<GenerateContentResponse> GenerateContentAsync(IEnumerable<Part> parts, CancellationToken cancellationToken = default)
Parameters
partsIEnumerable<Part>The sequence of Part objects to be used for generating content.
cancellationTokenCancellationTokenA token for cancelling the operation, if needed.
Returns
- Task<GenerateContentResponse>
Returns an instance of GenerateContentResponse containing the generated content.
- See Also
GenerateContentAsync(string, string, string, CancellationToken)
Generates content asynchronously based on the provided text prompt and an inline file path.
Task<GenerateContentResponse> GenerateContentAsync(string prompt, string fileUri, string mimeType, CancellationToken cancellationToken = default)
Parameters
promptstringThe input text prompt used for generating content.
fileUristringThe URI to an file that should be included in the content generation request.
mimeTypestringThe MIME type of the file specified in fileUri.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<GenerateContentResponse>
A task that represents the asynchronous operation, containing the GenerateContentResponse or null if content generation fails.
- See Also
GenerateContentAsync(string, CancellationToken)
Generates content asynchronously based on the specified text input prompt.
Task<GenerateContentResponse> GenerateContentAsync(string prompt, CancellationToken cancellationToken = default)
Parameters
promptstringThe text input used to generate the content.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<GenerateContentResponse>
A task representing the asynchronous operation, containing the generated content response.
- See Also
GenerateContentAsync<T>(GenerateContentRequest, CancellationToken)
Generates content asynchronously using JSON mode based on the given input parameters and converts the resulting JSON into a C# object of type T.
Task<GenerateContentResponse> GenerateContentAsync<T>(GenerateContentRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
requestGenerateContentRequestAn instance of GenerateContentRequest containing the input configuration and settings for content generation.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<GenerateContentResponse>
A task that represents the asynchronous operation, containing the generated content response of type
T.
Type Parameters
TThe type of C# object to send as JSON schema input in request.
Remarks
Some of the complex data types are not supported such as Dictionary. So make sure to avoid these.
GenerateEnumAsync<T>(GenerateContentRequest, CancellationToken)
Generates an enumerated value asynchronously using Enum mode based on the given input parameters.
Task<T?> GenerateEnumAsync<T>(GenerateContentRequest request, CancellationToken cancellationToken = default) where T : Enum
Parameters
requestGenerateContentRequestAn instance of GenerateContentRequest containing the input configuration and settings for enum generation.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<T>
A task that represents the asynchronous operation, containing the generated enumeration value of type
T.
Type Parameters
TThe enumeration type to convert the resulting JSON into.
GenerateEnumAsync<T>(IEnumerable<Part>, CancellationToken)
Asynchronously generates an enumeration of the specified type T based on the provided parts input.
Task<T?> GenerateEnumAsync<T>(IEnumerable<Part> parts, CancellationToken cancellationToken = default) where T : Enum
Parameters
partsIEnumerable<Part>A collection of Part objects representing the input components for generating the enumeration.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<T>
A task representing the asynchronous operation, containing the generated enumeration of type
T.
Type Parameters
TThe enumeration type to convert the resulting data into. Must be an enumeration.
Remarks
Ensure the type T is an enumeration; non-enumeration types are not supported.
GenerateEnumAsync<T>(string, CancellationToken)
Generates an enumeration asynchronously using Enum mode based on the provided prompt and converts the resulting Enum data into a C# enumeration of type T.
Task<T?> GenerateEnumAsync<T>(string prompt, CancellationToken cancellationToken = default) where T : Enum
Parameters
promptstringThe textual input used to generate an enumeration of type
T.cancellationTokenCancellationTokenToken to monitor for cancellation requests during the asynchronous operation.
Returns
- Task<T>
A task representing the asynchronous operation, containing the generated enumeration of type
T.
Type Parameters
TThe type of C# enumeration to convert the resulting JSON into. Must be an Enum.
Remarks
Some of the complex data types are not supported, such as Dictionary. Ensure that all input and output types conform to the supported JSON conversion structure.
GenerateObjectAsync<T>(GenerateContentRequest, CancellationToken)
Generates content asynchronously using JSON mode based on the given input parameters and converts the resulting JSON into a C# object of type T.
Task<T?> GenerateObjectAsync<T>(GenerateContentRequest request, CancellationToken cancellationToken = default) where T : class
Parameters
requestGenerateContentRequestAn instance of GenerateContentRequest containing the input configuration and settings for content generation.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<T>
A task that represents the asynchronous operation, containing the generated object of type
T.
Type Parameters
TThe type of C# object to convert the resulting JSON into.
Remarks
Some of the complex data types are not supported such as Dictionary. So make sure to avoid these.
GenerateObjectAsync<T>(IEnumerable<Part>, CancellationToken)
Generates content asynchronously using JSON mode based on the specified content generation request parts and converts the resulting JSON into a C# object of type T.
Task<T?> GenerateObjectAsync<T>(IEnumerable<Part> parts, CancellationToken cancellationToken = default) where T : class
Parameters
partsIEnumerable<Part>An enumerable containing the input parts used for generating the content.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<T>
A task that represents the asynchronous operation, containing the generated object of type
T.
Type Parameters
TThe type of C# object to convert the resulting JSON into.
Remarks
Some of the complex data types are not supported such as Dictionary. So make sure to avoid these.
GenerateObjectAsync<T>(string, CancellationToken)
Generates content asynchronously using JSON mode based on the specified text input prompt and converts the resulting JSON into a C# object of type T.
Task<T?> GenerateObjectAsync<T>(string prompt, CancellationToken cancellationToken = default) where T : class
Parameters
promptstringThe text input used to generate the content.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- Task<T>
A task representing the asynchronous operation, containing the generated object of type
T.
Type Parameters
TThe type of C# object to convert the resulting JSON into.
Remarks
Some of the complex data types are not supported such as Dictionary. So make sure to avoid these.
StreamContentAsync(GenerateContentRequest, CancellationToken)
Streams content generation results asynchronously based on a given request and optional cancellation token.
IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(GenerateContentRequest request, CancellationToken cancellationToken = default)
Parameters
requestGenerateContentRequestThe content generation request containing input configurations and options.
cancellationTokenCancellationTokenAn optional token to monitor for cancellation requests.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An asynchronous enumerable of GenerateContentResponse objects containing the streamed generation results.
- See Also
StreamContentAsync(IEnumerable<Content>, CancellationToken)
Streams generated content as an asynchronous enumerable based on the provided request.
IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(IEnumerable<Content> contents, CancellationToken cancellationToken = default)
Parameters
contentsIEnumerable<Content>The contents containing the parameters for content generation.
cancellationTokenCancellationTokenOptional token to cancel the streaming operation.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An asynchronous enumerable of GenerateContentResponse objects.
StreamContentAsync(IEnumerable<Part>, CancellationToken)
Streams content generation based on a GenerateContentRequest asynchronously.
IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(IEnumerable<Part> parts, CancellationToken cancellationToken = default)
Parameters
partsIEnumerable<Part>The Parts containing input parameters for the content generation process.
cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An asynchronous stream of GenerateContentResponse objects representing the generated content.
StreamContentAsync(string, string, string, CancellationToken)
Streams content generation asynchronously based on the given input prompt, file URI, and MIME type.
IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(string prompt, string fileUri, string mimeType, CancellationToken cancellationToken = default)
Parameters
promptstringThe input string used as a prompt for generating and streaming content.
fileUristringThe URI of the file to be used for content generation.
mimeTypestringThe MIME type associated with the provided file URI.
cancellationTokenCancellationTokenToken to monitor for cancellation requests.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An asynchronous enumerable of GenerateContentResponse instances representing the streamed content responses.
- See Also
StreamContentAsync(string, CancellationToken)
Streams content generation based on a string message.
IAsyncEnumerable<GenerateContentResponse> StreamContentAsync(string prompt, CancellationToken cancellationToken = default)
Parameters
promptstringThe input prompt to be processed and streamed.
cancellationTokenCancellationTokenA token to observe for cancellation requests.
Returns
- IAsyncEnumerable<GenerateContentResponse>
An asynchronous enumerable of generated content responses.
- See Also