Class: VibeSort::Providers::Base

Inherits:
Object
  • Object
show all
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.

Direct Known Subclasses

Anthropic, Gemini, OpenAI

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.

Parameters:



17
18
19
# File 'lib/vibe_sort/providers/base.rb', line 17

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (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

Parameters:

  • array (Array)

    Array of numbers and/or strings to sort

Returns:

  • (Hash)

    Result hash with :success and :sorted_array keys

Raises:



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