Class: PatientLLM::Configuration
- Inherits:
-
Object
- Object
- PatientLLM::Configuration
- Defined in:
- lib/patient_llm/configuration.rb
Overview
Configuration for provider registry.
Providers can be registered from a built-in preset, which supplies the vendor's base URL, serializer, and authentication header details, so that registering a provider and wiring up its API key is a single step:
Constant Summary collapse
- SECRET_NAME_PREFIX =
Prefix for secret names derived from provider names by the api_key option.
"patient_llm"
Instance Attribute Summary collapse
-
#session_offload_options ⇒ Object
readonly
Returns the value of attribute session_offload_options.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#lookup(name) ⇒ Hash?
Look up a registered provider by name.
-
#provider(name, preset: nil, url: nil, api_key: nil, region: nil, headers: nil, serializer: nil, path: nil, params: {}, preprocessors: nil, timeout: nil, max_tool_iterations: nil) ⇒ void
Register a provider.
-
#provider_names ⇒ Array<String>
All registered provider names.
-
#session_offload(payload_store:, threshold: 65_536) ⇒ void
Configure automatic offloading of large sessions to a PatientHttp payload store instead of carrying them through the job queue inline.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
31 32 33 34 |
# File 'lib/patient_llm/configuration.rb', line 31 def initialize @providers = {} @session_offload_options = nil end |
Instance Attribute Details
#session_offload_options ⇒ Object (readonly)
Returns the value of attribute session_offload_options.
29 30 31 |
# File 'lib/patient_llm/configuration.rb', line 29 def @session_offload_options end |
Instance Method Details
#lookup(name) ⇒ Hash?
Look up a registered provider by name. A provider registered with callable arguments is resolved on every lookup: each callable is called and the provider config is rebuilt from the results.
97 98 99 100 101 102 103 104 105 |
# File 'lib/patient_llm/configuration.rb', line 97 def lookup(name) entry = @providers[name&.to_s] return entry unless entry&.key?(:deferred) resolved = entry[:deferred].transform_values do |value| value.respond_to?(:call) ? value.call : value end build_provider_config(resolved) end |
#provider(name, preset: nil, url: nil, api_key: nil, region: nil, headers: nil, serializer: nil, path: nil, params: {}, preprocessors: nil, timeout: nil, max_tool_iterations: nil) ⇒ void
This method returns an undefined value.
Register a provider.
When a preset is given, its values are used as defaults; any explicit
keyword argument overrides the preset. When api_key is given, the key is
registered as a PatientHttp secret named patient_llm.<name>.api_key and
referenced from the provider's authentication header, so no separate
register_secret call is needed. The key value itself is never serialized
into requests; only the secret name travels with them.
Arguments passed as a callable object (responds to :call) are evaluated
at runtime on every request.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/patient_llm/configuration.rb', line 67 def provider(name, preset: nil, url: nil, api_key: nil, region: nil, headers: nil, serializer: nil, path: nil, params: {}, preprocessors: nil, timeout: nil, max_tool_iterations: nil) preset_config = preset ? Presets.fetch(preset) : nil = { preset_config: preset_config, url: url, region: region, headers: headers, serializer: serializer, path: path, params: params, preprocessors: preprocessors, timeout: timeout, max_tool_iterations: max_tool_iterations } [:api_key_header] = api_key_header(name, api_key, preset_config || {}) if api_key @providers[name.to_s] = if .values.any? { |value| value.respond_to?(:call) } {deferred: } else build_provider_config() end end |
#provider_names ⇒ Array<String>
All registered provider names.
110 111 112 |
# File 'lib/patient_llm/configuration.rb', line 110 def provider_names @providers.keys end |
#session_offload(payload_store:, threshold: 65_536) ⇒ void
This method returns an undefined value.
Configure automatic offloading of large sessions to a PatientHttp payload store instead of carrying them through the job queue inline. Sessions whose serialized size exceeds the threshold are written to the store and passed by reference.
123 124 125 126 127 |
# File 'lib/patient_llm/configuration.rb', line 123 def session_offload(payload_store:, threshold: 65_536) raise ArgumentError, "threshold must be a positive Integer" unless threshold.is_a?(Integer) && threshold.positive? @session_offload_options = {payload_store: payload_store.to_s, threshold: threshold} end |