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) ⇒ Client
constructor
Initialize a new VibeSort client.
-
#sort(array) ⇒ Hash
Sort an array of numbers and/or strings using OpenAI API.
Constructor Details
#initialize(api_key:, temperature: 0.0) ⇒ Client
Initialize a new VibeSort client
16 17 18 |
# File 'lib/vibe_sort/client.rb', line 16 def initialize(api_key:, temperature: 0.0) @config = Configuration.new(api_key: api_key, temperature: temperature) 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 OpenAI API
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/vibe_sort/client.rb', line 47 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.message}" } end |