vibe-sort 0.3.0 โ†’ 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,23 +6,23 @@ VibeSort has been updated to **version 0.2.0** with support for sorting arrays c
6
6
 
7
7
  ---
8
8
 
9
- ## ๐ŸŽฏ What Changed
9
+ ## What Changed
10
10
 
11
11
  ### Core Functionality
12
12
 
13
13
  #### Before (v0.1.0)
14
- - โœ… Sort arrays of numbers (integers and floats)
15
- - โŒ Strings not supported
16
- - โŒ Mixed-type arrays rejected
14
+ - Sort arrays of numbers (integers and floats)
15
+ - Strings not supported
16
+ - Mixed-type arrays rejected
17
17
 
18
18
  #### After (v0.2.0)
19
- - โœ… Sort arrays of numbers (integers and floats)
20
- - โœ… Sort arrays of strings (case-sensitive)
21
- - โœ… Sort mixed-type arrays (numbers + strings)
19
+ - Sort arrays of numbers (integers and floats)
20
+ - Sort arrays of strings (case-sensitive)
21
+ - Sort mixed-type arrays (numbers + strings)
22
22
 
23
23
  ---
24
24
 
25
- ## ๐Ÿ“ Technical Changes
25
+ ## Technical Changes
26
26
 
27
27
  ### 1. Input Validation (`VibeSort::Client`)
28
28
 
@@ -114,7 +114,7 @@ end
114
114
 
115
115
  ---
116
116
 
117
- ## ๐Ÿš€ New Usage Examples
117
+ ## New Usage Examples
118
118
 
119
119
  ### Sorting Strings
120
120
 
@@ -141,24 +141,24 @@ puts result[:sorted_array]
141
141
 
142
142
  ---
143
143
 
144
- ## ๐Ÿ“‹ Sorting Rules
144
+ ## Sorting Rules
145
145
 
146
146
  The AI follows these standard sorting conventions:
147
147
 
148
148
  1. **Numbers Only**: Ascending numerical order
149
- - `[5, 2, 8, 1]` โ†’ `[1, 2, 5, 8]`
149
+ - `[5, 2, 8, 1]` `[1, 2, 5, 8]`
150
150
 
151
151
  2. **Strings Only**: Ascending alphabetical order (case-sensitive)
152
- - `["banana", "Apple", "cherry"]` โ†’ `["Apple", "banana", "cherry"]`
152
+ - `["banana", "Apple", "cherry"]` `["Apple", "banana", "cherry"]`
153
153
  - Capital letters come before lowercase in ASCII ordering
154
154
 
155
155
  3. **Mixed Types**: Numbers first, then strings
156
- - `[42, "hello", 8, "world"]` โ†’ `[8, 42, "hello", "world"]`
156
+ - `[42, "hello", 8, "world"]` `[8, 42, "hello", "world"]`
157
157
  - Each group is sorted within itself
158
158
 
159
159
  ---
160
160
 
161
- ## ๐Ÿ“š Documentation Updates
161
+ ## Documentation Updates
162
162
 
163
163
  ### Updated Files
164
164
 
@@ -185,7 +185,7 @@ The AI follows these standard sorting conventions:
185
185
 
186
186
  ---
187
187
 
188
- ## โœ… Backward Compatibility
188
+ ## Backward Compatibility
189
189
 
190
190
  **Good News:** This update is **fully backward compatible**!
191
191
 
@@ -203,7 +203,7 @@ result = client.sort([5, 2, 8, 1, 9])
203
203
 
204
204
  ---
205
205
 
206
- ## ๐Ÿงช Testing Recommendations
206
+ ## Testing Recommendations
207
207
 
208
208
  When upgrading to v0.2.0, test these scenarios:
209
209
 
@@ -237,7 +237,7 @@ client.sort([1, { key: "value" }]) # Contains hash
237
237
 
238
238
  ---
239
239
 
240
- ## ๐Ÿ” Implementation Notes
240
+ ## Implementation Notes
241
241
 
242
242
  ### Why These Changes?
243
243
 
@@ -263,27 +263,27 @@ The OpenAI GPT model (gpt-3.5-turbo-1106) handles mixed-type sorting intelligent
263
263
 
264
264
  ---
265
265
 
266
- ## ๐ŸŽจ Architecture Remains Clean
266
+ ## Architecture Remains Clean
267
267
 
268
268
  The core architecture is unchanged:
269
269
 
270
270
  ```
271
271
  User Application
272
- โ†“
272
+
273
273
  VibeSort::Client (validates input)
274
- โ†“
274
+
275
275
  VibeSort::Configuration (stores settings)
276
- โ†“
276
+
277
277
  VibeSort::Sorter (communicates with OpenAI)
278
- โ†“
278
+
279
279
  OpenAI API (processes request)
280
- โ†“
280
+
281
281
  Sorted Array (returned to user)
282
282
  ```
