Class: Raif::Configuration

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

Constant Summary collapse

CAPTURE_MODEL_COMPLETION_MODES =
["full", "summary", "none"].freeze
OPEN_ROUTER_DATA_COLLECTION_VALUES =
["allow", "deny"].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/raif/configuration.rb', line 83

def initialize
  @agent_types = Set.new(["Raif::Agents::NativeToolCallingAgent"])
  @anthropic_api_key = default_disable_llm_api_requests? ? "placeholder-anthropic-api-key" : ENV["ANTHROPIC_API_KEY"]
  @anthropic_message_batches_beta_header = "message-batches-2024-09-24"
  @bedrock_models_enabled = false
  @anthropic_models_enabled = ENV["ANTHROPIC_API_KEY"].present?
  @authorize_admin_controller_action = ->{ false }
  @authorize_controller_action = ->{ false }
  @aws_bedrock_region = "us-east-1"
  @aws_bedrock_model_name_prefix = "us"
  # Master switch for the archive-and-cull capability. Explicit opt-in
  # only: with the default false (and no archive_storage adapter),
  # upgrading the gem never deletes anything.
  @archive_enabled = false
  # Column on the archived resource (e.g. :account_id) whose value
  # partitions archive objects: every object then holds records from
  # exactly one partition and is stored under a per-partition key
  # prefix, so Raif::Archive.purge_partition! can completely erase one
  # partition's archives. nil (the default) preserves unpartitioned
  # behavior. The column's value must be immutable for the record's
  # lifetime. Column existence is validated when the archive job or
  # dry_run executes, not at boot.
  @archive_partition_column = nil
  # Applies only when archive_partition_column is set: what to do with a
  # record whose partition value is NULL or normalizes to blank. nil
  # (the default) fails closed: the record is never archived, so a later
  # partition purge cannot miss records that lost their attribution.
  # Hosts with intentionally global/unowned records may explicitly set
  # Raif::ArchivePartition::UNGROUPED (aliased as Raif::Archive::UNGROUPED
  # for post-boot callers) to archive them under the reserved
  # "_ungrouped" storage segment, which purge_partition! never touches.
  @archive_partition_fallback = nil
  # Storage adapter instance implementing
  # write(key:, io:, checksum_sha256:), returning a location string and
  # raising on any failure. See Raif::ArchiveStorage::FileSystem for a
  # reference implementation; production hosts typically supply their own
  # (e.g. S3-backed) adapter.
  @archive_storage = nil
  @bedrock_embedding_models_enabled = false
  @task_system_prompt_intro = "You are a helpful assistant."
  @conversation_entries_controller = "Raif::ConversationEntriesController"
  @conversation_entry_max_retries = 2
  @conversation_llm_messages_max_length_default = 50
  @conversation_system_prompt_intro = "You are a helpful assistant who is collaborating with a teammate."
  @conversation_types = Set.new(["Raif::Conversation"])
  @conversations_controller = "Raif::ConversationsController"
  @current_user_method = :current_user
  @default_embedding_model_key = "open_ai_text_embedding_3_small"
  @default_llm_model_key = default_disable_llm_api_requests? ? :raif_test_llm : (ENV["RAIF_DEFAULT_LLM_MODEL_KEY"].presence || "open_ai_gpt_4o")
  # :full captures every prompt, message, and response - what you want debugging one eval,
  # unmanageable for a dataset run. :summary keeps tokens and cost, :none omits the
  # per-call array. Usage totals are identical in all three modes.
  @evals_capture_model_completions = :full
  # How many eval executions run at once. An eval run is almost entirely waiting on provider
  # responses, so this is the wall clock. Serial by default: raising it needs a database
  # connection pool larger than the concurrency, and enough provider rate limit to absorb it.
  @evals_concurrency = 1
  # Unset means judging falls back to default_llm_model_key, so the model under test grades its
  # own output and a run against a second model changes the judge with it, which
  # Raif::Evals::Run warns about.
  @evals_default_llm_judge_model_key = ENV["RAIF_EVALS_DEFAULT_LLM_JUDGE_MODEL_KEY"].presence
  @evals_verbose_output = false
  google_api_key = ENV["GOOGLE_AI_API_KEY"].presence || ENV["GOOGLE_API_KEY"]
  @google_api_key = default_disable_llm_api_requests? ? "placeholder-google-api-key" : google_api_key
  @google_embedding_models_enabled = false
  @google_models_enabled = @google_api_key.present?
  # Optional callable receiving a model_completion: keyword argument and
  # returning a hash merged into Raif::InferenceCostEvent#metadata at sync
  # time. The sanctioned host extension point for attaching app-specific
  # context (e.g. account/workflow ids) to cost events.
  @inference_cost_event_metadata = nil
  # When true, a durable Raif::InferenceCostEvent is created for each
  # model completion that reaches a terminal state (completed or failed).
  @inference_cost_events_enabled = true
  @llm_api_requests_enabled = !default_disable_llm_api_requests?
  @llm_request_max_retries = 2
  @llm_request_retriable_exceptions = [
    Faraday::ConnectionFailed,
    Faraday::TimeoutError,
    Faraday::ServerError,
    # 429. A ClientError rather than a ServerError, so it is not covered above, and the
    # transient failure that gets more likely the more requests are in flight at once.
    Faraday::TooManyRequestsError,
    Net::ReadTimeout,
    Net::OpenTimeout,
    Raif::Errors::BlankResponseError,
  ]
  # Schedule for the self-rescheduling Raif::PollModelCompletionBatchJob.
  # The Nth poll waits poll_schedule[N] (clamped to the last entry once exhausted).
  @model_completion_batch_poll_schedule = [
    60.seconds,
    2.minutes,
    5.minutes,
    10.minutes,
    30.minutes
  ]
  # Optional lambda called with llm:/source: keyword args at the start of
  # Raif::Llm#chat, before the Raif::ModelCompletion is created or any
  # provider API call is made. Raise from it to veto the request (e.g. a
  # host app enforcing per-account usage limits); the exception propagates
  # to the caller. Return values are ignored. Does not apply to embedding
  # generation or batch API submissions.
  @model_completion_authorizer = nil
  # Hard ceiling for any non-terminal Raif::ModelCompletionBatch. Older
  # batches are expired by the hourly safety sweep
  # (Raif::ExpireStuckModelCompletionBatchesJob) and the polling job's
  # max_age_exceeded? branch: a best-effort provider-side cancel is issued
  # via batch.cancel! before the batch is force-failed locally, so the
  # workflow can advance and we stop paying for completions we won't read.
  # If the cancel fails (network, 5xx, etc.), the local force-fail still
  # happens and the provider-side batch may continue and be billed.
  @model_completion_batch_max_age = 26.hours
  # How long completed/failed Raif::ModelCompletion rows are retained
  # before Raif::ArchiveModelCompletionsJob archives and deletes them
  # (e.g. 6.months). nil (the default) disables model completion culling
  # even when archive_enabled is true. validate! rejects values below
  # 1.month: cost and budget consumers aggregate by billing period, so an
  # accidentally tiny retention value must never be able to eat rows out
  # from under an open billing window.
  @model_completion_retention_period = nil
  @model_superclass = "ApplicationRecord"
  @open_ai_api_key = default_disable_llm_api_requests? ? "placeholder-open-ai-api-key" : ENV["OPENAI_API_KEY"]
  @open_ai_api_version = nil
  @open_ai_batch_completion_window = "24h"
  @open_ai_auth_header_style = :bearer
  @open_ai_base_url = "https://api.openai.com/v1"
  @open_ai_embedding_base_url = "https://api.openai.com/v1"
  @open_ai_embedding_models_enabled = ENV["OPENAI_API_KEY"].present?
  @open_ai_models_enabled = ENV["OPENAI_API_KEY"].present?
  # Value of the `store` parameter on every OpenAI Responses API request.
  # The provider defaults it to true and then keeps the response object for
  # 30 days, so the prompt becomes readable in the OpenAI dashboard and
  # retrievable by response id. Raif defaults to false, because an engine
  # cannot know whether its host app is allowed to leave prompts with a
  # processor. Set it to true to get that visibility and provider-side
  # response retrieval back.
  #
  # false is not zero retention. OpenAI still generates abuse monitoring
  # logs for all API usage and holds them for up to 30 days, unless the
  # organization is approved for Zero Data Retention or Modified Abuse
  # Monitoring. Under Zero Data Retention `store` is always treated as
  # false, so setting this to true has no effect there.
  #
  # Only the Responses API is affected: `store` already defaults to false
  # on Chat Completions, so Raif::Llms::OpenAiCompletions sends nothing.
  @open_ai_store_responses = false
  open_router_api_key = ENV["OPEN_ROUTER_API_KEY"].presence || ENV["OPENROUTER_API_KEY"]
  @open_router_api_key = default_disable_llm_api_requests? ? "placeholder-open-router-api-key" : open_router_api_key
  # Value of `provider.data_collection` on every OpenRouter request.
  # OpenRouter routes a request to an upstream inference provider, and some
  # of those providers store prompts non-transiently and train on them.
  # OpenRouter defaults the parameter to "allow", which filters nothing, so
  # the only thing standing between a prompt and such a provider is the
  # account-level privacy setting on openrouter.ai, which the host app
  # cannot see from its own code. "deny" (the Raif default) routes only to
  # providers that do not collect user data.
  #
  # "deny" is about training and non-transient storage, not retention:
  # OpenRouter states it has no routing rules based on provider retention
  # policies, so a provider that holds prompts for a fixed window without
  # training on them still qualifies. Use open_router_zdr below for
  # retention.
  @open_router_data_collection = "deny"
  # Value of `provider.zdr` on OpenRouter requests. true restricts routing
  # to endpoints with a Zero Data Retention policy, which is the only
  # OpenRouter control that stops an upstream provider retaining the
  # prompt. Defaults to false, because it is a much narrower filter than
  # data_collection and many models have no ZDR endpoint at all - a
  # restrictive default would turn working models into 404s on upgrade.
  # The parameter is only sent when true: OpenRouter documents false and
  # absent as identical, and per-request ZDR is OR'd with the account-wide
  # and guardrail settings, so it can only add enforcement.
  @open_router_zdr = false
  @open_router_models_enabled = @open_router_api_key.present?
  @prompt_studio_runs_enabled = Rails.env.development?
  @open_router_app_name = nil
  @open_router_site_url = nil
  @request_open_timeout = nil
  @request_read_timeout = nil
  @request_write_timeout = nil
  # Raif model keys whose streaming path is known to be unreliable. When a
  # caller passes a block to Raif::Llm#chat for one of these models, Raif
  # transparently falls back to the non-streaming path. Each entry may be
  # a String, Symbol, or Regexp matched against the model key.
  #
  # Default is derived from the model manifest definitions: every model
  # whose entry declares streaming: false. It currently covers Bedrock
  # gpt-oss, whose Converse streaming endpoint delivers corrupted/
  # truncated tool_use deltas. Set to [] to disable the workaround.
  @streaming_unsupported_model_keys = Raif.default_streaming_unsupported_model_keys.dup
  @streaming_update_chunk_size_threshold = 25
  @task_creator_optional = true
  # How long Raif::Task rows are retained before Raif::ArchiveTasksJob
  # archives and deletes them (e.g. 12.months). nil (the default)
  # disables task culling even when archive_enabled is true. Independent
  # of model_completion_retention_period, and validated against the same
  # 1.month floor.
  #
  # A task is never culled while its Raif::ModelCompletion row survives,
  # so setting this below model_completion_retention_period does not cull
  # tasks any earlier - it just makes the completion's window govern both.
  @task_retention_period = nil
  @user_tool_types = []
  x_ai_api_key = ENV["XAI_API_KEY"].presence || ENV["X_AI_API_KEY"]
  @x_ai_api_key = default_disable_llm_api_requests? ? "placeholder-x-ai-api-key" : x_ai_api_key
  @x_ai_base_url = "https://api.x.ai/v1"
  @x_ai_models_enabled = @x_ai_api_key.present?
