Class: CodeToQuery::Configuration
- Inherits:
-
Object
- Object
- CodeToQuery::Configuration
- Includes:
- Singleton
- Defined in:
- lib/code_to_query/configuration.rb
Overview
Centralized configuration with sensible defaults
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#aggregation_limit ⇒ Object
Returns the value of attribute aggregation_limit.
-
#allow_seq_scans ⇒ Object
Returns the value of attribute allow_seq_scans.
-
#auto_glossary_with_llm ⇒ Object
Returns the value of attribute auto_glossary_with_llm.
-
#block_subqueries ⇒ Object
Returns the value of attribute block_subqueries.
-
#context_pack_path ⇒ Object
Returns the value of attribute context_pack_path.
-
#context_rag_top_k ⇒ Object
Returns the value of attribute context_rag_top_k.
-
#count_limit ⇒ Object
Returns the value of attribute count_limit.
-
#default_limit ⇒ Object
Returns the value of attribute default_limit.
-
#distinct_limit ⇒ Object
Returns the value of attribute distinct_limit.
-
#enable_explain_gate ⇒ Object
Returns the value of attribute enable_explain_gate.
-
#exists_limit ⇒ Object
Returns the value of attribute exists_limit.
-
#explain_fail_open ⇒ Object
Returns the value of attribute explain_fail_open.
-
#force_readonly_session ⇒ Object
Returns the value of attribute force_readonly_session.
-
#llm_api_base ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#llm_client ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#llm_temperature ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#llm_timeout ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#logger ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#max_glossary_suggestions ⇒ Object
Returns the value of attribute max_glossary_suggestions.
-
#max_joins ⇒ Object
Returns the value of attribute max_joins.
-
#max_limit ⇒ Object
Returns the value of attribute max_limit.
-
#max_query_cost ⇒ Object
Returns the value of attribute max_query_cost.
-
#max_query_rows ⇒ Object
Returns the value of attribute max_query_rows.
-
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
-
#openai_model ⇒ Object
Returns the value of attribute openai_model.
-
#planner_feedback_mode ⇒ Object
Returns the value of attribute planner_feedback_mode.
-
#planner_max_attempts ⇒ Object
Returns the value of attribute planner_max_attempts.
-
#policy_adapter ⇒ Object
Returns the value of attribute policy_adapter.
-
#prefer_static_scan ⇒ Object
Returns the value of attribute prefer_static_scan.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#provider_options ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
-
#query_timeout ⇒ Object
Returns the value of attribute query_timeout.
-
#readonly_role ⇒ Object
Returns the value of attribute readonly_role.
-
#require_limit_by_default ⇒ Object
Returns the value of attribute require_limit_by_default.
-
#reset_session_after_query ⇒ Object
Returns the value of attribute reset_session_after_query.
-
#static_scan_dirs ⇒ Object
Returns the value of attribute static_scan_dirs.
-
#stub_llm ⇒ Object
Returns the value of attribute stub_llm.
-
#system_prompt_template ⇒ Object
Extended configuration knobs (added for LLM transport and logging).
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/code_to_query/configuration.rb', line 27 def initialize @adapter = :postgres @readonly_role = nil @default_limit = 100 @max_limit = 10_000 @max_joins = 3 @block_subqueries = false @allow_seq_scans = false @max_query_cost = 10_000 @max_query_rows = 100_000 @query_timeout = 30 @force_readonly_session = false @reset_session_after_query = false @policy_adapter = nil @context_pack_path = if defined?(Rails) Rails.root.join('db/code_to_query/context.json') else File.join(Dir.pwd, 'db/code_to_query/context.json') end @enable_explain_gate = false @explain_fail_open = true @provider = :auto @openai_api_key = ENV.fetch('OPENAI_API_KEY', nil) @openai_model = 'gpt-4' @stub_llm = false # LLM-assisted glossary enrichment during bootstrap (on by default for better UX) @auto_glossary_with_llm = true @max_glossary_suggestions = 200 # Query type specific limits for flexibility @count_limit = nil # No limit for COUNT operations by default @aggregation_limit = nil # No limit for SUM/AVG/MAX/MIN operations by default @distinct_limit = 10_000 # Higher limit for DISTINCT queries @exists_limit = 1 # LIMIT 1 for existence checks # Planner iteration @planner_max_attempts = Integer(ENV.fetch('CODE_TO_QUERY_PLANNER_MAX_ATTEMPTS', 2)) # feedback modes: :none, :schema_strict, :adaptive @planner_feedback_mode = ENV.fetch('CODE_TO_QUERY_PLANNER_FEEDBACK_MODE', 'adaptive').to_sym # Logging and LLM provider knobs @logger = if defined?(Rails) && Rails.respond_to?(:logger) Rails.logger else Logger.new($stdout).tap { |l| l.level = Logger::WARN } end @llm_api_base = ENV.fetch('CODE_TO_QUERY_LLM_API_BASE', 'https://api.openai.com/v1') @llm_timeout = Integer(ENV.fetch('CODE_TO_QUERY_LLM_TIMEOUT', 30)) @llm_temperature = Float(ENV.fetch('CODE_TO_QUERY_LLM_TEMPERATURE', 0.1)) @provider_options = {} @system_prompt_template = nil @llm_client = nil # Static analysis and RAG context options @prefer_static_scan = true @static_scan_dirs = if defined?(Rails) [Rails.root.join('app/models').to_s] else [File.join(Dir.pwd, 'app/models')] end @context_rag_top_k = Integer(ENV.fetch('CODE_TO_QUERY_CONTEXT_RAG_TOP_K', 6)) # Guardrail defaults @require_limit_by_default = true end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def adapter @adapter end |
#aggregation_limit ⇒ Object
Returns the value of attribute aggregation_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def aggregation_limit @aggregation_limit end |
#allow_seq_scans ⇒ Object
Returns the value of attribute allow_seq_scans.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def allow_seq_scans @allow_seq_scans end |
#auto_glossary_with_llm ⇒ Object
Returns the value of attribute auto_glossary_with_llm.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def auto_glossary_with_llm @auto_glossary_with_llm end |
#block_subqueries ⇒ Object
Returns the value of attribute block_subqueries.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def block_subqueries @block_subqueries end |
#context_pack_path ⇒ Object
Returns the value of attribute context_pack_path.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def context_pack_path @context_pack_path end |
#context_rag_top_k ⇒ Object
Returns the value of attribute context_rag_top_k.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def context_rag_top_k @context_rag_top_k end |
#count_limit ⇒ Object
Returns the value of attribute count_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def count_limit @count_limit end |
#default_limit ⇒ Object
Returns the value of attribute default_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def default_limit @default_limit end |
#distinct_limit ⇒ Object
Returns the value of attribute distinct_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def distinct_limit @distinct_limit end |
#enable_explain_gate ⇒ Object
Returns the value of attribute enable_explain_gate.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def enable_explain_gate @enable_explain_gate end |
#exists_limit ⇒ Object
Returns the value of attribute exists_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def exists_limit @exists_limit end |
#explain_fail_open ⇒ Object
Returns the value of attribute explain_fail_open.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def explain_fail_open @explain_fail_open end |
#force_readonly_session ⇒ Object
Returns the value of attribute force_readonly_session.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def force_readonly_session @force_readonly_session end |
#llm_api_base ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def llm_api_base @llm_api_base end |
#llm_client ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def llm_client @llm_client end |
#llm_temperature ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def llm_temperature @llm_temperature end |
#llm_timeout ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def llm_timeout @llm_timeout end |
#logger ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def logger @logger end |
#max_glossary_suggestions ⇒ Object
Returns the value of attribute max_glossary_suggestions.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def max_glossary_suggestions @max_glossary_suggestions end |
#max_joins ⇒ Object
Returns the value of attribute max_joins.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def max_joins @max_joins end |
#max_limit ⇒ Object
Returns the value of attribute max_limit.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def max_limit @max_limit end |
#max_query_cost ⇒ Object
Returns the value of attribute max_query_cost.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def max_query_cost @max_query_cost end |
#max_query_rows ⇒ Object
Returns the value of attribute max_query_rows.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def max_query_rows @max_query_rows end |
#openai_api_key ⇒ Object
Returns the value of attribute openai_api_key.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def openai_api_key @openai_api_key end |
#openai_model ⇒ Object
Returns the value of attribute openai_model.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def openai_model @openai_model end |
#planner_feedback_mode ⇒ Object
Returns the value of attribute planner_feedback_mode.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def planner_feedback_mode @planner_feedback_mode end |
#planner_max_attempts ⇒ Object
Returns the value of attribute planner_max_attempts.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def planner_max_attempts @planner_max_attempts end |
#policy_adapter ⇒ Object
Returns the value of attribute policy_adapter.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def policy_adapter @policy_adapter end |
#prefer_static_scan ⇒ Object
Returns the value of attribute prefer_static_scan.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def prefer_static_scan @prefer_static_scan end |
#provider ⇒ Object
Returns the value of attribute provider.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def provider @provider end |
#provider_options ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def @provider_options end |
#query_timeout ⇒ Object
Returns the value of attribute query_timeout.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def query_timeout @query_timeout end |
#readonly_role ⇒ Object
Returns the value of attribute readonly_role.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def readonly_role @readonly_role end |
#require_limit_by_default ⇒ Object
Returns the value of attribute require_limit_by_default.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def require_limit_by_default @require_limit_by_default end |
#reset_session_after_query ⇒ Object
Returns the value of attribute reset_session_after_query.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def reset_session_after_query @reset_session_after_query end |
#static_scan_dirs ⇒ Object
Returns the value of attribute static_scan_dirs.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def static_scan_dirs @static_scan_dirs end |
#stub_llm ⇒ Object
Returns the value of attribute stub_llm.
13 14 15 |
# File 'lib/code_to_query/configuration.rb', line 13 def stub_llm @stub_llm end |
#system_prompt_template ⇒ Object
Extended configuration knobs (added for LLM transport and logging)
25 26 27 |
# File 'lib/code_to_query/configuration.rb', line 25 def system_prompt_template @system_prompt_template end |