Class: VibeSort::Providers::Base
- Inherits:
-
Object
- Object
- VibeSort::Providers::Base
- Defined in:
- lib/vibe_sort/providers/base.rb
Overview
Base class for LLM provider adapters.
Holds everything that is provider-agnostic: the sorting prompt, the
Faraday connection plumbing, and validation of the returned array.
Subclasses implement the provider-specific hooks: provider_name,
endpoint, headers, build_payload, and extract_content.
Constant Summary collapse
- SYSTEM_PROMPT =
"You are an assistant that only sorts arrays. The array may contain numbers and strings. Sort the array in ascending order. Follow standard sorting rules: numbers should come before strings, and string sorting should be case-sensitive. Return a JSON object with a single key 'sorted_array' containing the sorted elements."
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config) ⇒ Base
constructor
A new instance of Base.
-
#perform(array) ⇒ Hash
Perform the sorting operation via the provider's API.
Constructor Details
#initialize(config) ⇒ Base
Returns a new instance of Base.
17 18 19 |
# File 'lib/vibe_sort/providers/base.rb', line 17 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
14 15 16 |
# File 'lib/vibe_sort/providers/base.rb', line 14 def config @config end |
Instance Method Details
#perform(array) ⇒ Hash
Perform the sorting operation via the provider's API
26 27 28 29 30 31 32 |
# File 'lib/vibe_sort/providers/base.rb', line 26 def perform(array) response = connection.post do |req| req.body = build_payload(array) end handle_response(response) end |