Table of Contents

Class StringExtensions

Namespace
GenerativeAI
Assembly
GenerativeAI.dll

Provides extension methods for string-related model manipulations.

public static class StringExtensions
Inheritance
StringExtensions
Inherited Members

Methods

MaskApiKey(string)

Masks the API key present in the query string of a URL.

public static string MaskApiKey(this string url)

Parameters

url string

The input URL containing an API key as part of its query parameters. If the key exists, it will be replaced with "Google_API_Key".

Returns

string

A new URL string with the API key masked. If the input URL does not contain a key or the input is null/whitespace, it returns the original URL.

RecoverModelIdFromOperationId(string)

Extracts the model ID from an operation ID string.

public static string RecoverModelIdFromOperationId(this string operationId)

Parameters

operationId string

The operation ID containing the model information.

Returns

string

The extracted model ID.

RecoverOperationId(string)

Ensures an operation ID is in the correct format with "operations/" prefix.

public static string RecoverOperationId(this string operationId)

Parameters

operationId string

The operation ID to format.

Returns

string

The properly formatted operation ID.

ToCachedContentId(string)

Converts a content name or path string into a standardized cached content identifier.

public static string ToCachedContentId(this string contentName)

Parameters

contentName string

The input content name or path. If the string contains a forward slash ('/'), it must start with "cachedContent/" (case-insensitive). Otherwise, the method will prefix the provided name with "cachedContent/".

Returns

string

A string formatted as a valid cached content identifier. If the input string already starts with "cachedContent/" and contains a '/', it will be returned in lowercase.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "cachedContent/".

ToCamelCase(string)

Converts a string into camel case format.

public static string ToCamelCase(this string input)

Parameters

input string

The input string to be converted.

Returns

string

A camel case representation of the input string, or an empty string if the input is null or whitespace.

ToCorpusId(string)

Converts a content name or path string into a standardized corpora content identifier.

public static string ToCorpusId(this string corporaName)

Parameters

corporaName string

The input corpora content name or path. If the string contains a forward slash ('/'), it must start with "corpora/" (case-insensitive). Otherwise, the method will prefix the provided name with "corpora/".

Returns

string

A string formatted as a valid corpora content identifier. If the input string already starts with "corpora/" and contains a '/', it will be returned in lowercase.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "corpora/".

ToFileId(string)

Converts a file name or path string into a standardized file identifier.

public static string ToFileId(this string fileName)

Parameters

fileName string

The input file name or path. If the string contains a forward slash ('/'), it must start with "files/" (case-insensitive). Otherwise, the method will prefix the provided name with "files/".

Returns

string

A string formatted as a valid file identifier. If the input string already starts with "files/" and contains a '/', it will be returned in lowercase.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "files/".

ToModelId(string)

Converts a model name string into a standardized model identifier.

public static string ToModelId(this string modelName)

Parameters

modelName string

The input model name. If the string contains a forward slash ('/'), it must start with "models/" (case-insensitive). Otherwise, the method will prefix the provided name with "models/".

Returns

string

A string formatted as a valid model identifier. If the input string already starts with "models/" and contains a '/', it will be returned in lowercase.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "models/".

ToRagCorpusId(string)

Converts a corpus name string into a standardized corpus identifier.

public static string ToRagCorpusId(this string corpusName)

Parameters

corpusName string

The input corpus name. If the string contains a forward slash ('/'), it must start with "corpora/" (case-insensitive). Otherwise, the method will prefix the provided name with "corpora/".

Returns

string

A string formatted as a valid corpus identifier. If the input string already starts with "corpora/" and contains a '/', it will be returned unchanged.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "corpora/".

ToRagFileId(string)

Converts a file name into a standardized RAG file identifier.

public static string ToRagFileId(this string fileName)

Parameters

fileName string

The input file name. If the string contains a forward slash ('/'), it must start with "corpora/" (case-insensitive). Otherwise, the method will prefix the file name with "corpora/".

Returns

string

A string formatted as a valid RAG file identifier. If the input string already starts with "corpora/" and contains a '/', it will be returned in its original form.

Exceptions

ArgumentException

Thrown if the input string contains a '/' but does not start with "corpora/".

ToTunedModelId(string)

Converts a given model name into a formatted tuned model identifier.

public static string ToTunedModelId(this string modelName)

Parameters

modelName string

The name of the model to convert into a tuned model identifier.

Returns

string

A string representing the tuned model identifier, prefixed with "tunedModels/" if it is not already formatted correctly.

Exceptions

ArgumentException

Thrown when the provided model name is invalid, such as when it contains a "/" but does not start with "tunedModels/".