Module: AsktiveRecord::Service::ClassMethods

Includes:
AsktiveRecord::SchemaLoader
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

Methods included from AsktiveRecord::SchemaLoader

#ensure_schema_is_not_empty!, #load_schema_content, #validate_llm_api_key!

Instance Method Details

#ask(natural_language_query, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/asktive_record/service.rb', line 16

def ask(natural_language_query, options = {})
  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 = options[:table_name] || "any"
  raw_sql = llm_service.generate_sql_for_service(natural_language_query, schema_content, target_table)
  target_model = resolve_model(options[:model])
  AsktiveRecord::Query.new(natural_language_query, raw_sql, target_model)
end