FEATURE: allow personas to provide command options (#331)
Personas now support providing options for commands. This PR introduces a single option "base_query" for the SearchCommand. When supplied all searches the persona will perform will also include the pre-supplied filter. This can allow personas to search a subset of the forum (such as documentation) This system is extensible we can add options to any command trivially.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
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",
|
||||
};
|
||||
|
||||
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",
|
||||
};
|
||||
|
||||
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"]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user