mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-01 23:09:19 +00:00
1. Personas are now optionally mentionable, meaning that you can mention them either from public topics or PMs - Mentioning from PMs helps "switch" persona mid conversation, meaning if you want to look up sites setting you can invoke the site setting bot, or if you want to generate an image you can invoke dall e - Mentioning outside of PMs allows you to inject a bot reply in a topic trivially - We also add the support for max_context_posts this allow you to limit the amount of context you feed in, which can help control costs 2. Add support for a "random picker" tool that can be used to pick random numbers 3. Clean up routing ai_personas -> ai-personas 4. Add Max Context Posts so users can control how much history a persona can consume (this is important for mentionable personas) Co-authored-by: Martin Brennan <martin@discourse.org>
111 lines
2.9 KiB
JavaScript
111 lines
2.9 KiB
JavaScript
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",
|
|
top_p: 0.8,
|
|
temperature: 0.7,
|
|
mentionable: false,
|
|
default_llm: "Default LLM",
|
|
user: null,
|
|
user_id: null,
|
|
max_context_posts: 5,
|
|
};
|
|
|
|
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 = {
|
|
name: "Test",
|
|
commands: ["CommandName"],
|
|
allowed_group_ids: [12],
|
|
system: false,
|
|
enabled: true,
|
|
system_prompt: "System Prompt",
|
|
priority: false,
|
|
description: "Description",
|
|
top_p: 0.8,
|
|
temperature: 0.7,
|
|
user: null,
|
|
user_id: null,
|
|
default_llm: "Default LLM",
|
|
mentionable: false,
|
|
max_context_posts: 5,
|
|
};
|
|
|
|
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"]);
|
|
});
|
|
});
|