Module: AsktiveRecord::Service::ClassMethods
- Included in:
- AsktiveRecord
- Defined in:
- lib/asktive_record/service.rb
Overview
This module provides methods for handling service-based queries where the LLM determines the appropriate tables and relationships based on the query. It allows for more complex queries that may involve multiple tables or relationships, without requiring the user to specify a target table.
Instance Method Summary collapse
Instance Method Details
#ask(natural_language_query, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/asktive_record/service.rb', line 12 def ask(natural_language_query, = {}) validate_llm_api_key! schema_content = load_schema_content ensure_schema_is_not_empty!(schema_content) llm_service = AsktiveRecord::LlmService.new(AsktiveRecord.configuration) target_table = [:table_name] || "any" raw_sql = llm_service.generate_sql_for_service(natural_language_query, schema_content, target_table) target_model = resolve_model([:model]) AsktiveRecord::Query.new(natural_language_query, raw_sql, target_model) end |