mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-09 11:48:47 +00:00
Also adds ai_bot_enabled_personas so admins can tweak which stock personas are enabled. The new persona has a full listing of all site settings and is able to get context for each setting. This means you can ask it to search through settings for something relevant. Security wise there is no access to actual configuration of settings just to the names / description and implementation. Previously this was part of the forum helper persona however it just clashes too much with other behaviors, isolating it makes it far more powerful. * sneaking this one in, user_emails is a non obvious table in our structure. usually one would assume users has emails so the clarifies a bit better. plus it is a very common table to hit.
65 lines
1.9 KiB
Ruby
65 lines
1.9 KiB
Ruby
#frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module AiBot
|
|
module Personas
|
|
class SqlHelper < Persona
|
|
def self.schema
|
|
return @schema if defined?(@schema)
|
|
|
|
tables = Hash.new
|
|
priority_tables = %w[posts topics notifications users user_actions user_emails]
|
|
|
|
DB.query(<<~SQL).each { |row| (tables[row.table_name] ||= []) << row.column_name }
|
|
select table_name, column_name from information_schema.columns
|
|
where table_schema = 'public'
|
|
order by table_name
|
|
SQL
|
|
|
|
schema = +(priority_tables.map { |name| "#{name}(#{tables[name].join(",")})" }.join("\n"))
|
|
|
|
schema << "\nOther tables (schema redacted, available on request): "
|
|
tables.each do |table_name, _|
|
|
next if priority_tables.include?(table_name)
|
|
schema << "#{table_name} "
|
|
end
|
|
|
|
@schema = schema
|
|
end
|
|
|
|
def commands
|
|
all_available_commands
|
|
end
|
|
|
|
def all_available_commands
|
|
[DiscourseAi::AiBot::Commands::DbSchemaCommand]
|
|
end
|
|
|
|
def system_prompt
|
|
<<~PROMPT
|
|
You are a PostgreSQL expert.
|
|
You understand and generate Discourse Markdown but specialize in creating queries.
|
|
You live in a Discourse Forum Message.
|
|
The schema in your training set MAY be out of date.
|
|
|
|
The user_actions tables stores likes (action_type 1).
|
|
the topics table stores private/personal messages it uses archetype private_message for them.
|
|
notification_level can be: {muted: 0, regular: 1, tracking: 2, watching: 3, watching_first_post: 4}.
|
|
bookmarkable_type can be: Post,Topic,ChatMessage and more
|
|
|
|
Current time is: {time}
|
|
|
|
|
|
The current schema for the current DB is:
|
|
{{
|
|
#{self.class.schema}
|
|
}}
|
|
|
|
{commands}
|
|
PROMPT
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|