2023-02-17 09:33:47 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-22 18:46:53 -05:00
|
|
|
# name: discourse-ai
|
2023-11-08 20:23:43 -05:00
|
|
|
# about: Enables integration between AI modules and features in Discourse
|
2023-11-07 18:45:02 -05:00
|
|
|
# meta_topic_id: 259214
|
2023-02-17 09:33:47 -05:00
|
|
|
# version: 0.0.1
|
|
|
|
# authors: Discourse
|
2023-05-11 22:54:25 -04:00
|
|
|
# url: https://meta.discourse.org/t/discourse-ai/259214
|
2023-02-17 09:33:47 -05:00
|
|
|
# required_version: 2.7.0
|
|
|
|
|
2024-04-04 10:02:16 -04:00
|
|
|
gem "tokenizers", "0.4.4"
|
2024-07-22 14:26:14 -04:00
|
|
|
gem "tiktoken_ruby", "0.0.9"
|
2024-10-16 11:41:18 -04:00
|
|
|
gem "ed25519", "1.2.4" #TODO remove this as existing ssl gem should handle this
|
2023-04-19 10:55:59 -04:00
|
|
|
|
2023-02-23 09:08:34 -05:00
|
|
|
enabled_site_setting :discourse_ai_enabled
|
2023-02-17 09:33:47 -05:00
|
|
|
|
2024-08-29 18:07:07 -04:00
|
|
|
register_asset "stylesheets/common/streaming.scss"
|
|
|
|
|
2023-03-15 16:02:20 -04:00
|
|
|
register_asset "stylesheets/modules/ai-helper/common/ai-helper.scss"
|
2024-09-10 23:45:48 -04:00
|
|
|
register_asset "stylesheets/modules/ai-helper/desktop/ai-helper-fk-modals.scss", :desktop
|
2024-11-28 11:06:48 -05:00
|
|
|
register_asset "stylesheets/modules/ai-helper/mobile/ai-helper.scss", :mobile
|
2023-05-18 11:34:49 -04:00
|
|
|
|
2024-07-02 11:51:59 -04:00
|
|
|
register_asset "stylesheets/modules/summarization/common/ai-summary.scss"
|
2024-08-05 11:39:08 -04:00
|
|
|
register_asset "stylesheets/modules/summarization/desktop/ai-summary.scss", :desktop
|
2024-07-02 11:51:59 -04:00
|
|
|
|
2024-11-19 15:33:34 -05:00
|
|
|
register_asset "stylesheets/modules/summarization/common/ai-gists.scss"
|
|
|
|
|
2023-05-05 14:28:31 -04:00
|
|
|
register_asset "stylesheets/modules/ai-bot/common/bot-replies.scss"
|
FEATURE: UI to update ai personas on admin page (#290)
Introduces a UI to manage customizable personas (admin only feature)
Part of the change was some extensive internal refactoring:
- AIBot now has a persona set in the constructor, once set it never changes
- Command now takes in bot as a constructor param, so it has the correct persona and is not generating AIBot objects on the fly
- Added a .prettierignore file, due to the way ALE is configured in nvim it is a pre-req for prettier to work
- Adds a bunch of validations on the AIPersona model, system personas (artist/creative etc...) are all seeded. We now ensure
- name uniqueness, and only allow certain properties to be touched for system personas.
- (JS note) the client side design takes advantage of nested routes, the parent route for personas gets all the personas via this.store.findAll("ai-persona") then child routes simply reach into this model to find a particular persona.
- (JS note) data is sideloaded into the ai-persona model the meta property supplied from the controller, resultSetMeta
- This removes ai_bot_enabled_personas and ai_bot_enabled_chat_commands, both should be controlled from the UI on a per persona basis
- Fixes a long standing bug in token accounting ... we were doing to_json.length instead of to_json.to_s.length
- Amended it so {commands} are always inserted at the end unconditionally, no need to add it to the template of the system message as it just confuses things
- Adds a concept of required_commands to stock personas, these are commands that must be configured for this stock persona to show up.
- Refactored tests so we stop requiring inference_stubs, it was very confusing to need it, added to plugin.rb for now which at least is clearer
- Migrates the persona selector to gjs
---------
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Co-authored-by: Martin Brennan <martin@discourse.org>
2023-11-21 00:56:43 -05:00
|
|
|
register_asset "stylesheets/modules/ai-bot/common/ai-persona.scss"
|
2024-03-21 00:29:56 -04:00
|
|
|
register_asset "stylesheets/modules/ai-bot/mobile/ai-persona.scss", :mobile
|
2023-03-15 16:02:20 -04:00
|
|
|
|
2023-07-13 15:34:02 -04:00
|
|
|
register_asset "stylesheets/modules/embeddings/common/semantic-related-topics.scss"
|
2023-09-05 10:08:23 -04:00
|
|
|
register_asset "stylesheets/modules/embeddings/common/semantic-search.scss"
|
2023-07-13 15:34:02 -04:00
|
|
|
|
2023-11-08 08:50:37 -05:00
|
|
|
register_asset "stylesheets/modules/sentiment/common/dashboard.scss"
|
|
|
|
|
2024-05-13 11:46:42 -04:00
|
|
|
register_asset "stylesheets/modules/llms/common/ai-llms-editor.scss"
|
|
|
|
|
2024-11-28 14:26:48 -05:00
|
|
|
register_asset "stylesheets/modules/llms/common/usage.scss"
|
|
|
|
|
2024-06-27 03:27:40 -04:00
|
|
|
register_asset "stylesheets/modules/ai-bot/common/ai-tools.scss"
|
|
|
|
|
2024-11-18 17:22:39 -05:00
|
|
|
register_asset "stylesheets/modules/ai-bot/common/ai-artifact.scss"
|
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
module ::DiscourseAi
|
|
|
|
PLUGIN_NAME = "discourse-ai"
|
2024-11-21 19:23:15 -05:00
|
|
|
|
|
|
|
def self.public_asset_path(name)
|
|
|
|
File.expand_path(File.join(__dir__, "public", name))
|
|
|
|
end
|
2023-03-14 15:03:50 -04:00
|
|
|
end
|
|
|
|
|
2023-11-28 23:17:46 -05:00
|
|
|
Rails.autoloaders.main.push_dir(File.join(__dir__, "lib"), namespace: ::DiscourseAi)
|
|
|
|
|
|
|
|
require_relative "lib/engine"
|
2023-03-07 13:39:28 -05:00
|
|
|
|
2023-02-24 05:53:43 -05:00
|
|
|
after_initialize do
|
2024-11-18 17:22:39 -05:00
|
|
|
if defined?(Rack::MiniProfiler)
|
|
|
|
Rack::MiniProfiler.config.skip_paths << "/discourse-ai/ai-bot/artifacts"
|
|
|
|
end
|
|
|
|
|
2023-11-28 23:17:46 -05:00
|
|
|
# do not autoload this cause we may have no namespace
|
|
|
|
require_relative "discourse_automation/llm_triage"
|
2023-12-18 20:04:15 -05:00
|
|
|
require_relative "discourse_automation/llm_report"
|
2023-02-22 18:46:53 -05:00
|
|
|
|
2024-03-21 00:29:56 -04:00
|
|
|
add_admin_route("discourse_ai.title", "discourse-ai", { use_new_show_route: true })
|
FEATURE: UI to update ai personas on admin page (#290)
Introduces a UI to manage customizable personas (admin only feature)
Part of the change was some extensive internal refactoring:
- AIBot now has a persona set in the constructor, once set it never changes
- Command now takes in bot as a constructor param, so it has the correct persona and is not generating AIBot objects on the fly
- Added a .prettierignore file, due to the way ALE is configured in nvim it is a pre-req for prettier to work
- Adds a bunch of validations on the AIPersona model, system personas (artist/creative etc...) are all seeded. We now ensure
- name uniqueness, and only allow certain properties to be touched for system personas.
- (JS note) the client side design takes advantage of nested routes, the parent route for personas gets all the personas via this.store.findAll("ai-persona") then child routes simply reach into this model to find a particular persona.
- (JS note) data is sideloaded into the ai-persona model the meta property supplied from the controller, resultSetMeta
- This removes ai_bot_enabled_personas and ai_bot_enabled_chat_commands, both should be controlled from the UI on a per persona basis
- Fixes a long standing bug in token accounting ... we were doing to_json.length instead of to_json.to_s.length
- Amended it so {commands} are always inserted at the end unconditionally, no need to add it to the template of the system message as it just confuses things
- Adds a concept of required_commands to stock personas, these are commands that must be configured for this stock persona to show up.
- Refactored tests so we stop requiring inference_stubs, it was very confusing to need it, added to plugin.rb for now which at least is clearer
- Migrates the persona selector to gjs
---------
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Co-authored-by: Martin Brennan <martin@discourse.org>
2023-11-21 00:56:43 -05:00
|
|
|
|
2023-03-07 13:39:28 -05:00
|
|
|
[
|
2023-03-15 16:21:45 -04:00
|
|
|
DiscourseAi::Embeddings::EntryPoint.new,
|
2023-03-14 15:03:50 -04:00
|
|
|
DiscourseAi::Sentiment::EntryPoint.new,
|
2023-03-15 16:02:20 -04:00
|
|
|
DiscourseAi::AiHelper::EntryPoint.new,
|
2023-04-04 10:24:09 -04:00
|
|
|
DiscourseAi::Summarization::EntryPoint.new,
|
2023-05-05 14:28:31 -04:00
|
|
|
DiscourseAi::AiBot::EntryPoint.new,
|
2023-11-28 23:17:46 -05:00
|
|
|
].each { |a_module| a_module.inject_into(self) }
|
2023-03-07 13:39:28 -05:00
|
|
|
|
2023-03-14 15:03:50 -04:00
|
|
|
register_reviewable_type ReviewableAiChatMessage
|
|
|
|
register_reviewable_type ReviewableAiPost
|
2023-03-07 13:39:28 -05:00
|
|
|
|
|
|
|
on(:reviewable_transitioned_to) do |new_status, reviewable|
|
|
|
|
ModelAccuracy.adjust_model_accuracy(new_status, reviewable)
|
|
|
|
end
|
FEATURE: UI to update ai personas on admin page (#290)
Introduces a UI to manage customizable personas (admin only feature)
Part of the change was some extensive internal refactoring:
- AIBot now has a persona set in the constructor, once set it never changes
- Command now takes in bot as a constructor param, so it has the correct persona and is not generating AIBot objects on the fly
- Added a .prettierignore file, due to the way ALE is configured in nvim it is a pre-req for prettier to work
- Adds a bunch of validations on the AIPersona model, system personas (artist/creative etc...) are all seeded. We now ensure
- name uniqueness, and only allow certain properties to be touched for system personas.
- (JS note) the client side design takes advantage of nested routes, the parent route for personas gets all the personas via this.store.findAll("ai-persona") then child routes simply reach into this model to find a particular persona.
- (JS note) data is sideloaded into the ai-persona model the meta property supplied from the controller, resultSetMeta
- This removes ai_bot_enabled_personas and ai_bot_enabled_chat_commands, both should be controlled from the UI on a per persona basis
- Fixes a long standing bug in token accounting ... we were doing to_json.length instead of to_json.to_s.length
- Amended it so {commands} are always inserted at the end unconditionally, no need to add it to the template of the system message as it just confuses things
- Adds a concept of required_commands to stock personas, these are commands that must be configured for this stock persona to show up.
- Refactored tests so we stop requiring inference_stubs, it was very confusing to need it, added to plugin.rb for now which at least is clearer
- Migrates the persona selector to gjs
---------
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Co-authored-by: Martin Brennan <martin@discourse.org>
2023-11-21 00:56:43 -05:00
|
|
|
|
|
|
|
if Rails.env.test?
|
2023-11-21 02:02:27 -05:00
|
|
|
require_relative "spec/support/embeddings_generation_stubs"
|
2024-01-04 08:44:07 -05:00
|
|
|
require_relative "spec/support/stable_diffusion_stubs"
|
FEATURE: UI to update ai personas on admin page (#290)
Introduces a UI to manage customizable personas (admin only feature)
Part of the change was some extensive internal refactoring:
- AIBot now has a persona set in the constructor, once set it never changes
- Command now takes in bot as a constructor param, so it has the correct persona and is not generating AIBot objects on the fly
- Added a .prettierignore file, due to the way ALE is configured in nvim it is a pre-req for prettier to work
- Adds a bunch of validations on the AIPersona model, system personas (artist/creative etc...) are all seeded. We now ensure
- name uniqueness, and only allow certain properties to be touched for system personas.
- (JS note) the client side design takes advantage of nested routes, the parent route for personas gets all the personas via this.store.findAll("ai-persona") then child routes simply reach into this model to find a particular persona.
- (JS note) data is sideloaded into the ai-persona model the meta property supplied from the controller, resultSetMeta
- This removes ai_bot_enabled_personas and ai_bot_enabled_chat_commands, both should be controlled from the UI on a per persona basis
- Fixes a long standing bug in token accounting ... we were doing to_json.length instead of to_json.to_s.length
- Amended it so {commands} are always inserted at the end unconditionally, no need to add it to the template of the system message as it just confuses things
- Adds a concept of required_commands to stock personas, these are commands that must be configured for this stock persona to show up.
- Refactored tests so we stop requiring inference_stubs, it was very confusing to need it, added to plugin.rb for now which at least is clearer
- Migrates the persona selector to gjs
---------
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
Co-authored-by: Martin Brennan <martin@discourse.org>
2023-11-21 00:56:43 -05:00
|
|
|
end
|
2024-03-12 01:51:41 -04:00
|
|
|
|
2024-10-18 17:01:39 -04:00
|
|
|
reloadable_patch do |plugin|
|
|
|
|
Guardian.prepend DiscourseAi::GuardianExtensions
|
|
|
|
Topic.prepend DiscourseAi::TopicExtensions
|
2024-12-03 08:27:03 -05:00
|
|
|
Post.prepend DiscourseAi::PostExtensions
|
2024-10-18 17:01:39 -04:00
|
|
|
end
|
2024-04-10 20:00:41 -04:00
|
|
|
|
|
|
|
register_modifier(:post_should_secure_uploads?) do |_, _, topic|
|
2024-05-07 07:55:46 -04:00
|
|
|
if topic.private_message? && SharedAiConversation.exists?(target: topic)
|
|
|
|
false
|
|
|
|
else
|
|
|
|
# revert to default behavior
|
|
|
|
# even though this can be shortened this is the clearest way to express it
|
|
|
|
nil
|
|
|
|
end
|
2024-04-10 20:00:41 -04:00
|
|
|
end
|
2023-02-22 18:46:53 -05:00
|
|
|
end
|