end

Instance Attribute Details

#agent_typesObject

Returns the value of attribute agent_types.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def agent_types
  @agent_types
end

#anthropic_api_keyObject

Returns the value of attribute anthropic_api_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def anthropic_api_key
  @anthropic_api_key
end

#anthropic_message_batches_beta_headerObject

Returns the value of attribute anthropic_message_batches_beta_header.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def anthropic_message_batches_beta_header
  @anthropic_message_batches_beta_header
end

#anthropic_models_enabledObject

Returns the value of attribute anthropic_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def anthropic_models_enabled
  @anthropic_models_enabled
end

#archive_enabledObject

Returns the value of attribute archive_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def archive_enabled
  @archive_enabled
end

#archive_partition_columnObject

Returns the value of attribute archive_partition_column.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def archive_partition_column
  @archive_partition_column
end

#archive_partition_fallbackObject

Returns the value of attribute archive_partition_fallback.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def archive_partition_fallback
  @archive_partition_fallback
end

#archive_storageObject

Returns the value of attribute archive_storage.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def archive_storage
  @archive_storage
end

#authorize_admin_controller_actionObject

Returns the value of attribute authorize_admin_controller_action.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def authorize_admin_controller_action
  @authorize_admin_controller_action
end

#authorize_controller_actionObject

