Class: PatientLLM::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/patient_llm/configuration.rb

Overview

Configuration for provider registry.

Examples:

PatientLLM.configure do |config|
  config.provider :openai,
    url: "https://api.openai.com",
    headers: {"Authorization" => "Bearer #{ENV["OPENAI_API_KEY"]}"},
    serializer: :chat_completion
end

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



14
15
16
# File 'lib/patient_llm/configuration.rb', line 14

def initialize
  @providers = {}
end

Instance Method Details

#lookup(name) ⇒ Hash?

Look up a registered provider by name.

Parameters:

  • name (Symbol, String)

    Provider name

Returns:

  • (Hash, nil)

    Provider config hash



46
47
48
# File 'lib/patient_llm/configuration.rb', line 46

def lookup(name)
  @providers[name&.to_s]
end

#provider(name, url:, headers: {}, serializer: :chat_completion, completion_path: nil, params: {}) ⇒ void

This method returns an undefined value.

Register a provider with a base URL and default headers.

Parameters:

  • name (Symbol, String)

    Provider name

  • url (String)

    Base URL for the provider API

  • headers (Hash) (defaults to: {})

    Default headers for requests

  • serializer (Symbol) (defaults to: :chat_completion)

    API format (:chat_completion, :open_responses, :messages, :converse, :gemini)

  • completion_path (String, nil) (defaults to: nil)

    Override the default endpoint path

  • params (Hash) (defaults to: {})

    Additional parameters to merge into every request payload



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/patient_llm/configuration.rb', line 27

def provider(name, url:, headers: {}, serializer: :chat_completion, completion_path: nil, params: {})
  sym = serializer.to_sym
  unless PatientLLM::VALID_SERIALIZERS.include?(sym)
    raise ArgumentError, "Unknown serializer: #{sym.inspect}. Valid options: #{PatientLLM::VALID_SERIALIZERS.map(&:inspect).join(", ")}"
  end

  @providers[name.to_s] = {
    url: url,
    headers: headers,
    serializer: sym,
    completion_path: completion_path,
    params: params
  }
end