Class: Tobias::CLI
- Inherits:
-
Thor
- Object
- Thor
- Tobias::CLI
- Includes:
- ActiveSupport::NumberHelper
- Defined in:
- lib/tobias/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
7 8 9 |
# File 'lib/tobias/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#profile(script) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tobias/cli.rb', line 46 def profile(script) database = Sequel.connect([:database_url], max_connections: Etc.nprocessors + 2) database.loggers << Logger.new(STDERR) if [:debug] database.extension :pg_json database.extension :pgvector if File.exist?(script) code = File.read(script) else raise "Script not found at: #{script}" end container = Container.new(code, database) results = {} parsed = TTY::Markdown.parse(" # @tobias is thinking...\n MARKDOWN\n puts parsed\n\n thinking_time = Benchmark.realtime do\n results = Evaluations.run(database, container, options)\n end\n\n parsed = TTY::Markdown.parse(<<~MARKDOWN)\n # @tobias has sent you a new message\n\n I thought about your queries for precisely \#{thinking_time.round(2)} seconds and here is what I recommend:\n\n \#{results.join(\"\\n\")}\n\n Regards,\n ~ Tobias\n MARKDOWN\n\n puts parsed\nend\n") |
#recommend ⇒ Object
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 40 41 |
# File 'lib/tobias/cli.rb', line 14 def recommend database = Sequel.connect([:database_url]) database.extension :pgvector database.loggers << Logger.new(STDERR) if [:debug] parsed = TTY::Markdown.parse(" # @tobias is thinking...\n MARKDOWN\n puts parsed\n\n work_mem = Tobias::WorkMem.valid_for(database).sort_by(&:amount).reverse.first\n\n parsed = TTY::Markdown.parse(<<~MARKDOWN)\n # @tobias has sent you a new message\n\n I've reviewed your database by analyzing your shared buffers and connection limits and\n recommend setting `work_mem` to `\#{work_mem.to_sql}`. To apply my recommendation, run the following SQL:\n\n ```sql\n ALTER SYSTEM SET work_mem = '\#{work_mem.to_sql}';\n SELECT pg_reload_conf();\n ```\n\n Regards,\n ~ Tobias\n MARKDOWN\n puts parsed\nend\n") |