Returns the value of attribute authorize_controller_action.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def authorize_controller_action
  @authorize_controller_action
end

#aws_bedrock_model_name_prefixObject

Returns the value of attribute aws_bedrock_model_name_prefix.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def aws_bedrock_model_name_prefix
  @aws_bedrock_model_name_prefix
end

#aws_bedrock_regionObject

Returns the value of attribute aws_bedrock_region.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def aws_bedrock_region
  @aws_bedrock_region
end

#bedrock_embedding_models_enabledObject Also known as: aws_bedrock_titan_embedding_models_enabled

Returns the value of attribute bedrock_embedding_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def bedrock_embedding_models_enabled
  @bedrock_embedding_models_enabled
end

#bedrock_models_enabledObject Also known as: anthropic_bedrock_models_enabled

Returns the value of attribute bedrock_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def bedrock_models_enabled
  @bedrock_models_enabled
end

#conversation_entries_controllerObject

Returns the value of attribute conversation_entries_controller.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversation_entries_controller
  @conversation_entries_controller
end

#conversation_entry_max_retriesObject

Returns the value of attribute conversation_entry_max_retries.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversation_entry_max_retries
  @conversation_entry_max_retries
end

#conversation_llm_messages_max_length_defaultObject

Returns the value of attribute conversation_llm_messages_max_length_default.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversation_llm_messages_max_length_default
  @conversation_llm_messages_max_length_default
