FEATURE: optional tool detail blocks (#662)

This is a rather huge refactor with 1 new feature (tool details can
be suppressed)

Previously we use the name "Command" to describe "Tools", this unifies
all the internal language and simplifies the code.

We also amended the persona UI to use less DToggles which aligns
with our design guidelines.

Co-authored-by: Martin Brennan <[email protected]>
This commit is contained in:
Sam
2024-06-11 18:14:14 +10:00
committed by GitHub
co-authored by Martin Brennan
parent 875bb04467
commit 52a7dd2a4b
85 changed files with 495 additions and 574 deletions
+19 -21
View File
@@ -4,26 +4,22 @@ import AiPersona from "discourse/plugins/discourse-ai/discourse/admin/models/ai-
module("Discourse AI | Unit | Model | ai-persona", function () {
test("init properties", function (assert) {
const properties = {
commands: [
["CommandName", { option1: "value1", option2: "value2" }],
"CommandName2",
"CommandName3",
tools: [
["ToolName", { option1: "value1", option2: "value2" }],
"ToolName2",
"ToolName3",
],
};
const aiPersona = AiPersona.create(properties);
assert.deepEqual(aiPersona.commands, [
"CommandName",
"CommandName2",
"CommandName3",
]);
assert.deepEqual(aiPersona.tools, ["ToolName", "ToolName2", "ToolName3"]);
assert.equal(
aiPersona.getCommandOption("CommandName", "option1").value,
aiPersona.getToolOption("ToolName", "option1").value,
"value1"
);
assert.equal(
aiPersona.getCommandOption("CommandName", "option2").value,
aiPersona.getToolOption("ToolName", "option2").value,
"value2"
);
});
@@ -32,7 +28,7 @@ module("Discourse AI | Unit | Model | ai-persona", function () {
const properties = {
id: 1,
name: "Test",
commands: ["CommandName"],
tools: ["ToolName"],
allowed_group_ids: [12],
system: false,
enabled: true,
@@ -54,16 +50,17 @@ module("Discourse AI | Unit | Model | ai-persona", function () {
rag_conversation_chunks: 10,
question_consolidator_llm: "Question Consolidator LLM",
allow_chat: false,
tool_details: true,
};
const aiPersona = AiPersona.create({ ...properties });
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
aiPersona.getToolOption("ToolName", "option1").value = "value1";
const updatedProperties = aiPersona.updateProperties();
// perform remapping for save
properties.commands = [["CommandName", { option1: "value1" }]];
properties.tools = [["ToolName", { option1: "value1" }]];
assert.deepEqual(updatedProperties, properties);
});
@@ -72,7 +69,7 @@ module("Discourse AI | Unit | Model | ai-persona", function () {
const properties = {
id: 1,
name: "Test",
commands: ["CommandName"],
tools: ["ToolName"],
allowed_group_ids: [12],
system: false,
enabled: true,
@@ -94,15 +91,16 @@ module("Discourse AI | Unit | Model | ai-persona", function () {
rag_conversation_chunks: 10,
question_consolidator_llm: "Question Consolidator LLM",
allow_chat: false,
tool_details: true,
};
const aiPersona = AiPersona.create({ ...properties });
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
aiPersona.getToolOption("ToolName", "option1").value = "value1";
const createdProperties = aiPersona.createProperties();
properties.commands = [["CommandName", { option1: "value1" }]];
properties.tools = [["ToolName", { option1: "value1" }]];
assert.deepEqual(createdProperties, properties);
});
@@ -110,18 +108,18 @@ module("Discourse AI | Unit | Model | ai-persona", function () {
test("working copy", function (assert) {
const aiPersona = AiPersona.create({
name: "Test",
commands: ["CommandName"],
tools: ["ToolName"],
});
aiPersona.getCommandOption("CommandName", "option1").value = "value1";
aiPersona.getToolOption("ToolName", "option1").value = "value1";
const workingCopy = aiPersona.workingCopy();
assert.equal(workingCopy.name, "Test");
assert.equal(
workingCopy.getCommandOption("CommandName", "option1").value,
workingCopy.getToolOption("ToolName", "option1").value,
"value1"
);
assert.deepEqual(workingCopy.commands, ["CommandName"]);
assert.deepEqual(workingCopy.tools, ["ToolName"]);
});
});