Class GenerateContentResponseExtensions
- Namespace
- GenerativeAI
- Assembly
- GenerativeAI.dll
Provides extension methods for the GenerateContentResponse type in the GenerativeAI.Types namespace.
public static class GenerateContentResponseExtensions
- Inheritance
-
GenerateContentResponseExtensions
- Inherited Members
Methods
ExtractCodeBlocks(GenerateContentResponse)
Extracts all code blocks from the provided GenerateContentResponse.
public static List<CodeBlock> ExtractCodeBlocks(this GenerateContentResponse response)
Parameters
responseGenerateContentResponseThe GenerateContentResponse containing potential code blocks.
Returns
- List<CodeBlock>
A list of CodeBlock objects extracted from the response. Returns an empty list if no code blocks are found.
ExtractJsonBlocks(GenerateContentResponse)
Extracts all JSON blocks from the provided GenerateContentResponse.
public static List<JsonBlock> ExtractJsonBlocks(this GenerateContentResponse response)
Parameters
responseGenerateContentResponseThe GenerateContentResponse containing potential JSON blocks.
Returns
- List<JsonBlock>
A list of JsonBlock objects extracted from the response. Returns an empty list if no JSON blocks are found.
GetFunction(GenerateContentResponse?)
Returns the first candidate’s first function call.
public static FunctionCall? GetFunction(this GenerateContentResponse? response)
Parameters
responseGenerateContentResponseThe GenerateContentResponse to process.
Returns
- FunctionCall
The function call if found; otherwise null.
GetFunctions(GenerateContentResponse?)
Returns the first candidate’s first function call.
public static List<FunctionCall>? GetFunctions(this GenerateContentResponse? response)
Parameters
responseGenerateContentResponseThe GenerateContentResponse to process.
Returns
- List<FunctionCall>
The function call if found; otherwise null.
Text(GenerateContentResponse)
Returns the text of the first candidate’s first content part.
public static string? Text(this GenerateContentResponse response)
Parameters
responseGenerateContentResponseThe GenerateContentResponse to process.
Returns
- string
The text if found; otherwise null.
ToEnum<T>(GenerateContentResponse, JsonSerializerOptions?)
Converts the response text to an enum value.
public static T? ToEnum<T>(this GenerateContentResponse response, JsonSerializerOptions? options = null) where T : Enum
Parameters
responseGenerateContentResponseThe response containing the text to convert.
optionsJsonSerializerOptionsOptional JSON serializer options (not used in this implementation).
Returns
- T
The parsed enum value, or the default value if parsing fails.
Type Parameters
TThe enum type to convert to.
ToObject<T>(GenerateContentResponse, JsonSerializerOptions?)
Extracts all JSON blocks from the provided GenerateContentResponse.
public static T? ToObject<T>(this GenerateContentResponse response, JsonSerializerOptions? options = null) where T : class
Parameters
responseGenerateContentResponseThe GenerateContentResponse containing potential JSON blocks.
optionsJsonSerializerOptionsOptional JSON serializer options to use for deserialization.
Returns
- T
A list of JsonBlock objects extracted from the response. Returns an empty list if no JSON blocks are found.
Type Parameters
T
ToObjects<T>(GenerateContentResponse, JsonSerializerOptions?)
Converts JSON blocks contained within the GenerateContentResponse into objects of the specified type.
public static List<T> ToObjects<T>(this GenerateContentResponse response, JsonSerializerOptions? options = null) where T : class
Parameters
responseGenerateContentResponseThe GenerateContentResponse containing JSON blocks to convert.
optionsJsonSerializerOptionsOptional JSON serializer options to use for deserialization.
Returns
- List<T>
A list of objects of type T. Returns an empty list if no JSON blocks are found or successfully converted.
Type Parameters
TThe type to which the JSON blocks are converted.