2023-12-08 08:42:56 +11:00
|
|
|
import { module, test } from "qunit";
|
|
|
|
import AiPersona from "discourse/plugins/discourse-ai/discourse/admin/models/ai-persona";
|
|
|
|
|
|
|
|
module("Discourse AI | Unit | Model | ai-persona", function () {
|
|
|
|
test("init properties", function (assert) {
|
|
|
|
const properties = {
|
|
|
|
commands: [
|
|
|
|
["CommandName", { option1: "value1", option2: "value2" }],
|
|
|
|
"CommandName2",
|
|
|
|
"CommandName3",
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
const aiPersona = AiPersona.create(properties);
|
|
|
|
|
|
|
|
assert.deepEqual(aiPersona.commands, [
|
|
|
|
"CommandName",
|
|
|
|
"CommandName2",
|
|
|
|
"CommandName3",
|
|
|
|
]);
|
|
|
|
assert.equal(
|
|
|
|
aiPersona.getCommandOption("CommandName", "option1").value,
|
|
|
|
"value1"
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
aiPersona.getCommandOption("CommandName", "option2").value,
|
|
|
|
"value2"
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("update properties", function (assert) {
|
|
|
|
const properties = {
|
|
|
|
id: 1,
|
|
|
|
name: "Test",
|
|
|
|
commands: ["CommandName"],
|
|
|
|
allowed_group_ids: [12],
|
|
|
|
system: false,
|
|
|
|
enabled: true,
|
|
|
|
system_prompt: "System Prompt",
|
|
|
|
priority: false,
|
|
|
|
description: "Description",
|
2024-02-03 07:09:34 +11:00
|
|
|
top_p: 0.8,
|
|
|
|
temperature: 0.7,
|
2024-02-15 16:37:59 +11:00
|
|
|
mentionable: false,
|
|
|
|
default_llm: "Default LLM",
|
|
|
|
user: null,
|
|
|
|
user_id: null,
|
|
|
|
max_context_posts: 5,
|
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-27 14:30:11 +11:00
|
|
|
vision_enabled: true,
|
|
|
|
vision_max_pixels: 100,
|
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 13:43:34 -03:00
|
|
|
rag_uploads: [],
|
2024-04-12 23:32:46 +10:00
|
|
|
rag_chunk_tokens: 374,
|
|
|
|
rag_chunk_overlap_tokens: 10,
|
|
|
|
rag_conversation_chunks: 10,
|
2023-12-08 08:42:56 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
const aiPersona = AiPersona.create({ ...properties });
|
|
|
|
|
|
|
|
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
|
|
|
|
|
|
|
|
const updatedProperties = aiPersona.updateProperties();
|
|
|
|
|
|
|
|
// perform remapping for save
|
|
|
|
properties.commands = [["CommandName", { option1: "value1" }]];
|
|
|
|
|
|
|
|
assert.deepEqual(updatedProperties, properties);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("create properties", function (assert) {
|
|
|
|
const properties = {
|
2024-04-09 11:03:07 -03:00
|
|
|
id: 1,
|
2023-12-08 08:42:56 +11:00
|
|
|
name: "Test",
|
|
|
|
commands: ["CommandName"],
|
|
|
|
allowed_group_ids: [12],
|
|
|
|
system: false,
|
|
|
|
enabled: true,
|
|
|
|
system_prompt: "System Prompt",
|
|
|
|
priority: false,
|
|
|
|
description: "Description",
|
2024-02-03 07:09:34 +11:00
|
|
|
top_p: 0.8,
|
|
|
|
temperature: 0.7,
|
2024-02-15 16:37:59 +11:00
|
|
|
user: null,
|
|
|
|
user_id: null,
|
|
|
|
default_llm: "Default LLM",
|
|
|
|
mentionable: false,
|
|
|
|
max_context_posts: 5,
|
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-27 14:30:11 +11:00
|
|
|
vision_enabled: true,
|
|
|
|
vision_max_pixels: 100,
|
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 13:43:34 -03:00
|
|
|
rag_uploads: [],
|
2024-04-15 23:22:06 +10:00
|
|
|
rag_chunk_tokens: 374,
|
|
|
|
rag_chunk_overlap_tokens: 10,
|
|
|
|
rag_conversation_chunks: 10,
|
2023-12-08 08:42:56 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
const aiPersona = AiPersona.create({ ...properties });
|
|
|
|
|
|
|
|
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
|
|
|
|
|
|
|
|
const createdProperties = aiPersona.createProperties();
|
|
|
|
|
|
|
|
properties.commands = [["CommandName", { option1: "value1" }]];
|
|
|
|
|
|
|
|
assert.deepEqual(createdProperties, properties);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("working copy", function (assert) {
|
|
|
|
const aiPersona = AiPersona.create({
|
|
|
|
name: "Test",
|
|
|
|
commands: ["CommandName"],
|
|
|
|
});
|
|
|
|
|
|
|
|
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
|
|
|
|
|
|
|
|
const workingCopy = aiPersona.workingCopy();
|
|
|
|
|
|
|
|
assert.equal(workingCopy.name, "Test");
|
|
|
|
assert.equal(
|
|
|
|
workingCopy.getCommandOption("CommandName", "option1").value,
|
|
|
|
"value1"
|
|
|
|
);
|
|
|
|
assert.deepEqual(workingCopy.commands, ["CommandName"]);
|
|
|
|
});
|
|
|
|
});
|