module

AI::ProviderUtils

Constants

VERSION = "0.1.0"

Class methods

combine_headers(*headers : Hash(String, String | Nil) | Nil) : Hash(String, String)

Combines multiple header hashes into one, with lowercase keys and no nil values. Later hashes override earlier ones.

Source
convert_uint8_array_to_base64(array : Bytes) : String

Converts a Uint8Array (Bytes) to a base64 string.

Source
convert_uint8_array_to_hex(array : Bytes) : String

Converts a Uint8Array (Bytes) to a hex string.

Source
convert_uint8_array_to_utf8(array : Bytes) : String

Converts a Uint8Array (Bytes) to a UTF-8 string.

Source
convert_utf8_to_uint8_array(string : String) : Bytes

Converts a UTF-8 string to a Uint8Array (Bytes).

Source
create_id_generator(prefix : String | Nil = nil, size : Int32 = 16, alphabet : String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator : String = "-") : Proc(String)

Creates an ID generator. The total length of the ID is the sum of the prefix, separator, and random part length. Not cryptographically secure.

Source
delay(delay_in_ms : Int32 | Float64 | Nil) : Nil

Creates a delay for a specified duration in milliseconds. @param delay_in_ms - The delay duration in milliseconds. If nil, resolves immediately.

Source
generate_id

Generates a 16-character random string to use for IDs. Not cryptographically secure.

Source
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.

Source
load_optional_setting(setting_value : String | Nil, environment_variable_name : String) : String | Nil

Loads an optional string setting from a parameter or environment variable.

Source
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.

Source
media_type_to_extension(media_type : String) : String

Maps a media type to its corresponding file extension.

Source
normalize_headers(headers : Hash(String, String | Nil) | Nil) : Hash(String, String)

Normalizes headers by converting keys to lowercase and removing nil values.

Source
parse_json(text : String) : JSON::Any

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.

Source
remove_undefined_entries(hash : Hash(K, V | Nil)) : Hash(K, V) forall K, V

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.

Source
resolve(value : Proc(T)) : T forall T

Resolves a value that is a function.

Source
resolve(value : T) : T forall T

Resolves a value that is a constant.

Source
without_trailing_slash(url : String | Nil) : String | Nil

Removes a trailing slash from a URL string.

Source