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.



19
20
21
# File 'lib/patient_llm/configuration.rb', line 19

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



63
64
65
# File 'lib/patient_llm/configuration.rb', line 63

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

#provider(name, url:, headers: {}, serializer: :chat_completion, path: nil, completion_path: nil, params: {}, preprocessors: nil) ⇒ 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)

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

    Override the default endpoint path

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

    Deprecated alias for path

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

    Additional parameters to merge into every request payload

  • preprocessors (String, Symbol, Array<String, Symbol>, nil) (defaults to: nil)

    Names of request preprocessors to apply to every request (e.g. for request signing). Names must be registered on the PatientHttp configuration with register_preprocessor.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/patient_llm/configuration.rb', line 36

def provider(name, url:, headers: {}, serializer: :chat_completion, path: nil, completion_path: nil, params: {}, preprocessors: nil)
  if completion_path
    warn "PatientLLM::Configuration#provider: the `completion_path:` argument is deprecated; use `path:` instead", uplevel: 1
    path ||= completion_path
  end

  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

  ensure_auth_headers_use_secrets!(headers)

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