:gem: [Feature] Sync agent info when select value changed
Browse files- components/buttons_binder.js +1 -0
- storages/agent_storage.js +30 -17
components/buttons_binder.js
CHANGED
@@ -366,6 +366,7 @@ class AgentsSelectBinder {
|
|
366 |
select.change(() => {
|
367 |
localStorage.setItem("default_agent", select.val());
|
368 |
console.log("set default_agent:", select.val());
|
|
|
369 |
});
|
370 |
}
|
371 |
}
|
|
|
366 |
select.change(() => {
|
367 |
localStorage.setItem("default_agent", select.val());
|
368 |
console.log("set default_agent:", select.val());
|
369 |
+
agent_storage.set_agent_info_widget();
|
370 |
});
|
371 |
}
|
372 |
}
|
storages/agent_storage.js
CHANGED
@@ -7,22 +7,18 @@ class AgentStorageItem {
|
|
7 |
}
|
8 |
|
9 |
export function get_current_agent_info() {
|
10 |
-
let
|
11 |
-
let
|
12 |
-
let name =
|
13 |
-
let model =
|
14 |
-
let system_prompt =
|
15 |
-
|
16 |
-
.val();
|
17 |
-
let description = agent_info_widget.find(`#${widget_id}-description`).val();
|
18 |
let temperature = parseFloat(
|
19 |
-
|
20 |
-
);
|
21 |
-
let top_p = parseFloat(
|
22 |
-
agent_info_widget.find(`#${widget_id}-top-p-number`).val()
|
23 |
);
|
|
|
24 |
let max_output_tokens = parseInt(
|
25 |
-
|
26 |
);
|
27 |
return {
|
28 |
name: name,
|
@@ -73,12 +69,12 @@ class AgentStorage {
|
|
73 |
this.db.agents.put({
|
74 |
index: agent.index || agent.name,
|
75 |
name: agent.name,
|
76 |
-
description: agent.description || "",
|
77 |
model: agent.model,
|
|
|
|
|
78 |
temperature: agent.temperature || 0.5,
|
79 |
top_p: agent.top_p || 0.9,
|
80 |
max_output_tokens: agent.max_output_tokens || -1,
|
81 |
-
system_prompt: agent.system_prompt || "",
|
82 |
need_protect: agent.need_protect || false,
|
83 |
});
|
84 |
});
|
@@ -98,7 +94,7 @@ class AgentStorage {
|
|
98 |
});
|
99 |
Promise.all(promises).then(() => {
|
100 |
this.set_default_agent();
|
101 |
-
this.
|
102 |
});
|
103 |
});
|
104 |
}
|
@@ -130,7 +126,7 @@ class AgentStorage {
|
|
130 |
console.log("current_agent_name:", current_agent_name);
|
131 |
return this.db.agents.get(current_agent_name);
|
132 |
}
|
133 |
-
|
134 |
this.get_current_agent().then((agent) => {
|
135 |
let agent_info_widget = new AgentInfoWidget({
|
136 |
agent: agent,
|
@@ -138,6 +134,23 @@ class AgentStorage {
|
|
138 |
agent_info_widget.spawn();
|
139 |
});
|
140 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
}
|
142 |
|
143 |
export let agent_storage = new AgentStorage();
|
|
|
7 |
}
|
8 |
|
9 |
export function get_current_agent_info() {
|
10 |
+
let id = "agent-info";
|
11 |
+
let widget = $(`#${id}`);
|
12 |
+
let name = widget.find(`#${id}-name`).val();
|
13 |
+
let model = widget.find(`#${id}-model-select`).val();
|
14 |
+
let system_prompt = widget.find(`#${id}-system-prompt`).val();
|
15 |
+
let description = widget.find(`#${id}-description`).val();
|
|
|
|
|
16 |
let temperature = parseFloat(
|
17 |
+
widget.find(`#${id}-temperature-number`).val()
|
|
|
|
|
|
|
18 |
);
|
19 |
+
let top_p = parseFloat(widget.find(`#${id}-top-p-number`).val());
|
20 |
let max_output_tokens = parseInt(
|
21 |
+
widget.find(`#${id}-max-output-tokens-number`).val()
|
22 |
);
|
23 |
return {
|
24 |
name: name,
|
|
|
69 |
this.db.agents.put({
|
70 |
index: agent.index || agent.name,
|
71 |
name: agent.name,
|
|
|
72 |
model: agent.model,
|
73 |
+
system_prompt: agent.system_prompt || "",
|
74 |
+
description: agent.description || "",
|
75 |
temperature: agent.temperature || 0.5,
|
76 |
top_p: agent.top_p || 0.9,
|
77 |
max_output_tokens: agent.max_output_tokens || -1,
|
|
|
78 |
need_protect: agent.need_protect || false,
|
79 |
});
|
80 |
});
|
|
|
94 |
});
|
95 |
Promise.all(promises).then(() => {
|
96 |
this.set_default_agent();
|
97 |
+
this.set_agent_info_widget();
|
98 |
});
|
99 |
});
|
100 |
}
|
|
|
126 |
console.log("current_agent_name:", current_agent_name);
|
127 |
return this.db.agents.get(current_agent_name);
|
128 |
}
|
129 |
+
set_agent_info_widget() {
|
130 |
this.get_current_agent().then((agent) => {
|
131 |
let agent_info_widget = new AgentInfoWidget({
|
132 |
agent: agent,
|
|
|
134 |
agent_info_widget.spawn();
|
135 |
});
|
136 |
}
|
137 |
+
get_agent_info(name = "") {
|
138 |
+
let agent_info = {};
|
139 |
+
if (name === "") {
|
140 |
+
name = $("#agents-select").val();
|
141 |
+
}
|
142 |
+
this.db.agents.get(name).then((agent) => {
|
143 |
+
agent_info.name = agent.name;
|
144 |
+
agent_info.model = agent.model;
|
145 |
+
agent_info.system_prompt = agent.system_prompt;
|
146 |
+
agent_info.description = agent.description;
|
147 |
+
agent_info.temperature = agent.temperature;
|
148 |
+
agent_info.top_p = agent.top_p;
|
149 |
+
agent_info.max_output_tokens = agent.max_output_tokens;
|
150 |
+
agent_info.need_protect = agent.need_protect;
|
151 |
+
return agent_info;
|
152 |
+
});
|
153 |
+
}
|
154 |
}
|
155 |
|
156 |
export let agent_storage = new AgentStorage();
|