module
AI::ProviderUtils
Defined in:
ai/provider_utils/delay.crai/provider_utils/generate_id.cr
ai/provider_utils/http.cr
ai/provider_utils/load_settings.cr
ai/provider_utils/media_type.cr
ai/provider_utils/parse_json.cr
ai/provider_utils/provider_utils.cr
ai/provider_utils/remove_undefined_entries.cr
ai/provider_utils/resolve.cr
ai/provider_utils/uint8_utils.cr
ai/provider_utils/url.cr
Constant Summary
-
VERSION =
"0.1.0"
Class Method Summary
-
.combine_headers(*headers : Hash(String, String | Nil) | Nil) : Hash(String, String)
Combines multiple header hashes into one, with lowercase keys and no nil values.
-
.convert_uint8_array_to_base64(array : Bytes) : String
Converts a Uint8Array (Bytes) to a base64 string.
-
.convert_uint8_array_to_hex(array : Bytes) : String
Converts a Uint8Array (Bytes) to a hex string.
-
.convert_uint8_array_to_utf8(array : Bytes) : String
Converts a Uint8Array (Bytes) to a UTF-8 string.
-
.convert_utf8_to_uint8_array(string : String) : Bytes
Converts a UTF-8 string to a Uint8Array (Bytes).
-
.create_id_generator(prefix : String | Nil = nil, size : Int32 = 16, alphabet : String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator : String = "-") : Proc(String)
Creates an ID generator.
-
.delay(delay_in_ms : Int32 | Float64 | Nil) : Nil
Creates a delay for a specified duration in milliseconds.
-
.generate_id : String
Generates a 16-character random string to use for IDs.
-
.load_api_key(api_key : String | Nil, environment_variable_name : String, description : String, api_key_parameter_name : String = "api_key") : String
Loads an API key from a parameter or environment variable.
-
.load_optional_setting(setting_value : String | Nil, environment_variable_name : String) : String | Nil
Loads an optional string setting from a parameter or environment variable.
-
.load_setting(setting_value : String | Nil, environment_variable_name : String, setting_name : String, description : String) : String
Loads a string setting from a parameter or environment variable.
-
.media_type_to_extension(media_type : String) : String
Maps a media type to its corresponding file extension.
-
.normalize_headers(headers : Hash(String, String | Nil) | Nil) : Hash(String, String)
Normalizes headers by converting keys to lowercase and removing nil values.
-
.parse_json(text : String) : JSON::Any
Parses a JSON string and returns a JSON::Any object.
-
.remove_undefined_entries(hash : Hash(K, V | Nil)) : Hash(K, V) forall K, V
Removes entries from a hash where the value is nil.
-
.resolve(value : Proc(T)) : T forall T
Resolves a value that is a function.
-
.resolve(value : T) : T forall T
Resolves a value that is a constant.
-
.without_trailing_slash(url : String | Nil) : String | Nil
Removes a trailing slash from a URL string.
Class Method Detail
Combines multiple header hashes into one, with lowercase keys and no nil values. Later hashes override earlier ones.
Converts a Uint8Array (Bytes) to a base64 string.
Converts a Uint8Array (Bytes) to a hex string.
Converts a Uint8Array (Bytes) to a UTF-8 string.
Converts a UTF-8 string to a Uint8Array (Bytes).
Creates an ID generator. The total length of the ID is the sum of the prefix, separator, and random part length. Not cryptographically secure.
Creates a delay for a specified duration in milliseconds. @param delay_in_ms - The delay duration in milliseconds. If nil, resolves immediately.
Generates a 16-character random string to use for IDs. Not cryptographically secure.
Loads an API key from a parameter or environment variable.
Loads an optional string setting from a parameter or environment variable.
Loads a string setting from a parameter or environment variable.
Maps a media type to its corresponding file extension.
Normalizes headers by converting keys to lowercase and removing nil values.
Parses a JSON string and returns a JSON::Any object. @param text - The JSON string to parse. @throws {JSONParseError} - If the JSON string is invalid.
Removes entries from a hash where the value is nil. @param hash - The input hash whose entries may be nil. @returns A new hash containing only entries with non-nil values.
Removes a trailing slash from a URL string.