end

#conversation_system_prompt_introObject

Returns the value of attribute conversation_system_prompt_intro.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversation_system_prompt_intro
  @conversation_system_prompt_intro
end

#conversation_typesObject

Returns the value of attribute conversation_types.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversation_types
  @conversation_types
end

#conversations_controllerObject

Returns the value of attribute conversations_controller.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def conversations_controller
  @conversations_controller
end

#current_user_methodObject

Returns the value of attribute current_user_method.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def current_user_method
  @current_user_method
end

#default_embedding_model_keyObject

Returns the value of attribute default_embedding_model_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def default_embedding_model_key
  @default_embedding_model_key
end

#default_llm_model_keyObject

Returns the value of attribute default_llm_model_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def default_llm_model_key
  @default_llm_model_key
end

#evals_capture_model_completionsObject

Returns the value of attribute evals_capture_model_completions.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def evals_capture_model_completions
  @evals_capture_model_completions
end

#evals_concurrencyObject

Returns the value of attribute evals_concurrency.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def evals_concurrency
  @evals_concurrency
end

#evals_default_llm_judge_model_keyObject

Returns the value of attribute evals_default_llm_judge_model_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def evals_default_llm_judge_model_key
  @evals_default_llm_judge_model_key
end

#evals_verbose_outputObject

