Class: SqlGenius::Core::Ai::Suggestion

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_genius/core/ai/suggestion.rb

Overview

Turns a natural-language prompt + a list of allowed tables into a SELECT query via the AI client.

Construct with:

connection - a Core::Connection implementation
client     - a Core::Ai::Client (pre-built with the same config)
config     - the Core::Ai::Config (used for system_context)

Call:

.call(user_prompt, allowed_tables)  -> Hash with "sql" and "explanation"

Instance Method Summary collapse

Constructor Details

#initialize(connection, client, config) ⇒ Suggestion

Returns a new instance of Suggestion.



17
18
19
20
21
# File 'lib/sql_genius/core/ai/suggestion.rb', line 17

def initialize(connection, client, config)
  @connection = connection
  @client = client
  @config = config
end

Instance Method Details

#call(user_prompt, allowed_tables) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/sql_genius/core/ai/suggestion.rb', line 23

def call(user_prompt, allowed_tables)
  schema = build_schema_description(allowed_tables)
  messages = [
    { role: "system", content: system_prompt(schema) },
    { role: "user", content: user_prompt },
  ]

  @client.chat(messages: messages)
end