Hansimov commited on
Commit
6828f2e
1 Parent(s): c664292

:gem: [Feature] Auto trigger model select in agent info

Browse files
configs/agents.json CHANGED
@@ -12,22 +12,22 @@
12
  {
13
  "name": "总结",
14
  "description": "文本总结",
15
- "model": "openchat-3.5",
16
  "system_prompt": "请用中文总结下面的文本:",
17
  "need_protect": false
18
  },
19
  {
20
  "name": "翻译",
21
  "description": "文本翻译",
22
- "model": "openchat-3.5",
23
  "system_prompt": "请用中文翻译下面的文本:",
24
  "need_protect": false
25
  },
26
  {
27
  "name": "搜索",
28
  "description": "网页搜索",
29
- "model": "openchat-3.5",
30
  "system_prompt": "请根据下列内容搜索网页:",
31
  "need_protect": false
32
  }
33
- ]
 
12
  {
13
  "name": "总结",
14
  "description": "文本总结",
15
+ "model": "nous-mixtral-8x7b",
16
  "system_prompt": "请用中文总结下面的文本:",
17
  "need_protect": false
18
  },
19
  {
20
  "name": "翻译",
21
  "description": "文本翻译",
22
+ "model": "nous-mixtral-8x7b",
23
  "system_prompt": "请用中文翻译下面的文本:",
24
  "need_protect": false
25
  },
26
  {
27
  "name": "搜索",
28
  "description": "网页搜索",
29
+ "model": "nous-mixtral-8x7b",
30
  "system_prompt": "请根据下列内容搜索网页:",
31
  "need_protect": false
32
  }
33
+ ]
widgets/agent_info_widget.js CHANGED
@@ -42,27 +42,40 @@ export class AgentInfoWidget {
42
  create_name_widget() {
43
  this.widget.find(`#${this.name_widget_id}`).val(this.agent.name);
44
  }
45
- create_model_widget() {
46
- this.model_widget = new AvailableModelsSelectWidget({
47
- widget_id: this.model_widget_id,
48
- });
49
- let model_widget_parent = this.widget.find(`#${this.model_widget_id}`);
50
  let model_select = this.widget.find(`#${this.model_widget_id}-select`);
51
  let agent_model = this.agent.model;
 
52
  let model_matched = false;
53
  model_select.find("option").each(function () {
54
  let option_model = $(this).val().split("|")[1];
55
- console.log("option_model:", option_model);
56
  if (option_model === agent_model) {
57
  model_select.val($(this).val());
58
  model_matched = true;
 
 
 
 
59
  }
60
  });
61
  if (!model_matched) {
62
- console.log("No model matched for:", agent_model);
 
 
 
 
63
  }
64
-
 
 
 
 
 
65
  this.model_widget.spawn_in_parent(model_widget_parent, "prepend");
 
 
 
 
66
  }
67
  create_system_prompt_widget() {
68
  this.widget
 
42
  create_name_widget() {
43
  this.widget.find(`#${this.name_widget_id}`).val(this.agent.name);
44
  }
45
+ update_model_widget() {
 
 
 
 
46
  let model_select = this.widget.find(`#${this.model_widget_id}-select`);
47
  let agent_model = this.agent.model;
48
+ let agent_name = this.agent.name;
49
  let model_matched = false;
50
  model_select.find("option").each(function () {
51
  let option_model = $(this).val().split("|")[1];
 
52
  if (option_model === agent_model) {
53
  model_select.val($(this).val());
54
  model_matched = true;
55
+ console.log(
56
+ `Model matched [${agent_model}] for agent [${agent_name}].`
57
+ );
58
+ return false;
59
  }
60
  });
61
  if (!model_matched) {
62
+ let default_model = model_select.find("option:first").val();
63
+ model_select.val(default_model);
64
+ console.log(
65
+ `No model matched [${agent_model}] for agent [${agent_name}].`
66
+ );
67
  }
68
+ }
69
+ create_model_widget() {
70
+ this.model_widget = new AvailableModelsSelectWidget({
71
+ widget_id: this.model_widget_id,
72
+ });
73
+ let model_widget_parent = this.widget.find(`#${this.model_widget_id}`);
74
  this.model_widget.spawn_in_parent(model_widget_parent, "prepend");
75
+ this.update_model_widget();
76
+ $(document).on("available_models_select:change", () => {
77
+ this.update_model_widget();
78
+ });
79
  }
80
  create_system_prompt_widget() {
81
  this.widget
widgets/available_models_select_widget.js CHANGED
@@ -33,6 +33,7 @@ export class AvailableModelsSelectWidget {
33
  for (let mutation of mutationsList) {
34
  if (mutation.type === "childList") {
35
  this.update_select_options();
 
36
  }
37
  }
38
  });
 
33
  for (let mutation of mutationsList) {
34
  if (mutation.type === "childList") {
35
  this.update_select_options();
36
+ $(document).trigger("available_models_select:change");
37
  }
38
  }
39
  });