mirror of
				https://github.com/discourse/discourse-ai.git
				synced 2025-11-03 16:08:52 +00:00 
			
		
		
		
	This splits out a bunch of code that used to live inside bots into a dedicated concept called a Persona. This allows us to start playing with multiple personas for the bot Ships with: artist - for making images sql helper - for helping with data explorer general - for everything and anything Also includes a few fixes that make the generic LLM function implementation more robust
		
			
				
	
	
		
			55 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
#frozen_string_literal: true
 | 
						|
 | 
						|
module DiscourseAi::AiBot::Commands
 | 
						|
  class DbSchemaCommand < Command
 | 
						|
    class << self
 | 
						|
      def name
 | 
						|
        "schema"
 | 
						|
      end
 | 
						|
 | 
						|
      def desc
 | 
						|
        "Will load schema information for specific tables in the database"
 | 
						|
      end
 | 
						|
 | 
						|
      def parameters
 | 
						|
        [
 | 
						|
          Parameter.new(
 | 
						|
            name: "tables",
 | 
						|
            description:
 | 
						|
              "list of tables to load schema information for, comma seperated list eg: (users,posts))",
 | 
						|
            type: "string",
 | 
						|
            required: true,
 | 
						|
          ),
 | 
						|
        ]
 | 
						|
      end
 | 
						|
    end
 | 
						|
 | 
						|
    def result_name
 | 
						|
      "results"
 | 
						|
    end
 | 
						|
 | 
						|
    def description_args
 | 
						|
      { tables: @tables.join(", ") }
 | 
						|
    end
 | 
						|
 | 
						|
    def process(tables:)
 | 
						|
      @tables = tables.split(",").map(&:strip)
 | 
						|
 | 
						|
      table_info = {}
 | 
						|
      DB
 | 
						|
        .query(<<~SQL, @tables)
 | 
						|
        select table_name, column_name, data_type from information_schema.columns
 | 
						|
        where table_schema = 'public'
 | 
						|
        and table_name in (?)
 | 
						|
        order by table_name
 | 
						|
      SQL
 | 
						|
        .each { |row| (table_info[row.table_name] ||= []) << "#{row.column_name} #{row.data_type}" }
 | 
						|
 | 
						|
      schema_info =
 | 
						|
        table_info.map { |table_name, columns| "#{table_name}(#{columns.join(",")})" }.join("\n")
 | 
						|
 | 
						|
      { tables: @tables, schema_info: schema_info }
 | 
						|
    end
 | 
						|
  end
 | 
						|
end
 |