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
|
|
|
import Component from "@glimmer/component";
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
import { cached, tracked } from "@glimmer/tracking";
|
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
|
|
|
import { Input } from "@ember/component";
|
|
|
|
import { on } from "@ember/modifier";
|
|
|
|
import { action } from "@ember/object";
|
|
|
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
|
|
|
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
|
2024-02-15 00:37:59 -05:00
|
|
|
import { LinkTo } from "@ember/routing";
|
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
|
|
|
import { later } from "@ember/runloop";
|
2024-11-19 05:57:40 -05:00
|
|
|
import { service } from "@ember/service";
|
2024-03-21 00:29:56 -04:00
|
|
|
import BackButton from "discourse/components/back-button";
|
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
|
|
|
import DButton from "discourse/components/d-button";
|
|
|
|
import Textarea from "discourse/components/d-textarea";
|
|
|
|
import DToggleSwitch from "discourse/components/d-toggle-switch";
|
2024-02-15 00:37:59 -05:00
|
|
|
import Avatar from "discourse/helpers/bound-avatar-template";
|
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
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import Group from "discourse/models/group";
|
|
|
|
import I18n from "discourse-i18n";
|
2024-02-15 00:37:59 -05:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
import ComboBox from "select-kit/components/combo-box";
|
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
|
|
|
import GroupChooser from "select-kit/components/group-chooser";
|
|
|
|
import DTooltip from "float-kit/components/d-tooltip";
|
2024-10-10 16:23:42 -04:00
|
|
|
import AiForcedToolStrategySelector from "./ai-forced-tool-strategy-selector";
|
2024-02-15 00:37:59 -05:00
|
|
|
import AiLlmSelector from "./ai-llm-selector";
|
2024-06-11 04:14:14 -04:00
|
|
|
import AiPersonaToolOptions from "./ai-persona-tool-options";
|
|
|
|
import AiToolSelector from "./ai-tool-selector";
|
2024-09-30 03:27:50 -04:00
|
|
|
import RagOptions from "./rag-options";
|
|
|
|
import RagUploader from "./rag-uploader";
|
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
|
|
|
|
|
|
|
export default class PersonaEditor extends Component {
|
|
|
|
@service router;
|
|
|
|
@service store;
|
|
|
|
@service dialog;
|
|
|
|
@service toasts;
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
@service siteSettings;
|
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
|
|
|
|
|
|
|
@tracked allGroups = [];
|
|
|
|
@tracked isSaving = false;
|
|
|
|
@tracked editingModel = null;
|
|
|
|
@tracked showDelete = false;
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
@tracked maxPixelsValue = null;
|
2024-04-09 10:03:07 -04:00
|
|
|
@tracked ragIndexingStatuses = null;
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
|
2024-10-04 19:46:57 -04:00
|
|
|
@tracked selectedTools = [];
|
|
|
|
@tracked selectedToolNames = [];
|
|
|
|
@tracked forcedToolNames = [];
|
2024-10-15 16:20:31 -04:00
|
|
|
@tracked hasDefaultLlm = false;
|
2024-10-04 19:46:57 -04:00
|
|
|
|
2024-05-05 19:49:02 -04:00
|
|
|
get chatPluginEnabled() {
|
|
|
|
return this.siteSettings.chat_enabled;
|
|
|
|
}
|
|
|
|
|
2024-10-04 19:46:57 -04:00
|
|
|
get allowForceTools() {
|
2024-10-10 16:23:42 -04:00
|
|
|
return !this.editingModel?.system && this.selectedToolNames.length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
get hasForcedTools() {
|
|
|
|
return this.forcedToolNames.length > 0;
|
2024-10-04 19:46:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
forcedToolsChanged(tools) {
|
|
|
|
this.forcedToolNames = tools;
|
|
|
|
this.editingModel.forcedTools = this.forcedToolNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toolsChanged(tools) {
|
|
|
|
this.selectedTools = this.args.personas.resultSetMeta.tools.filter((tool) =>
|
|
|
|
tools.includes(tool.id)
|
|
|
|
);
|
|
|
|
this.selectedToolNames = tools.slice();
|
|
|
|
|
|
|
|
this.forcedToolNames = this.forcedToolNames.filter(
|
|
|
|
(tool) => this.editingModel.tools.indexOf(tool) !== -1
|
|
|
|
);
|
|
|
|
|
|
|
|
this.editingModel.tools = this.selectedToolNames;
|
|
|
|
this.editingModel.forcedTools = this.forcedToolNames;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
@action
|
|
|
|
updateModel() {
|
|
|
|
this.editingModel = this.args.model.workingCopy();
|
2024-10-15 16:20:31 -04:00
|
|
|
this.hasDefaultLlm = !!this.editingModel.default_llm;
|
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
|
|
|
this.showDelete = !this.args.model.isNew && !this.args.model.system;
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
this.maxPixelsValue = this.findClosestPixelValue(
|
|
|
|
this.editingModel.vision_max_pixels
|
|
|
|
);
|
2024-10-04 19:46:57 -04:00
|
|
|
|
|
|
|
this.selectedToolNames = this.editingModel.tools || [];
|
|
|
|
this.selectedTools = this.args.personas.resultSetMeta.tools.filter((tool) =>
|
|
|
|
this.selectedToolNames.includes(tool.id)
|
|
|
|
);
|
|
|
|
this.forcedToolNames = this.editingModel.forcedTools || [];
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
findClosestPixelValue(pixels) {
|
|
|
|
let value = "high";
|
|
|
|
this.maxPixelValues.forEach((info) => {
|
|
|
|
if (pixels === info.pixels) {
|
|
|
|
value = info.id;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@cached
|
|
|
|
get maxPixelValues() {
|
|
|
|
const l = (key) =>
|
|
|
|
I18n.t(`discourse_ai.ai_persona.vision_max_pixel_sizes.${key}`);
|
|
|
|
return [
|
|
|
|
{ id: "low", name: l("low"), pixels: 65536 },
|
|
|
|
{ id: "medium", name: l("medium"), pixels: 262144 },
|
|
|
|
{ id: "high", name: l("high"), pixels: 1048576 },
|
|
|
|
];
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async updateAllGroups() {
|
|
|
|
this.allGroups = await Group.findAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async save() {
|
|
|
|
const isNew = this.args.model.isNew;
|
|
|
|
this.isSaving = true;
|
|
|
|
|
|
|
|
const backupModel = this.args.model.workingCopy();
|
|
|
|
|
|
|
|
this.args.model.setProperties(this.editingModel);
|
|
|
|
try {
|
|
|
|
await this.args.model.save();
|
|
|
|
this.#sortPersonas();
|
2024-04-09 10:03:07 -04:00
|
|
|
if (isNew && this.args.model.rag_uploads.length === 0) {
|
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
|
|
|
this.args.personas.addObject(this.args.model);
|
|
|
|
this.router.transitionTo(
|
2024-05-01 22:42:30 -04:00
|
|
|
"adminPlugins.show.discourse-ai-personas.show",
|
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
|
|
|
this.args.model
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
this.toasts.success({
|
|
|
|
data: { message: I18n.t("discourse_ai.ai_persona.saved") },
|
|
|
|
duration: 2000,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
this.args.model.setProperties(backupModel);
|
|
|
|
popupAjaxError(e);
|
|
|
|
} finally {
|
|
|
|
later(() => {
|
|
|
|
this.isSaving = false;
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-02 15:09:34 -05:00
|
|
|
get showTemperature() {
|
|
|
|
return this.editingModel?.temperature || !this.editingModel?.system;
|
|
|
|
}
|
|
|
|
|
|
|
|
get showTopP() {
|
|
|
|
return this.editingModel?.top_p || !this.editingModel?.system;
|
|
|
|
}
|
|
|
|
|
2024-02-15 00:37:59 -05:00
|
|
|
get adminUser() {
|
|
|
|
return AdminUser.create(this.editingModel?.user);
|
|
|
|
}
|
|
|
|
|
FEATURE: Add Question Consolidator for robust Upload support in Personas (#596)
This commit introduces a new feature for AI Personas called the "Question Consolidator LLM". The purpose of the Question Consolidator is to consolidate a user's latest question into a self-contained, context-rich question before querying the vector database for relevant fragments. This helps improve the quality and relevance of the retrieved fragments.
Previous to this change we used the last 10 interactions, this is not ideal cause the RAG would "lock on" to an answer.
EG:
- User: how many cars are there in europe
- Model: detailed answer about cars in europe including the term car and vehicle many times
- User: Nice, what about trains are there in the US
In the above example "trains" and "US" becomes very low signal given there are pages and pages talking about cars and europe. This mean retrieval is sub optimal.
Instead, we pass the history to the "question consolidator", it would simply consolidate the question to "How many trains are there in the United States", which would make it fare easier for the vector db to find relevant content.
The llm used for question consolidator can often be less powerful than the model you are talking to, we recommend using lighter weight and fast models cause the task is very simple. This is configurable from the persona ui.
This PR also removes support for {uploads} placeholder, this is too complicated to get right and we want freedom to shift RAG implementation.
Key changes:
1. Added a new `question_consolidator_llm` column to the `ai_personas` table to store the LLM model used for question consolidation.
2. Implemented the `QuestionConsolidator` module which handles the logic for consolidating the user's latest question. It extracts the relevant user and model messages from the conversation history, truncates them if needed to fit within the token limit, and generates a consolidated question prompt.
3. Updated the `Persona` class to use the Question Consolidator LLM (if configured) when crafting the RAG fragments prompt. It passes the conversation context to the consolidator to generate a self-contained question.
4. Added UI elements in the AI Persona editor to allow selecting the Question Consolidator LLM. Also made some UI tweaks to conditionally show/hide certain options based on persona configuration.
5. Wrote unit tests for the QuestionConsolidator module and updated existing persona tests to cover the new functionality.
This feature enables AI Personas to better understand the context and intent behind a user's question by consolidating the conversation history into a single, focused question. This can lead to more relevant and accurate responses from the AI assistant.
2024-04-29 23:49:21 -04:00
|
|
|
get mappedQuestionConsolidatorLlm() {
|
|
|
|
return this.editingModel?.question_consolidator_llm || "blank";
|
|
|
|
}
|
|
|
|
|
|
|
|
set mappedQuestionConsolidatorLlm(value) {
|
|
|
|
if (value === "blank") {
|
|
|
|
this.editingModel.question_consolidator_llm = null;
|
|
|
|
} else {
|
|
|
|
this.editingModel.question_consolidator_llm = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-15 00:37:59 -05:00
|
|
|
get mappedDefaultLlm() {
|
|
|
|
return this.editingModel?.default_llm || "blank";
|
|
|
|
}
|
|
|
|
|
|
|
|
set mappedDefaultLlm(value) {
|
|
|
|
if (value === "blank") {
|
|
|
|
this.editingModel.default_llm = null;
|
2024-10-15 16:20:31 -04:00
|
|
|
this.hasDefaultLlm = false;
|
2024-02-15 00:37:59 -05:00
|
|
|
} else {
|
|
|
|
this.editingModel.default_llm = value;
|
2024-10-15 16:20:31 -04:00
|
|
|
this.hasDefaultLlm = true;
|
2024-02-15 00:37:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
@action
|
|
|
|
onChangeMaxPixels(value) {
|
|
|
|
const entry = this.maxPixelValues.findBy("id", value);
|
|
|
|
if (!entry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.maxPixelsValue = value;
|
|
|
|
this.editingModel.vision_max_pixels = entry.pixels;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
@action
|
|
|
|
delete() {
|
|
|
|
return this.dialog.confirm({
|
|
|
|
message: I18n.t("discourse_ai.ai_persona.confirm_delete"),
|
|
|
|
didConfirm: () => {
|
|
|
|
return this.args.model.destroyRecord().then(() => {
|
|
|
|
this.args.personas.removeObject(this.args.model);
|
|
|
|
this.router.transitionTo(
|
2024-05-01 22:42:30 -04:00
|
|
|
"adminPlugins.show.discourse-ai-personas.index"
|
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
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
updateAllowedGroups(ids) {
|
|
|
|
this.editingModel.set("allowed_group_ids", ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async toggleEnabled() {
|
2024-02-15 00:37:59 -05:00
|
|
|
await this.toggleField("enabled");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async togglePriority() {
|
2024-02-15 00:37:59 -05:00
|
|
|
await this.toggleField("priority", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async createUser() {
|
|
|
|
try {
|
|
|
|
let user = await this.args.model.createUser();
|
|
|
|
this.editingModel.set("user", user);
|
|
|
|
this.editingModel.set("user_id", user.id);
|
|
|
|
} catch (e) {
|
|
|
|
popupAjaxError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
@action
|
2024-04-25 09:48:55 -04:00
|
|
|
updateUploads(uploads) {
|
|
|
|
this.editingModel.rag_uploads = uploads;
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
removeUpload(upload) {
|
|
|
|
this.editingModel.rag_uploads.removeObject(upload);
|
2024-04-15 09:22:06 -04:00
|
|
|
if (!this.args.model.isNew) {
|
|
|
|
this.save();
|
|
|
|
}
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
}
|
|
|
|
|
2024-02-15 00:37:59 -05:00
|
|
|
async toggleField(field, sortPersonas) {
|
|
|
|
this.args.model.set(field, !this.args.model[field]);
|
|
|
|
this.editingModel.set(field, this.args.model[field]);
|
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 (!this.args.model.isNew) {
|
|
|
|
try {
|
2024-02-15 00:37:59 -05:00
|
|
|
const args = {};
|
|
|
|
args[field] = this.args.model[field];
|
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
|
|
|
|
2024-02-15 00:37:59 -05:00
|
|
|
await this.args.model.update(args);
|
|
|
|
if (sortPersonas) {
|
|
|
|
this.#sortPersonas();
|
|
|
|
}
|
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
|
|
|
} catch (e) {
|
|
|
|
popupAjaxError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#sortPersonas() {
|
|
|
|
const sorted = this.args.personas.toArray().sort((a, b) => {
|
|
|
|
if (a.priority && !b.priority) {
|
|
|
|
return -1;
|
|
|
|
} else if (!a.priority && b.priority) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return a.name.localeCompare(b.name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.args.personas.clear();
|
|
|
|
this.args.personas.setObjects(sorted);
|
|
|
|
}
|
|
|
|
|
|
|
|
<template>
|
2024-03-21 00:29:56 -04:00
|
|
|
<BackButton
|
2024-05-01 22:42:30 -04:00
|
|
|
@route="adminPlugins.show.discourse-ai-personas"
|
2024-03-21 00:29:56 -04:00
|
|
|
@label="discourse_ai.ai_persona.back"
|
|
|
|
/>
|
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
|
|
|
<form
|
|
|
|
class="form-horizontal ai-persona-editor"
|
|
|
|
{{didUpdate this.updateModel @model.id}}
|
|
|
|
{{didInsert this.updateModel @model.id}}
|
|
|
|
{{didInsert this.updateAllGroups @model.id}}
|
|
|
|
>
|
|
|
|
<div class="control-group">
|
|
|
|
<DToggleSwitch
|
|
|
|
class="ai-persona-editor__enabled"
|
|
|
|
@state={{@model.enabled}}
|
|
|
|
@label="discourse_ai.ai_persona.enabled"
|
|
|
|
{{on "click" this.toggleEnabled}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="control-group ai-persona-editor__priority">
|
|
|
|
<DToggleSwitch
|
|
|
|
class="ai-persona-editor__priority"
|
|
|
|
@state={{@model.priority}}
|
|
|
|
@label="discourse_ai.ai_persona.priority"
|
|
|
|
{{on "click" this.togglePriority}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
2023-12-07 16:42:56 -05:00
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.priority_help"}}
|
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
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.name"}}</label>
|
|
|
|
<Input
|
|
|
|
class="ai-persona-editor__name"
|
|
|
|
@type="text"
|
|
|
|
@value={{this.editingModel.name}}
|
|
|
|
disabled={{this.editingModel.system}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.description"}}</label>
|
|
|
|
<Textarea
|
|
|
|
class="ai-persona-editor__description"
|
|
|
|
@value={{this.editingModel.description}}
|
|
|
|
disabled={{this.editingModel.system}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-10-21 20:16:02 -04:00
|
|
|
{{#if this.editingModel.user}}
|
2024-10-15 16:20:31 -04:00
|
|
|
<div class="control-group">
|
2024-10-21 20:16:02 -04:00
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.default_llm"}}</label>
|
|
|
|
<AiLlmSelector
|
|
|
|
class="ai-persona-editor__llms"
|
|
|
|
@value={{this.mappedDefaultLlm}}
|
|
|
|
@llms={{@personas.resultSetMeta.llms}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.default_llm_help"}}
|
|
|
|
/>
|
2024-10-15 16:20:31 -04:00
|
|
|
</div>
|
2024-10-21 20:16:02 -04:00
|
|
|
{{#if this.hasDefaultLlm}}
|
|
|
|
<div class="control-group">
|
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
|
|
|
@checked={{this.editingModel.force_default_llm}}
|
|
|
|
/>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.force_default_llm"}}</label>
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-10-15 16:20:31 -04:00
|
|
|
{{/if}}
|
2024-02-15 00:37:59 -05:00
|
|
|
{{#unless @model.isNew}}
|
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.user"}}</label>
|
|
|
|
{{#if this.editingModel.user}}
|
|
|
|
<a
|
|
|
|
class="avatar"
|
|
|
|
href={{this.editingModel.user.path}}
|
|
|
|
data-user-card={{this.editingModel.user.username}}
|
|
|
|
>
|
|
|
|
{{Avatar this.editingModel.user.avatar_template "small"}}
|
|
|
|
</a>
|
|
|
|
<LinkTo @route="adminUser" @model={{this.adminUser}}>
|
|
|
|
{{this.editingModel.user.username}}
|
|
|
|
</LinkTo>
|
|
|
|
{{else}}
|
|
|
|
<DButton
|
|
|
|
@action={{this.createUser}}
|
|
|
|
class="ai-persona-editor__create-user"
|
|
|
|
>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.create_user"}}
|
|
|
|
</DButton>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.create_user_help"}}
|
|
|
|
/>
|
|
|
|
{{/if}}
|
|
|
|
</div>
|
|
|
|
{{/unless}}
|
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
|
|
|
<div class="control-group">
|
2024-06-11 04:14:14 -04:00
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.tools"}}</label>
|
|
|
|
<AiToolSelector
|
|
|
|
class="ai-persona-editor__tools"
|
2024-10-04 19:46:57 -04:00
|
|
|
@value={{this.selectedToolNames}}
|
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
|
|
|
@disabled={{this.editingModel.system}}
|
2024-06-11 04:14:14 -04:00
|
|
|
@tools={{@personas.resultSetMeta.tools}}
|
2024-10-04 19:46:57 -04:00
|
|
|
@onChange={{this.toolsChanged}}
|
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
|
|
|
/>
|
|
|
|
</div>
|
2024-10-04 19:46:57 -04:00
|
|
|
{{#if this.allowForceTools}}
|
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.forced_tools"}}</label>
|
|
|
|
<AiToolSelector
|
2024-10-10 16:23:42 -04:00
|
|
|
class="ai-persona-editor__forced_tools"
|
2024-10-04 19:46:57 -04:00
|
|
|
@value={{this.forcedToolNames}}
|
|
|
|
@tools={{this.selectedTools}}
|
|
|
|
@onChange={{this.forcedToolsChanged}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-10-10 16:23:42 -04:00
|
|
|
{{#if this.hasForcedTools}}
|
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.forced_tool_strategy"
|
|
|
|
}}</label>
|
|
|
|
<AiForcedToolStrategySelector
|
|
|
|
class="ai-persona-editor__forced_tool_strategy"
|
|
|
|
@value={{this.editingModel.forced_tool_count}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-10-04 19:46:57 -04:00
|
|
|
{{/if}}
|
2023-12-07 16:42:56 -05:00
|
|
|
{{#unless this.editingModel.system}}
|
2024-06-11 04:14:14 -04:00
|
|
|
<AiPersonaToolOptions
|
2023-12-07 16:42:56 -05:00
|
|
|
@persona={{this.editingModel}}
|
2024-10-04 19:46:57 -04:00
|
|
|
@tools={{this.selectedToolNames}}
|
2024-06-11 04:14:14 -04:00
|
|
|
@allTools={{@personas.resultSetMeta.tools}}
|
2023-12-07 16:42:56 -05:00
|
|
|
/>
|
|
|
|
{{/unless}}
|
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
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.allowed_groups"}}</label>
|
|
|
|
<GroupChooser
|
|
|
|
@value={{this.editingModel.allowed_group_ids}}
|
|
|
|
@content={{this.allGroups}}
|
|
|
|
@onChange={{this.updateAllowedGroups}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="control-group">
|
|
|
|
<label for="ai-persona-editor__system_prompt">{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.system_prompt"
|
|
|
|
}}</label>
|
|
|
|
<Textarea
|
|
|
|
class="ai-persona-editor__system_prompt"
|
|
|
|
@value={{this.editingModel.system_prompt}}
|
|
|
|
disabled={{this.editingModel.system}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-10-15 16:20:31 -04:00
|
|
|
<div class="control-group ai-persona-editor__allow_personal_messages">
|
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
|
|
|
@checked={{this.editingModel.allow_personal_messages}}
|
|
|
|
/>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.allow_personal_messages"}}</label>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_personal_messages_help"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-06-11 04:14:14 -04:00
|
|
|
{{#if this.editingModel.user}}
|
2024-10-15 16:20:31 -04:00
|
|
|
<div class="control-group ai-persona-editor__allow_topic_mentions">
|
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
|
|
|
@checked={{this.editingModel.allow_topic_mentions}}
|
|
|
|
/>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.allow_topic_mentions"}}</label>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_topic_mentions_help"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-06-11 04:14:14 -04:00
|
|
|
{{#if this.chatPluginEnabled}}
|
2024-10-15 16:20:31 -04:00
|
|
|
<div
|
|
|
|
class="control-group ai-persona-editor__allow_chat_direct_messages"
|
|
|
|
>
|
2024-06-11 04:14:14 -04:00
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
2024-10-15 16:20:31 -04:00
|
|
|
@checked={{this.editingModel.allow_chat_direct_messages}}
|
2024-06-11 04:14:14 -04:00
|
|
|
/>
|
2024-10-15 16:20:31 -04:00
|
|
|
{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_chat_direct_messages"
|
|
|
|
}}</label>
|
2024-06-11 04:14:14 -04:00
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
2024-10-15 16:20:31 -04:00
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_chat_direct_messages_help"
|
|
|
|
}}
|
2024-06-11 04:14:14 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2024-10-15 16:20:31 -04:00
|
|
|
<div
|
|
|
|
class="control-group ai-persona-editor__allow_chat_channel_mentions"
|
|
|
|
>
|
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
|
|
|
@checked={{this.editingModel.allow_chat_channel_mentions}}
|
|
|
|
/>
|
|
|
|
{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_chat_channel_mentions"
|
|
|
|
}}</label>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.allow_chat_channel_mentions_help"
|
|
|
|
}}
|
2024-06-11 04:14:14 -04:00
|
|
|
/>
|
2024-10-15 16:20:31 -04:00
|
|
|
</div>
|
|
|
|
{{/if}}
|
2024-06-11 04:14:14 -04:00
|
|
|
{{/if}}
|
|
|
|
<div class="control-group ai-persona-editor__tool-details">
|
|
|
|
<label>
|
|
|
|
<Input @type="checkbox" @checked={{this.editingModel.tool_details}} />
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.tool_details"}}</label>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.tool_details_help"}}
|
2024-02-15 00:37:59 -05:00
|
|
|
/>
|
2024-06-11 04:14:14 -04:00
|
|
|
</div>
|
|
|
|
<div class="control-group ai-persona-editor__vision_enabled">
|
|
|
|
<label>
|
|
|
|
<Input
|
|
|
|
@type="checkbox"
|
|
|
|
@checked={{this.editingModel.vision_enabled}}
|
|
|
|
/>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.vision_enabled"}}</label>
|
2024-02-15 00:37:59 -05:00
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
2024-06-11 04:14:14 -04:00
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.vision_enabled_help"}}
|
2024-02-15 00:37:59 -05:00
|
|
|
/>
|
|
|
|
</div>
|
2024-06-11 04:14:14 -04:00
|
|
|
{{#if this.editingModel.vision_enabled}}
|
FEATURE: Add vision support to AI personas (Claude 3) (#546)
This commit adds the ability to enable vision for AI personas, allowing them to understand images that are posted in the conversation.
For personas with vision enabled, any images the user has posted will be resized to be within the configured max_pixels limit, base64 encoded and included in the prompt sent to the AI provider.
The persona editor allows enabling/disabling vision and has a dropdown to select the max supported image size (low, medium, high). Vision is disabled by default.
This initial vision support has been tested and implemented with Anthropic's claude-3 models which accept images in a special format as part of the prompt.
Other integrations will need to be updated to support images.
Several specs were added to test the new functionality at the persona, prompt building and API layers.
- Gemini is omitted, pending API support for Gemini 1.5. Current Gemini bot is not performing well, adding images is unlikely to make it perform any better.
- Open AI is omitted, vision support on GPT-4 it limited in that the API has no tool support when images are enabled so we would need to full back to a different prompting technique, something that would add lots of complexity
---------
Co-authored-by: Martin Brennan <martin@discourse.org>
2024-03-26 23:30:11 -04:00
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.vision_max_pixels"}}</label>
|
|
|
|
<ComboBox
|
|
|
|
@value={{this.maxPixelsValue}}
|
|
|
|
@content={{this.maxPixelValues}}
|
|
|
|
@onChange={{this.onChangeMaxPixels}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
<div class="control-group">
|
2024-06-11 04:14:14 -04:00
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.max_context_posts"}}</label>
|
|
|
|
<Input
|
|
|
|
@type="number"
|
|
|
|
lang="en"
|
|
|
|
class="ai-persona-editor__max_context_posts"
|
|
|
|
@value={{this.editingModel.max_context_posts}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.max_context_posts_help"}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{{#if this.showTemperature}}
|
|
|
|
<div class="control-group">
|
2024-02-02 15:09:34 -05:00
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.temperature"}}</label>
|
|
|
|
<Input
|
|
|
|
@type="number"
|
|
|
|
class="ai-persona-editor__temperature"
|
2024-03-07 17:54:05 -05:00
|
|
|
step="any"
|
|
|
|
lang="en"
|
2024-02-02 15:09:34 -05:00
|
|
|
@value={{this.editingModel.temperature}}
|
|
|
|
disabled={{this.editingModel.system}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.temperature_help"}}
|
|
|
|
/>
|
2024-06-11 04:14:14 -04:00
|
|
|
</div>
|
|
|
|
{{/if}}
|
|
|
|
{{#if this.showTopP}}
|
|
|
|
<div class="control-group">
|
2024-02-02 15:09:34 -05:00
|
|
|
<label>{{I18n.t "discourse_ai.ai_persona.top_p"}}</label>
|
|
|
|
<Input
|
|
|
|
@type="number"
|
2024-03-07 17:54:05 -05:00
|
|
|
step="any"
|
|
|
|
lang="en"
|
2024-02-02 15:09:34 -05:00
|
|
|
class="ai-persona-editor__top_p"
|
|
|
|
@value={{this.editingModel.top_p}}
|
|
|
|
disabled={{this.editingModel.system}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t "discourse_ai.ai_persona.top_p_help"}}
|
|
|
|
/>
|
2024-06-11 04:14:14 -04:00
|
|
|
</div>
|
|
|
|
{{/if}}
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
{{#if this.siteSettings.ai_embeddings_enabled}}
|
|
|
|
<div class="control-group">
|
2024-09-30 03:27:50 -04:00
|
|
|
<RagUploader
|
|
|
|
@target={{this.editingModel}}
|
2024-04-25 09:48:55 -04:00
|
|
|
@updateUploads={{this.updateUploads}}
|
FEATURE: AI Bot RAG support. (#537)
This PR lets you associate uploads to an AI persona, which we'll split and generate embeddings from. When building the system prompt to get a bot reply, we'll do a similarity search followed by a re-ranking (if available). This will let us find the most relevant fragments from the body of knowledge you associated with the persona, resulting in better, more informed responses.
For now, we'll only allow plain-text files, but this will change in the future.
Commits:
* FEATURE: RAG embeddings for the AI Bot
This first commit introduces a UI where admins can upload text files, which we'll store, split into fragments,
and generate embeddings of. In a next commit, we'll use those to give the bot additional information during
conversations.
* Basic asymmetric similarity search to provide guidance in system prompt
* Fix tests and lint
* Apply reranker to fragments
* Uploads filter, css adjustments and file validations
* Add placeholder for rag fragments
* Update annotations
2024-04-01 12:43:34 -04:00
|
|
|
@onRemove={{this.removeUpload}}
|
|
|
|
/>
|
2024-02-02 15:09:34 -05:00
|
|
|
</div>
|
2024-09-30 03:27:50 -04:00
|
|
|
<RagOptions @model={{this.editingModel}}>
|
2024-04-12 09:32:46 -04:00
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.rag_conversation_chunks"
|
|
|
|
}}</label>
|
|
|
|
<Input
|
|
|
|
@type="number"
|
|
|
|
step="any"
|
|
|
|
lang="en"
|
|
|
|
class="ai-persona-editor__rag_conversation_chunks"
|
|
|
|
@value={{this.editingModel.rag_conversation_chunks}}
|
|
|
|
/>
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.rag_conversation_chunks_help"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
FEATURE: Add Question Consolidator for robust Upload support in Personas (#596)
This commit introduces a new feature for AI Personas called the "Question Consolidator LLM". The purpose of the Question Consolidator is to consolidate a user's latest question into a self-contained, context-rich question before querying the vector database for relevant fragments. This helps improve the quality and relevance of the retrieved fragments.
Previous to this change we used the last 10 interactions, this is not ideal cause the RAG would "lock on" to an answer.
EG:
- User: how many cars are there in europe
- Model: detailed answer about cars in europe including the term car and vehicle many times
- User: Nice, what about trains are there in the US
In the above example "trains" and "US" becomes very low signal given there are pages and pages talking about cars and europe. This mean retrieval is sub optimal.
Instead, we pass the history to the "question consolidator", it would simply consolidate the question to "How many trains are there in the United States", which would make it fare easier for the vector db to find relevant content.
The llm used for question consolidator can often be less powerful than the model you are talking to, we recommend using lighter weight and fast models cause the task is very simple. This is configurable from the persona ui.
This PR also removes support for {uploads} placeholder, this is too complicated to get right and we want freedom to shift RAG implementation.
Key changes:
1. Added a new `question_consolidator_llm` column to the `ai_personas` table to store the LLM model used for question consolidation.
2. Implemented the `QuestionConsolidator` module which handles the logic for consolidating the user's latest question. It extracts the relevant user and model messages from the conversation history, truncates them if needed to fit within the token limit, and generates a consolidated question prompt.
3. Updated the `Persona` class to use the Question Consolidator LLM (if configured) when crafting the RAG fragments prompt. It passes the conversation context to the consolidator to generate a self-contained question.
4. Added UI elements in the AI Persona editor to allow selecting the Question Consolidator LLM. Also made some UI tweaks to conditionally show/hide certain options based on persona configuration.
5. Wrote unit tests for the QuestionConsolidator module and updated existing persona tests to cover the new functionality.
This feature enables AI Personas to better understand the context and intent behind a user's question by consolidating the conversation history into a single, focused question. This can lead to more relevant and accurate responses from the AI assistant.
2024-04-29 23:49:21 -04:00
|
|
|
<div class="control-group">
|
|
|
|
<label>{{I18n.t
|
|
|
|
"discourse_ai.ai_persona.question_consolidator_llm"
|
|
|
|
}}</label>
|
|
|
|
<AiLlmSelector
|
|
|
|
class="ai-persona-editor__llms"
|
|
|
|
@value={{this.mappedQuestionConsolidatorLlm}}
|
|
|
|
@llms={{@personas.resultSetMeta.llms}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<DTooltip
|
|
|
|
@icon="question-circle"
|
|
|
|
@content={{I18n.t
|
|
|
|
"discourse_ai.ai_persona.question_consolidator_llm_help"
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-09-30 03:27:50 -04:00
|
|
|
</RagOptions>
|
2024-02-02 15:09:34 -05:00
|
|
|
{{/if}}
|
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
|
|
|
<div class="control-group ai-persona-editor__action_panel">
|
|
|
|
<DButton
|
|
|
|
class="btn-primary ai-persona-editor__save"
|
|
|
|
@action={{this.save}}
|
|
|
|
@disabled={{this.isSaving}}
|
|
|
|
>{{I18n.t "discourse_ai.ai_persona.save"}}</DButton>
|
|
|
|
{{#if this.showDelete}}
|
|
|
|
<DButton
|
|
|
|
@action={{this.delete}}
|
|
|
|
class="btn-danger ai-persona-editor__delete"
|
|
|
|
>
|
|
|
|
{{I18n.t "discourse_ai.ai_persona.delete"}}
|
|
|
|
</DButton>
|
|
|
|
{{/if}}
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</template>
|
|
|
|
}
|