Returns the value of attribute evals_verbose_output.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def evals_verbose_output
  @evals_verbose_output
end

#google_api_keyObject

Returns the value of attribute google_api_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def google_api_key
  @google_api_key
end

#google_embedding_models_enabledObject

Returns the value of attribute google_embedding_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def google_embedding_models_enabled
  @google_embedding_models_enabled
end

#google_models_enabledObject

Returns the value of attribute google_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def google_models_enabled
  @google_models_enabled
end

#inference_cost_event_metadataObject

Returns the value of attribute inference_cost_event_metadata.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def 
  @inference_cost_event_metadata
end

#inference_cost_events_enabledObject

Returns the value of attribute inference_cost_events_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def inference_cost_events_enabled
  @inference_cost_events_enabled
end

#llm_api_requests_enabledObject

Returns the value of attribute llm_api_requests_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def llm_api_requests_enabled
  @llm_api_requests_enabled
end

#llm_request_max_retriesObject

Returns the value of attribute llm_request_max_retries.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def llm_request_max_retries
  @llm_request_max_retries
end

#llm_request_retriable_exceptionsObject

Returns the value of attribute llm_request_retriable_exceptions.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def llm_request_retriable_exceptions
  @llm_request_retriable_exceptions
end

#model_completion_authorizerObject

Returns the value of attribute model_completion_authorizer.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def model_completion_authorizer
  @model_completion_authorizer
end

#model_completion_batch_max_ageObject

Returns the value of attribute model_completion_batch_max_age.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def model_completion_batch_max_age
  @model_completion_batch_max_age
end

#model_completion_batch_poll_scheduleObject

Returns the value of attribute model_completion_batch_poll_schedule.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def model_completion_batch_poll_schedule
  @model_completion_batch_poll_schedule
end

#model_completion_retention_periodObject

Returns the value of attribute model_completion_retention_period.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def model_completion_retention_period
  @model_completion_retention_period
end

#model_superclassObject

Returns the value of attribute model_superclass.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def model_superclass
  @model_superclass
end

#open_ai_api_keyObject

Returns the value of attribute open_ai_api_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_api_key
  @open_ai_api_key
end

#open_ai_api_versionObject

Returns the value of attribute open_ai_api_version.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_api_version
  @open_ai_api_version
end

#open_ai_auth_header_styleObject

Returns the value of attribute open_ai_auth_header_style.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_auth_header_style
  @open_ai_auth_header_style
end

#open_ai_base_urlObject

Returns the value of attribute open_ai_base_url.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_base_url
  @open_ai_base_url
end

#open_ai_batch_completion_windowObject

Returns the value of attribute open_ai_batch_completion_window.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_batch_completion_window
  @open_ai_batch_completion_window
end

#open_ai_embedding_base_urlObject

Returns the value of attribute open_ai_embedding_base_url.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_embedding_base_url
  @open_ai_embedding_base_url
end

#open_ai_embedding_models_enabledObject

Returns the value of attribute open_ai_embedding_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_embedding_models_enabled
  @open_ai_embedding_models_enabled
end

#open_ai_models_enabledObject

Returns the value of attribute open_ai_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_models_enabled
  @open_ai_models_enabled
end

#open_ai_store_responsesObject

Returns the value of attribute open_ai_store_responses.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_ai_store_responses
  @open_ai_store_responses
end

