Class: CodeToQuery::Providers::Local

Inherits:
Base
  • Object
show all
Defined in:
lib/code_to_query/providers/local.rb

Instance Attribute Summary

Attributes inherited from Base

#metrics

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CodeToQuery::Providers::Base

Instance Method Details

#extract_intent(prompt:, schema:, allow_tables:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/code_to_query/providers/local.rb', line 6

def extract_intent(prompt:, schema:, allow_tables:)
  @prompt = prompt.to_s.strip
  @schema = schema || {}
  @allow_tables = Array(allow_tables).compact
  started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)

  table = select_table
  table ||= 'main_table' # Back-compat default expected by specs

  intent = {
    'type' => 'select',
    'table' => table,
    'columns' => ['*'],
    'filters' => [],
    'order' => [],
    'params' => {}
  }

  # Only set limit when configured (avoid nil which fails validation)
  intent['limit'] = @config.default_limit if @config.default_limit

  result = validate_and_enhance_intent(intent, allow_tables)

  # Lightweight metrics: elapsed and estimated tokens from prompt + schema table names
  elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - started_at
  prompt_blob = build_prompt_blob(@prompt, @schema)
  est = estimate_tokens(prompt_blob)
  @metrics[:prompt_tokens] = est
  @metrics[:completion_tokens] = 0
  @metrics[:total_tokens] = est
  @metrics[:elapsed_s] = elapsed

  result
end