Class: VibeSort::Client
- Inherits:
-
Object
- Object
- VibeSort::Client
- Defined in:
- lib/vibe_sort/client.rb
Overview
Client is the main public interface for the VibeSort gem
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(api_key:, temperature: 0.0, provider: :openai, model: nil) ⇒ Client
constructor
Initialize a new VibeSort client.
-
#sort(array) ⇒ Hash
Sort an array of numbers and/or strings using the configured provider's API.
Constructor Details
#initialize(api_key:, temperature: 0.0, provider: :openai, model: nil) ⇒ Client
Initialize a new VibeSort client
25 26 27 |
# File 'lib/vibe_sort/client.rb', line 25 def initialize(api_key:, temperature: 0.0, provider: :openai, model: nil) @config = Configuration.new(api_key: api_key, temperature: temperature, provider: provider, model: model) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/vibe_sort/client.rb', line 6 def config @config end |
Instance Method Details
#sort(array) ⇒ Hash
Sort an array of numbers and/or strings using the configured provider's API
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vibe_sort/client.rb', line 57 def sort(array) # Validate input unless valid_input?(array) return { success: false, sorted_array: [], error: "Input must be an array of numbers or strings" } end # Perform the sort via API sorter = Sorter.new(config) sorter.perform(array) rescue ApiError => e { success: false, sorted_array: [], error: e. } rescue StandardError => e { success: false, sorted_array: [], error: "Unexpected error: #{e.}" } end |