#open_router_api_keyObject

Returns the value of attribute open_router_api_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_api_key
  @open_router_api_key
end

#open_router_app_nameObject

Returns the value of attribute open_router_app_name.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_app_name
  @open_router_app_name
end

#open_router_data_collectionObject

Returns the value of attribute open_router_data_collection.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_data_collection
  @open_router_data_collection
end

#open_router_models_enabledObject

Returns the value of attribute open_router_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_models_enabled
  @open_router_models_enabled
end

#open_router_site_urlObject

Returns the value of attribute open_router_site_url.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_site_url
  @open_router_site_url
end

#open_router_zdrObject

Returns the value of attribute open_router_zdr.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def open_router_zdr
  @open_router_zdr
end

#prompt_studio_runs_enabledObject

Returns the value of attribute prompt_studio_runs_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def prompt_studio_runs_enabled
  @prompt_studio_runs_enabled
end

#request_open_timeoutObject

Returns the value of attribute request_open_timeout.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def request_open_timeout
  @request_open_timeout
end

#request_read_timeoutObject

Returns the value of attribute request_read_timeout.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def request_read_timeout
  @request_read_timeout
end

#request_write_timeoutObject

Returns the value of attribute request_write_timeout.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def request_write_timeout
  @request_write_timeout
end

#streaming_unsupported_model_keysObject

Returns the value of attribute streaming_unsupported_model_keys.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def streaming_unsupported_model_keys
  @streaming_unsupported_model_keys
end

#streaming_update_chunk_size_thresholdObject

Returns the value of attribute streaming_update_chunk_size_threshold.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def streaming_update_chunk_size_threshold
  @streaming_update_chunk_size_threshold
end

#task_creator_optionalObject

Returns the value of attribute task_creator_optional.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def task_creator_optional
  @task_creator_optional
end

#task_retention_periodObject

Returns the value of attribute task_retention_period.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def task_retention_period
  @task_retention_period
end

#task_system_prompt_introObject

Returns the value of attribute task_system_prompt_intro.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def task_system_prompt_intro
  @task_system_prompt_intro
end

#user_tool_typesObject

Returns the value of attribute user_tool_types.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def user_tool_types
  @user_tool_types
end

#x_ai_api_keyObject

Returns the value of attribute x_ai_api_key.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def x_ai_api_key
  @x_ai_api_key
end

#x_ai_base_urlObject

Returns the value of attribute x_ai_base_url.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def x_ai_base_url
  @x_ai_base_url
end

#x_ai_models_enabledObject

Returns the value of attribute x_ai_models_enabled.



8
9
10
# File 'lib/raif/configuration.rb', line 8

def x_ai_models_enabled
  @x_ai_models_enabled
end

Instance Method Details

#validate!Object



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/raif/configuration.rb', line 292

