Module: PatientLLM::Presets

Defined in:
lib/patient_llm/presets.rb

Overview

Built-in provider presets bundling the vendor-specific details needed to talk to the major LLM APIs: base URL, serializer format, authentication header name, and how the API key is formatted into that header.

Presets are pure defaults. Every value can be overridden with the normal keyword arguments to Configuration#provider, so a stale preset never blocks anyone.

Examples:

PatientLLM.configure do |config|
  config.provider :anthropic, preset: :anthropic, api_key: -> { ENV["ANTHROPIC_API_KEY"] }
  config.provider :bedrock, preset: :bedrock_runtime, region: "us-east-1", preprocessors: :aws_sigv4
end

Constant Summary collapse

TABLE =
{
  openai: {
    url: "https://api.openai.com",
    serializer: :open_responses,
    auth_header: "authorization",
    auth_format: "Bearer %s"
  },
  anthropic: {
    url: "https://api.anthropic.com",
    serializer: :messages,
    auth_header: "x-api-key",
    auth_format: "%s",
    headers: {"anthropic-version" => ANTHROPIC_VERSION}
  },
  gemini: {
    url: "https://generativelanguage.googleapis.com",
    serializer: :gemini,
    auth_header: "x-goog-api-key",
    auth_format: "%s"
  },
  # Bedrock's bearer auth is for Amazon Bedrock API keys; SigV4 signing is
  # available instead via the :aws_sigv4 preprocessor (see AwsRequestSigner).
  bedrock_runtime: {
    url: "https://bedrock-runtime.%{region}.amazonaws.com",
    serializer: :converse,
    auth_header: "authorization",
    auth_format: "Bearer %s",
    requires_region: true
  }
}.freeze

Class Method Summary collapse

Class Method Details

.fetch(name) ⇒ Hash

Fetch a preset by name.

Parameters:

  • name (Symbol, String)

    the preset name

Returns:

  • (Hash)

    the preset attributes

Raises:

  • (ArgumentError)

    if the preset is unknown



55
56
57
# File 'lib/patient_llm/presets.rb', line 55

def fetch(name)
  TABLE[name.to_sym] || raise(ArgumentError, "Unknown preset: #{name.inspect}. Valid presets: #{TABLE.keys.map(&:inspect).join(", ")}")
end

.url(preset, region: nil) ⇒ String?

Resolve a preset's base URL, filling in the region placeholder when the preset requires one.

Parameters:

  • preset (Hash)

    a preset row from TABLE

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

    the region for region-templated URLs

Returns:

  • (String, nil)

    the resolved base URL or nil if the region is required but not provided



65
66
67
68
69
70
71
72
73
# File 'lib/patient_llm/presets.rb', line 65

def url(preset, region: nil)
  if preset[:requires_region]
    return nil if region.nil?

    format(preset[:url], region: region)
  else
    preset[:url]
  end
end