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
urlstringThe 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
operationIdstringThe 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
operationIdstringThe 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
contentNamestringThe 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
inputstringThe 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
corporaNamestringThe 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
fileNamestringThe 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
modelNamestringThe 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
corpusNamestringThe 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
fileNamestringThe 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
modelNamestringThe 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/".