FIX: forced tools wasn't set correctly when tool has no options. (#1231)
* wip: more dynamic availableForcedTools * FIX: forced tools wasn't set correctly when tool has no options. --------- Co-authored-by: Roman Rizzi <rizziromanalejandro@gmail.com>
This commit is contained in:
parent
f43137e067
commit
28fa723472
|
@ -77,7 +77,11 @@ export default class AiPersona extends RestModel {
|
|||
|
||||
flattenedToolStructure(data) {
|
||||
return (data.tools || []).map((tName) => {
|
||||
return [tName, data.toolOptions[tName], data.forcedTools.includes(tName)];
|
||||
return [
|
||||
tName,
|
||||
data.toolOptions[tName] || {},
|
||||
data.forcedTools.includes(tName),
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ export default class PersonaEditor extends Component {
|
|||
|
||||
@tracked allGroups = [];
|
||||
@tracked isSaving = false;
|
||||
@tracked availableForcedTools = [];
|
||||
|
||||
dirtyFormData = null;
|
||||
|
||||
|
@ -208,10 +207,6 @@ export default class PersonaEditor extends Component {
|
|||
toolOptions: updatedOptions,
|
||||
});
|
||||
|
||||
this.availableForcedTools = this.allTools.filter((tool) =>
|
||||
updatedTools.includes(tool.id)
|
||||
);
|
||||
|
||||
if (currentData.forcedTools?.length > 0) {
|
||||
const updatedForcedTools = currentData.forcedTools.filter(
|
||||
(fct) => !removedTools.includes(fct)
|
||||
|
@ -220,6 +215,11 @@ export default class PersonaEditor extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
@action
|
||||
availableForcedTools(tools) {
|
||||
return this.allTools.filter((tool) => tools.includes(tool.id));
|
||||
}
|
||||
|
||||
mapToolOptions(currentOptions, toolNames) {
|
||||
const updatedOptions = Object.assign({}, currentOptions);
|
||||
|
||||
|
@ -439,7 +439,7 @@ export default class PersonaEditor extends Component {
|
|||
@value={{field.value}}
|
||||
@disabled={{data.system}}
|
||||
@onChange={{field.set}}
|
||||
@content={{this.availableForcedTools}}
|
||||
@content={{this.availableForcedTools data.tools}}
|
||||
/>
|
||||
</field.Custom>
|
||||
</form.Field>
|
||||
|
|
|
@ -27,10 +27,12 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do
|
|||
tool_selector = PageObjects::Components::SelectKit.new("#control-tools .select-kit")
|
||||
tool_selector.expand
|
||||
tool_selector.select_row_by_value("Read")
|
||||
tool_selector.select_row_by_value("ListCategories")
|
||||
tool_selector.collapse
|
||||
|
||||
tool_selector = PageObjects::Components::SelectKit.new("#control-forcedTools .select-kit")
|
||||
tool_selector.expand
|
||||
tool_selector.select_row_by_value("ListCategories")
|
||||
tool_selector.select_row_by_value("Read")
|
||||
tool_selector.collapse
|
||||
|
||||
|
@ -46,8 +48,10 @@ RSpec.describe "Admin AI persona configuration", type: :system, js: true do
|
|||
expect(persona.name).to eq("Test Persona")
|
||||
expect(persona.description).to eq("I am a test persona")
|
||||
expect(persona.system_prompt).to eq("You are a helpful bot")
|
||||
expect(persona.tools).to eq([["Read", { "read_private" => nil }, true]])
|
||||
expect(persona.forced_tool_count).to eq(1)
|
||||
|
||||
expected_tools = [["Read", { "read_private" => nil }, true], ["ListCategories", {}, true]]
|
||||
expect(persona.tools).to contain_exactly(*expected_tools)
|
||||
end
|
||||
|
||||
it "will not allow deletion or editing of system personas" do
|
||||
|
|
Loading…
Reference in New Issue