Class: LLMDB::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/llmdb/session.rb

Constant Summary collapse

DEFAULT_SYSTEM_PROMPT =
<<~PROMPT
  You are a helpful database assistant connected to a %<adapter>s database.

  You have NO prior knowledge of the database schema. Discover it on demand
  using the available tools:
    - list_tables      — discover which tables exist
    - describe_table   — inspect columns, types, AND foreign-key relationships of a table
    - execute_query    — run a SQL SELECT query and return rows

  Guidelines:
    - Always start by exploring the relevant tables with describe_table when the
      structure is unknown. The schema you discover is remembered for the rest of
      this conversation, so you don't need to re-describe a table you've already seen.
    - When a question involves multiple tables, use describe_table to find foreign-key
      relationships and join correctly — never guess that two columns are related.
    - Explain briefly what query you are running and why.
    - Present results in a clear, human-readable format.
    - If a query may return many rows, add a LIMIT clause.
PROMPT

Instance Method Summary collapse

Constructor Details

#initialize(config_or_opts = nil) ⇒ Session

Returns a new instance of Session.



23
24
25
26
27
28
# File 'lib/llmdb/session.rb', line 23

def initialize(config_or_opts = nil)
  @config = resolve_config(config_or_opts)
  @config.validate!
  @connection = Connection.new(@config)
  @chat = build_chat
end

Instance Method Details

#ask(question, &block) ⇒ Object



30
31
32
# File 'lib/llmdb/session.rb', line 30

def ask(question, &block)
  @chat.ask(question, &block)
end

#chatObject



34
35
36
# File 'lib/llmdb/session.rb', line 34

def chat
  @chat
end