Class: LLMDB::Tools::ExecuteQuery
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- LLMDB::Tools::ExecuteQuery
- Defined in:
- lib/llmdb/tools/execute_query.rb
Instance Method Summary collapse
- #execute(sql:) ⇒ Object
-
#initialize(connection) ⇒ ExecuteQuery
constructor
A new instance of ExecuteQuery.
Constructor Details
#initialize(connection) ⇒ ExecuteQuery
Returns a new instance of ExecuteQuery.
15 16 17 18 |
# File 'lib/llmdb/tools/execute_query.rb', line 15 def initialize(connection) super() @connection = connection end |
Instance Method Details
#execute(sql:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/llmdb/tools/execute_query.rb', line 20 def execute(sql:) rows = @connection.execute(sql) return "Query returned no rows." if rows.empty? total = rows.length suffix = total == 1 ? "row" : "rows" "#{total} #{suffix}:\n#{JSON.generate(rows)}" rescue LLMDB::SafetyError => e { error: "Blocked: #{e.}" } rescue LLMDB::QueryError => e { error: "Query error: #{e.}" } end |