283
283
 
284
284
  ---
285
285
 
286
- ## ๐Ÿ“ฆ Upgrade Instructions
286
+ ## Upgrade Instructions
287
287
 
288
288
  ### Using Bundler
289
289
 
@@ -307,7 +307,7 @@ gem install vibe-sort -v 0.2.0
307
307
 
308
308
  ---
309
309
 
310
- ## ๐Ÿ› Known Limitations
310
+ ## Known Limitations
311
311
 
312
312
  Same limitations as v0.1.0:
313
313
 
@@ -326,7 +326,7 @@ Same limitations as v0.1.0:
326
326
 
327
327
  ---
328
328
 
329
- ## ๐Ÿ”ฎ Future Enhancements
329
+ ## Future Enhancements
330
330
 
331
331
  Potential features for future versions:
332
332
 
@@ -348,27 +348,27 @@ Potential features for future versions:
348
348
 
349
349
  ---
350
350
 
351
- ## ๐Ÿ“ž Support
351
+ ## Support
352
352
 
353
- - ๐Ÿ› [Report Issues](https://github.com/chayut/vibe-sort/issues)
354
- - ๐Ÿ’ก [Feature Requests](https://github.com/chayut/vibe-sort/issues/new?labels=enhancement)
355
- - ๐Ÿ“– [Documentation](https://github.com/chayut/vibe-sort/tree/main/docs)
353
+ - [Report Issues](https://github.com/chayut/vibe-sort/issues)
354
+ - [Feature Requests](https://github.com/chayut/vibe-sort/issues/new?labels=enhancement)
355
+ - [Documentation](https://github.com/chayut/vibe-sort/tree/main/docs)
356
356
 
357
357
  ---
358
358
 
359
- ## โœจ Summary
359
+ ## Summary
360
360
 
361
361
  Version 0.2.0 expands VibeSort's capabilities while maintaining:
362
362
 
363
- - โœ… Same clean API
364
- - โœ… Same architecture
365
- - โœ… Full backward compatibility
366
- - โœ… Same performance characteristics
367
- - โœ… Comprehensive documentation
363
+ - Same clean API
364
+ - Same architecture
365
+ - Full backward compatibility
366
+ - Same performance characteristics
367
+ - Comprehensive documentation
368
368
 
369
369
  The gem now handles a wider variety of data types, making it more versatile for educational purposes and demonstrations.
370
370
 
371
- **Happy Sorting!** ๐ŸŒ€
371
+ **Happy Sorting!**
372
372
 
373
373
  ---
374
374
 
@@ -10,20 +10,34 @@ module VibeSort
10
10
  # @param api_key [String] API key for the selected provider
11
11
  # @param temperature [Float] Temperature for the model (default: 0.0).
12
12
  # Ignored by providers whose current models do not accept it (Anthropic).
13
- # @param provider [Symbol, String] LLM provider: :openai (default), :anthropic, or :gemini
13
+ # @param provider [Symbol, String, nil] LLM provider: :openai, :anthropic, :gemini,
14
+ # :groq, :spacexai, or :openrouter. When omitted, the provider is inferred from
15
+ # the api_key prefix (e.g. "sk-ant-..." routes to Anthropic), falling back to
16
+ # :openai for unrecognized key formats.
14
17
  # @param model [String, nil] Model ID override (nil uses the provider's default)
18
+ # @param extra_params [Hash] Provider-native request parameters deep-merged into
19
+ # the request payload last, so they can override anything the adapter builds
15
20
  # @raise [ArgumentError] if api_key or provider is invalid
16
21
  #
17
- # @example OpenAI (default provider)
18
- # client = VibeSort::Client.new(api_key: ENV['OPENAI_API_KEY'])
22
+ # @example Provider inferred from the key prefix
23
+ # client = VibeSort::Client.new(api_key: ENV['ANTHROPIC_API_KEY']) # sk-ant-... => :anthropic
19
24
  #
20
- # @example Anthropic Claude
21
- # client = VibeSort::Client.new(provider: :anthropic, api_key: ENV['ANTHROPIC_API_KEY'])
25
+ # @example OpenAI (explicit)
26
+ # client = VibeSort::Client.new(provider: :openai, api_key: ENV['OPENAI_API_KEY'])
22
27
  #
23
28
  # @example Google Gemini with a custom model
24
29
  # client = VibeSort::Client.new(provider: :gemini, api_key: ENV['GEMINI_API_KEY'], model: 'gemini-2.5-pro')
25
- def initialize(api_key:, temperature: 0.0, provider: :openai, model: nil)
26
- @config = Configuration.new(api_key: api_key, temperature: temperature, provider: provider, model: model)
30
+ #
31
+ # @example OpenRouter with extra request parameters
32
+ # client = VibeSort::Client.new(
33
+ # provider: :openrouter,
34
+ # api_key: ENV['OPENROUTER_API_KEY'],
35
+ # model: 'meta-llama/llama-3.3-70b-instruct',
36
+ # extra_params: { max_tokens: 200 }
37
+ # )
38
+ def initialize(api_key:, temperature: 0.0, provider: nil, model: nil, extra_params: {})
39
+ @config = Configuration.new(api_key: api_key, temperature: temperature, provider: provider, model: model,
40
+ extra_params: extra_params)
27
41
  end
28
42
 
29
43
  # Sort an array of numbers and/or strings using the configured provider's API
@@ -53,7 +67,7 @@ module VibeSort
53
67
  # @example API error
54
68
  # result = client.sort([1, 2, 3]) # with invalid API key
55
69
  # #=> { success: false, sorted_array: [], error: "OpenAI API error: Invalid API key" }
56
- # # The error prefix names the configured provider (OpenAI, Anthropic, or Gemini)
70
+ # # The error prefix names the configured provider (OpenAI, Anthropic, Gemini, ...)
57
71
  def sort(array)
58
72
  # Validate input
59
73
  unless valid_input?(array)
@@ -2,29 +2,53 @@
2
2
 
3
3
  module VibeSort
4
4
  # Configuration class for VibeSort
5
- # Holds provider, API key, model, and temperature settings
5
+ # Holds provider, API key, model, temperature, and extra request parameters
6
6
  class Configuration
7
- PROVIDERS = %i[openai anthropic gemini groq spacexai].freeze
7
+ PROVIDERS = %i[openai anthropic gemini groq spacexai openrouter].freeze
8
8
 
9
- attr_reader :api_key, :temperature, :provider, :model
9
+ attr_reader :api_key, :temperature, :provider, :model, :extra_params
10
10
 
11
11
  # Initialize a new Configuration
12
12
  #
13
13
  # @param api_key [String] API key for the selected provider
14
14
  # @param temperature [Float] Temperature for the model (0.0 to 2.0).
15
15
  # Ignored by providers whose current models do not accept it (Anthropic).
16
- # @param provider [Symbol, String] LLM provider: :openai (default), :anthropic, :gemini, :groq, or :spacexai
16
+ # @param provider [Symbol, String, nil] LLM provider: :openai, :anthropic, :gemini,
17
+ # :groq, :spacexai, or :openrouter. When nil (default), the provider is inferred
18
+ # from the api_key prefix, falling back to :openai for unrecognized keys.
17
19
  # @param model [String, nil] Model ID override (nil uses the provider's default)
20
+ # @param extra_params [Hash] Provider-native request parameters deep-merged into
21
+ # the payload last, so they can override anything (e.g. { max_tokens: 100 })
18
22
  # @raise [ArgumentError] if api_key is nil or empty, or provider is unknown
19
- def initialize(api_key:, temperature: 0.0, provider: :openai, model: nil)
23
+ def initialize(api_key:, temperature: 0.0, provider: nil, model: nil, extra_params: {})
20
24
  raise ArgumentError, "API key cannot be nil or empty" if api_key.nil? || api_key.empty?
21
25
 
22
- @provider = provider.to_s.to_sym
23
- raise ArgumentError, "Unknown provider: #{provider.inspect} (supported: #{PROVIDERS.join(", ")})" unless PROVIDERS.include?(@provider)
24
-
26
+ @provider = resolve_provider(provider, api_key)
25
27
  @api_key = api_key
26
28
  @temperature = temperature
27
29
  @model = model
30
+ @extra_params = extra_params
31
+ end
32
+
33
+ private
34
+
35
+ # Resolve the provider: explicit argument wins (with a non-fatal warning if the
36
+ # key prefix suggests a different provider); otherwise infer from the key prefix,
37
+ # defaulting to :openai for unrecognized formats.
38
+ #
39
+ # @param provider [Symbol, String, nil] Explicit provider argument, if any
40
+ # @param api_key [String] API key used for prefix inference
41
+ # @return [Symbol] Resolved provider
42
+ # @raise [ArgumentError] if an explicit provider is unknown
43
+ def resolve_provider(provider, api_key)
44
+ detected = KeyDetector.detect(api_key)
45
+ return detected || :openai if provider.nil?
46
+
47
+ explicit = provider.to_s.to_sym
48
+ raise ArgumentError, "Unknown provider: #{provider.inspect} (supported: #{PROVIDERS.join(", ")})" unless PROVIDERS.include?(explicit)
49
+
50
+ warn "vibe-sort: api_key format suggests :#{detected} but provider is :#{explicit}" if detected && detected != explicit
51
+ explicit
28
52
  end
29
53
  end
30
54
  end
@@ -25,7 +25,7 @@ module VibeSort
25
25
  # @raise [VibeSort::ApiError] if the API request fails
26
26
  def perform(array)
27
27
  response = connection.post do |req|
28
- req.body = build_payload(array)
28
+ req.body = deep_merge(build_payload(array), config.extra_params)
29
29
  end
30
30
 
31
31
  handle_response(response)
@@ -33,6 +33,20 @@ module VibeSort
33
33
 
34
34
  private
35
35
 
36
+ # Merge the user's extra_params into the adapter payload last, so they can
37
+ # override anything (response_format, temperature, even model). Nested
38
+ # hashes merge recursively (e.g. Gemini's generationConfig); arrays and
39
+ # scalars replace.
40
+ #
41
+ # @param base [Hash] Adapter-built payload
42
+ # @param extra [Hash] User-supplied provider-native parameters
43
+ # @return [Hash] Merged payload
44
+ def deep_merge(base, extra)
45
+ base.merge(extra) do |_key, old_val, new_val|
46
+ old_val.is_a?(Hash) && new_val.is_a?(Hash) ? deep_merge(old_val, new_val) : new_val
47
+ end
48
+ end
49
+
36
50
  # Model to use: explicit override from config, or the provider default
37
51
  #
38
52
  # @return [String] Model ID
@@ -8,7 +8,8 @@ module VibeSort
8
8
  anthropic: Providers::Anthropic,
9
9
  gemini: Providers::Gemini,
10
10
  groq: Providers::Groq,
11
- spacexai: Providers::SpaceXAI
11
+ spacexai: Providers::SpaceXAI,
12
+ openrouter: Providers::OpenRouter
12
13
  }.freeze
13
14
 
14
15
  attr_reader :config
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module VibeSort
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/vibe_sort.rb CHANGED
@@ -5,6 +5,7 @@ require "json"
5
5
 
6
6
  require_relative "vibe_sort/version"
7
7
  require_relative "vibe_sort/error"
8
+ require_relative "vibe_sort/key_detector"
8
9
  require_relative "vibe_sort/configuration"
9
10
  require_relative "vibe_sort/providers/base"
10
11
  require_relative "vibe_sort/providers/openai"
@@ -12,6 +13,7 @@ require_relative "vibe_sort/providers/anthropic"
12
13
  require_relative "vibe_sort/providers/gemini"
13
14
  require_relative "vibe_sort/providers/groq"
14
15
  require_relative "vibe_sort/providers/space_x_ai"
16
+ require_relative "vibe_sort/providers/open_router"
15
17
  require_relative "vibe_sort/sorter"
16
18
  require_relative "vibe_sort/client"
17
19
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vibe-sort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chayut Orapinpatipat
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-07-10 00:00:00.000000000 Z
11
+ date: 2026-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -25,8 +25,9 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  description: A proof-of-concept Ruby gem that sorts arrays by leveraging LLM APIs
28
- (OpenAI Chat Completions, Anthropic Messages, Google Gemini). Demonstrates how AI
29
- can be used for computational tasks.
28
+ (OpenAI Chat Completions, Anthropic Messages, Google Gemini, and the OpenAI-compatible
29
+ Groq, SpaceXAI Grok, and OpenRouter APIs). Infers the provider from the API key
30
+ format. Demonstrates how AI can be used for computational tasks.
30
31
  email:
31
32
  - chayut_o@hotmail.com
32
33
  executables: []
@@ -44,6 +45,7 @@ files:
44
45
  - docs/api_reference.md
45
46
  - docs/architecture.md
46
47
  - docs/development.md
48
+ - docs/free_model_benchmark_2026-07-12.md
47
49
  - docs/v0.2.0_UPDATE.md
48
50
  - lib/vibe/sort.rb
49
51
  - lib/vibe_sort.rb
@@ -65,6 +67,8 @@ metadata:
65
67
  homepage_uri: https://github.com/chayuto/vibe-sort
66
68
  source_code_uri: https://github.com/chayuto/vibe-sort
67
69
  changelog_uri: https://github.com/chayuto/vibe-sort/blob/main/CHANGELOG.md
70
+ documentation_uri: https://rubydoc.info/gems/vibe-sort
71
+ bug_tracker_uri: https://github.com/chayuto/vibe-sort/issues
68
72
  rubygems_mfa_required: 'true'
69
73
  post_install_message:
70
74
  rdoc_options: []
@@ -84,5 +88,6 @@ requirements: []
84
88
  rubygems_version: 3.5.22
85
89
  signing_key:
86
90
  specification_version: 4
87
- summary: AI-powered array sorting using OpenAI, Anthropic Claude, or Google Gemini
91
+ summary: AI-powered array sorting using OpenAI, Anthropic Claude, Google Gemini, Groq,
92
+ SpaceXAI Grok, or OpenRouter
88
93
  test_files: []