def validate!
  # Before the LLM-registry early return below: archive validation guards
  # a destructive path (culling), so a node with no LLM API keys (e.g. a
  # misconfigured cron/worker box) must still have its archive settings
  # validated.
  validate_archive_config!

  # Also before the early return: a typo in a data retention setting must
  # fail loudly rather than silently fall back to the provider default,
  # which is the permissive one for both providers.
  validate_provider_data_retention_config!

  if Raif.llm_registry.blank?
    puts <<~EOS

      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      No LLMs are enabled in Raif. Make sure you have an API key configured for at least one LLM provider. You can do this by setting an API key in your environment variables or in config/initializers/raif.rb (e.g. ENV["OPENAI_API_KEY"], ENV["ANTHROPIC_API_KEY"], ENV["OPEN_ROUTER_API_KEY"]).

      See the README for more information: https://github.com/CultivateLabs/raif#setup
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    EOS

    return
  end

  unless Raif.available_llm_keys.include?(default_llm_model_key.to_sym)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.default_llm_model_key was set to #{default_llm_model_key}, but must be one of: #{Raif.available_llm_keys.join(", ")}"
  end

  default_llm_config = Raif.llm_config(default_llm_model_key.to_sym)
  if default_llm_config && default_llm_config[:deprecated]
    Raif.logger.warn(
      "Raif.config.default_llm_model_key is set to :#{default_llm_model_key}, which is deprecated" \
        "#{default_llm_config[:retirement_date] ? " and will be removed after #{default_llm_config[:retirement_date]}" : ""}." \
        "#{default_llm_config[:replacement_key] ? " Use :#{default_llm_config[:replacement_key]} instead." : ""}"
    )
  end

  if default_embedding_model_key.present? &&
      Raif.embedding_model_registry.present? &&
      !Raif.available_embedding_model_keys.include?(default_embedding_model_key.to_sym)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.default_embedding_model_key was set to #{default_embedding_model_key}, but must be one of: #{Raif.available_embedding_model_keys.join(", ")}" # rubocop:disable Layout/LineLength
  end

  if authorize_controller_action.respond_to?(:call)
    authorize_controller_action.freeze
  else
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.authorize_controller_action must respond to :call and return a boolean"
  end

  if authorize_admin_controller_action.respond_to?(:call)
    authorize_admin_controller_action.freeze
  else
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.authorize_admin_controller_action must respond to :call and return a boolean"
  end

  if model_completion_authorizer.nil? || model_completion_authorizer.respond_to?(:call)
    model_completion_authorizer&.freeze
  else
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.model_completion_authorizer must be nil or respond to :call"
  end

  unless CAPTURE_MODEL_COMPLETION_MODES.include?(evals_capture_model_completions.to_s)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.evals_capture_model_completions was set to #{evals_capture_model_completions.inspect}, but must be one of: #{CAPTURE_MODEL_COMPLETION_MODES.join(", ")}" # rubocop:disable Layout/LineLength
  end

  if open_ai_models_enabled && open_ai_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_ai_api_key is required when Raif.config.open_ai_models_enabled is true. Set it via Raif.config.open_ai_api_key or ENV[\"OPENAI_API_KEY\"]" # rubocop:disable Layout/LineLength
  end

  if open_ai_models_enabled && ![:bearer, :api_key].include?(open_ai_auth_header_style)
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_ai_auth_header_style must be either :bearer or :api_key"
  end

  if open_ai_embedding_models_enabled && open_ai_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_ai_api_key is required when Raif.config.open_ai_embedding_models_enabled is true. Set it via Raif.config.open_ai_api_key or ENV[\"OPENAI_API_KEY\"]" # rubocop:disable Layout/LineLength
  end

  if anthropic_models_enabled && anthropic_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.anthropic_api_key is required when Raif.config.anthropic_models_enabled is true. Set it via Raif.config.anthropic_api_key or ENV['ANTHROPIC_API_KEY']" # rubocop:disable Layout/LineLength
  end

  if open_router_models_enabled && open_router_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.open_router_api_key is required when Raif.config.open_router_models_enabled is true. Set it via Raif.config.open_router_api_key or ENV['OPEN_ROUTER_API_KEY']" # rubocop:disable Layout/LineLength
  end

  if google_models_enabled && google_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.google_api_key is required when Raif.config.google_models_enabled is true. Set it via Raif.config.google_api_key or ENV['GOOGLE_API_KEY']" # rubocop:disable Layout/LineLength
  end

  if google_embedding_models_enabled && google_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.google_api_key is required when Raif.config.google_embedding_models_enabled is true. Set it via Raif.config.google_api_key or ENV['GOOGLE_API_KEY']" # rubocop:disable Layout/LineLength
  end

  if x_ai_models_enabled && x_ai_api_key.blank?
    raise Raif::Errors::InvalidConfigError,
      "Raif.config.x_ai_api_key is required when Raif.config.x_ai_models_enabled is true. Set it via Raif.config.x_ai_api_key or ENV['XAI_API_KEY']" # rubocop:disable Layout/LineLength
  end
end