Hansimov commited on
Commit
e940bf5
1 Parent(s): 70064ec

:gem: [Feature] Display agent items, and enable clear-agents-button

Browse files
components/buttons_binder.js CHANGED
@@ -13,6 +13,7 @@ import { NewAgentModalWidget } from "../widgets/new_agent_modal_widget.js";
13
  import { screen_scroller } from "./screen_scroller.js";
14
  import { chat_history_storage } from "../storages/chat_history_storage.js";
15
  import { endpoint_storage } from "../storages/endpoint_storage.js";
 
16
 
17
  export class ButtonsBinder {
18
  constructor() {}
@@ -42,6 +43,8 @@ export class ButtonsBinder {
42
  let clear_chat_history_button_binder =
43
  new ClearChatHistoryButtonBinder();
44
  clear_chat_history_button_binder.bind();
 
 
45
  let available_models_select_binder = new AvailableModelsSelectBinder();
46
  available_models_select_binder.bind();
47
  let dark_theme_toggle_button_binder = new DarkThemeToggleButtonBinder();
@@ -332,7 +335,7 @@ class ClearChatAgentsButtonBinder {
332
  button.attr("title", "Clear agents");
333
  button.click(() => {
334
  if (confirm("Clear agents?")) {
335
- // chat_history_storage.clear_database();
336
  } else {
337
  console.log("Clear agents canceled.");
338
  }
 
13
  import { screen_scroller } from "./screen_scroller.js";
14
  import { chat_history_storage } from "../storages/chat_history_storage.js";
15
  import { endpoint_storage } from "../storages/endpoint_storage.js";
16
+ import { agent_storage } from "../storages/agent_storage.js";
17
 
18
  export class ButtonsBinder {
19
  constructor() {}
 
43
  let clear_chat_history_button_binder =
44
  new ClearChatHistoryButtonBinder();
45
  clear_chat_history_button_binder.bind();
46
+ let clear_chat_agents_button_binder = new ClearChatAgentsButtonBinder();
47
+ clear_chat_agents_button_binder.bind();
48
  let available_models_select_binder = new AvailableModelsSelectBinder();
49
  available_models_select_binder.bind();
50
  let dark_theme_toggle_button_binder = new DarkThemeToggleButtonBinder();
 
335
  button.attr("title", "Clear agents");
336
  button.click(() => {
337
  if (confirm("Clear agents?")) {
338
+ agent_storage.clear_database();
339
  } else {
340
  console.log("Clear agents canceled.");
341
  }
configs/agents.json CHANGED
@@ -1,11 +1,38 @@
1
  [
2
  {
3
- "name": "Summarizer",
4
- "description": "Summarizes text",
5
  "temperature": 0.5,
6
  "top_p": 0.9,
7
  "max_output_token": -1,
8
- "system_prompt": "Summarize the following text:",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  "need_protect": false
10
  }
11
  ]
 
1
  [
2
  {
3
+ "name": "默认",
4
+ "description": "默认",
5
  "temperature": 0.5,
6
  "top_p": 0.9,
7
  "max_output_token": -1,
8
+ "system_prompt": "",
9
+ "need_protect": false
10
+ },
11
+ {
12
+ "name": "总结",
13
+ "description": "文本总结",
14
+ "temperature": 0.5,
15
+ "top_p": 0.9,
16
+ "max_output_token": -1,
17
+ "system_prompt": "总结下面的文本:",
18
+ "need_protect": false
19
+ },
20
+ {
21
+ "name": "翻译",
22
+ "description": "文本翻译",
23
+ "temperature": 0.5,
24
+ "top_p": 0.9,
25
+ "max_output_token": -1,
26
+ "system_prompt": "请翻译下面的文本:",
27
+ "need_protect": false
28
+ },
29
+ {
30
+ "name": "搜索",
31
+ "description": "网页搜索",
32
+ "temperature": 0.5,
33
+ "top_p": 0.9,
34
+ "max_output_token": -1,
35
+ "system_prompt": "请根据下列内容搜索网页:",
36
  "need_protect": false
37
  }
38
  ]
storages/agent_storage.js CHANGED
@@ -1,13 +1,20 @@
 
 
 
 
 
 
1
  class AgentStorage {
2
  constructor() {
3
  this.init_database();
4
- this.load_local_agents();
5
- // this.create_agent_items();
 
6
  }
7
  init_database() {
8
  this.db = new Dexie("agents");
9
  this.db.version(1).stores({
10
- agents: "index, name, model, temperature, max_output_tokens, system_prompt, need_protect",
11
  });
12
  this.db.agents.count((count) => {
13
  console.log(`${count} agents loaded.`);
@@ -20,7 +27,7 @@ class AgentStorage {
20
  this.db.agents.clear();
21
  }
22
  async load_local_agents() {
23
- fetch("/agents")
24
  .then((response) => response.json())
25
  .then((data) => {
26
  if (data.error) {
@@ -47,11 +54,26 @@ class AgentStorage {
47
  });
48
  }
49
 
50
- generate_agent_item_html() {
51
- let agent_item_html = ``;
 
 
 
 
 
 
52
  return agent_item_html;
53
  }
54
 
 
 
 
 
 
 
 
 
 
55
  set_default_agent() {
56
  let storage_default_agent = localStorage.getItem("default_agent");
57
 
 
1
+ class AgentStorageItem {
2
+ constructor(agent_storage) {
3
+ this.agent_storage = agent_storage;
4
+ }
5
+ }
6
+
7
  class AgentStorage {
8
  constructor() {
9
  this.init_database();
10
+ this.load_local_agents().then(() => {
11
+ this.create_agent_items();
12
+ });
13
  }
14
  init_database() {
15
  this.db = new Dexie("agents");
16
  this.db.version(1).stores({
17
+ agents: "index, name, model, description, temperature, top_p, max_output_tokens, system_prompt, need_protect",
18
  });
19
  this.db.agents.count((count) => {
20
  console.log(`${count} agents loaded.`);
 
27
  this.db.agents.clear();
28
  }
29
  async load_local_agents() {
30
+ return fetch("/agents")
31
  .then((response) => response.json())
32
  .then((data) => {
33
  if (data.error) {
 
54
  });
55
  }
56
 
57
+ generate_agent_item_html(agent) {
58
+ let agent_item_html = `
59
+ <div class="my-2 row no-gutters">
60
+ <button id="${agent.name}-agent-button" title="${agent.system_prompt}" class="agent-button" type="button">
61
+ <i class="fa fa-arrow-circle-o-right"></i> ${agent.name}
62
+ </button>
63
+ </div>
64
+ `;
65
  return agent_item_html;
66
  }
67
 
68
+ create_agent_items() {
69
+ let chat_agents_sidebar_items = $("#chat-agents-sidebar-items");
70
+ chat_agents_sidebar_items.empty();
71
+ this.db.agents.each((agent) => {
72
+ let agent_item_html = this.generate_agent_item_html(agent);
73
+ chat_agents_sidebar_items.append(agent_item_html);
74
+ });
75
+ }
76
+
77
  set_default_agent() {
78
  let storage_default_agent = localStorage.getItem("default_agent");
79
 
storages/endpoint_storage.js CHANGED
@@ -3,9 +3,10 @@ import { AvailableModelsRequester } from "../networks/llm_requester.js";
3
  class EndpointStorage {
4
  constructor() {
5
  this.init_database();
6
- this.load_local_endpoints();
7
- this.create_endpoint_and_api_key_items();
8
- this.fill_available_models_select();
 
9
  }
10
  init_database() {
11
  this.db = new Dexie("endpoints");
@@ -24,7 +25,7 @@ class EndpointStorage {
24
  this.db.endpoints.clear();
25
  }
26
  async load_local_endpoints() {
27
- fetch("/endpoints")
28
  .then((response) => response.json())
29
  .then((data) => {
30
  if (data.error) {
 
3
  class EndpointStorage {
4
  constructor() {
5
  this.init_database();
6
+ this.load_local_endpoints().then(() => {
7
+ this.create_endpoint_and_api_key_items();
8
+ this.fill_available_models_select();
9
+ });
10
  }
11
  init_database() {
12
  this.db = new Dexie("endpoints");
 
25
  this.db.endpoints.clear();
26
  }
27
  async load_local_endpoints() {
28
+ return fetch("/endpoints")
29
  .then((response) => response.json())
30
  .then((data) => {
31
  if (data.error) {