module AI::ProviderUtils

Defined in:

ai/provider_utils/delay.cr
ai/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

Class Method Detail

def self.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.


[View source]
def self.convert_uint8_array_to_base64(array : Bytes) : String #

Converts a Uint8Array (Bytes) to a base64 string.


[View source]
def self.convert_uint8_array_to_hex(array : Bytes) : String #

Converts a Uint8Array (Bytes) to a hex string.


[View source]
def self.convert_uint8_array_to_utf8(array : Bytes) : String #

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


[View source]
def self.convert_utf8_to_uint8_array(string : String) : Bytes #

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


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.generate_id : String #

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


[View source]
def self.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.


[View source]
def self.load_optional_setting(setting_value : String | Nil, environment_variable_name : String) : String | Nil #

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


[View source]
def self.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.


[View source]
def self.media_type_to_extension(media_type : String) : String #

Maps a media type to its corresponding file extension.


[View source]
def self.normalize_headers(headers : Hash(String, String | Nil) | Nil) : Hash(String, String) #

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


[View source]
def self.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.


[View source]
def self.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.


[View source]
def self.resolve(value : Proc(T)) : T forall T #

Resolves a value that is a function.


[View source]
def self.resolve(value : T) : T forall T #

Resolves a value that is a constant.


[View source]
def self.without_trailing_slash(url : String | Nil) : String | Nil #

Removes a trailing slash from a URL string.


[View source]