From 0d6d9a6ef59b00520b85b8451bd5bcc15899a1f5 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 19 Jun 2024 15:49:36 +1000 Subject: [PATCH] FEATURE: allow access to private topics if tool permits (#673) Previously read tool only had access to public topics, this allows access to all topics user has access to, if admin opts for the option Also - Fixes VLLM migration - Display which llms have bot enabled --- .../discourse_ai/admin/ai_llms_controller.rb | 2 +- app/models/llm_model.rb | 7 ++- .../components/ai-llms-list-editor.gjs | 28 ++++++++++- config/locales/client.en.yml | 2 +- config/locales/server.en.yml | 4 ++ .../20240603143158_seed_oss_models.rb | 2 +- lib/ai_bot/tools/read.rb | 14 +++--- lib/ai_bot/tools/tool.rb | 2 +- spec/lib/modules/ai_bot/tools/read_spec.rb | 46 +++++++++++++++++++ spec/system/ai_bot/persona_spec.rb | 2 +- 10 files changed, 93 insertions(+), 16 deletions(-) diff --git a/app/controllers/discourse_ai/admin/ai_llms_controller.rb b/app/controllers/discourse_ai/admin/ai_llms_controller.rb index 250dd873..6e3fc321 100644 --- a/app/controllers/discourse_ai/admin/ai_llms_controller.rb +++ b/app/controllers/discourse_ai/admin/ai_llms_controller.rb @@ -6,7 +6,7 @@ module DiscourseAi requires_plugin ::DiscourseAi::PLUGIN_NAME def index - llms = LlmModel.all + llms = LlmModel.all.order(:display_name) render json: { ai_llms: diff --git a/app/models/llm_model.rb b/app/models/llm_model.rb index 4ac22fc1..07c60789 100644 --- a/app/models/llm_model.rb +++ b/app/models/llm_model.rb @@ -18,9 +18,7 @@ class LlmModel < ActiveRecord::Base provider: "vllm", tokenizer: "DiscourseAi::Tokenizer::MixtralTokenizer", url: RESERVED_VLLM_SRV_URL, - vllm_key: "", - user_id: nil, - enabled_chat_bot: false, + max_prompt_tokens: 8000, ) record.save(validate: false) # Ignore reserved URL validation @@ -55,7 +53,8 @@ class LlmModel < ActiveRecord::Base new_user.save!(validate: false) self.update!(user: new_user) else - user.update!(active: true) + user.active = true + user.save!(validate: false) end elsif user # will include deleted diff --git a/assets/javascripts/discourse/components/ai-llms-list-editor.gjs b/assets/javascripts/discourse/components/ai-llms-list-editor.gjs index 13b00bce..03f74b93 100644 --- a/assets/javascripts/discourse/components/ai-llms-list-editor.gjs +++ b/assets/javascripts/discourse/components/ai-llms-list-editor.gjs @@ -1,6 +1,10 @@ import Component from "@glimmer/component"; -import { concat } from "@ember/helper"; +import { concat, fn } from "@ember/helper"; +import { on } from "@ember/modifier"; +import { action } from "@ember/object"; import { LinkTo } from "@ember/routing"; +import DToggleSwitch from "discourse/components/d-toggle-switch"; +import { popupAjaxError } from "discourse/lib/ajax-error"; import icon from "discourse-common/helpers/d-icon"; import i18n from "discourse-common/helpers/i18n"; import I18n from "discourse-i18n"; @@ -11,6 +15,21 @@ export default class AiLlmsListEditor extends Component { return this.args.llms.length !== 0; } + @action + async toggleEnabledChatBot(llm) { + const oldValue = llm.enabled_chat_bot; + const newValue = !oldValue; + try { + llm.set("enabled_chat_bot", newValue); + await llm.update({ + enabled_chat_bot: newValue, + }); + } catch (err) { + llm.set("enabled_chat_bot", oldValue); + popupAjaxError(err); + } + } +