Hansimov commited on
Commit
cf83c0e
1 Parent(s): 38880bf

:zap: [Enhance] NewAgentModal: Add top_p and set_to_default button

Browse files
configs/agents.json CHANGED
@@ -2,7 +2,8 @@
2
  {
3
  "name": "Summarizer",
4
  "description": "Summarizes text",
5
- "temperature": 0.0,
 
6
  "max_output_token": -1,
7
  "system_prompt": "Summarize the following text:",
8
  "need_protect": false
 
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
storages/agent_storage.js CHANGED
@@ -30,14 +30,15 @@ class AgentStorage {
30
  let count = Object.keys(data).length;
31
  console.log(`${count} local agents loaded.`);
32
  // data is array of agent items, each item has 7 keys:
33
- // - name, model, description, temperature, max_output_tokens, system_prompt, need_protect
34
  data.forEach((agent) => {
35
  this.db.agents.put({
36
  index: agent.name,
37
  name: agent.name,
38
  description: agent.description || "",
39
  model: agent.model,
40
- temperature: agent.temperature || 0.0,
 
41
  max_output_tokens: agent.max_output_tokens || -1,
42
  system_prompt: agent.system_prompt || "",
43
  need_protect: agent.need_protect || false,
 
30
  let count = Object.keys(data).length;
31
  console.log(`${count} local agents loaded.`);
32
  // data is array of agent items, each item has 7 keys:
33
+ // - name, model, description, temperature, top_p, max_output_tokens, system_prompt, need_protect
34
  data.forEach((agent) => {
35
  this.db.agents.put({
36
  index: agent.name,
37
  name: agent.name,
38
  description: agent.description || "",
39
  model: agent.model,
40
+ temperature: agent.temperature || 0.5,
41
+ top_p: agent.top_p || 0.9,
42
  max_output_tokens: agent.max_output_tokens || -1,
43
  system_prompt: agent.system_prompt || "",
44
  need_protect: agent.need_protect || false,
widgets/new_agent_modal_widget.js CHANGED
@@ -8,9 +8,11 @@ export class NewAgentModalWidget {
8
  this.model_widget_id = `${this.widget_id}-model`;
9
  this.description_widget_id = `${this.widget_id}-description`;
10
  this.temperature_widget_id = `${this.widget_id}-temperature`;
 
11
  this.max_output_tokens_widget_id = `${this.widget_id}-max-output-tokens`;
12
  this.system_prompt_widget_id = `${this.widget_id}-system-prompt`;
13
  this.save_button_id = `${this.widget_id}-save-button`;
 
14
  this.close_button_id = `${this.widget_id}-close-button`;
15
  }
16
  spawn() {
@@ -31,7 +33,7 @@ export class NewAgentModalWidget {
31
  this.temperature_widget = new RangeNumberWidget({
32
  widget_id: this.temperature_widget_id,
33
  label_text: "Temperature",
34
- default_val: 0,
35
  min_val: 0,
36
  max_val: 1,
37
  step_val: 0.1,
@@ -41,10 +43,22 @@ export class NewAgentModalWidget {
41
  );
42
  this.temperature_widget.spawn_in_parent(temperature_widget_parent);
43
  }
 
 
 
 
 
 
 
 
 
 
 
 
44
  create_max_output_tokens_widget() {
45
  this.max_output_tokens_widget = new RangeNumberWidget({
46
  widget_id: this.max_output_tokens_widget_id,
47
- label_text: "Max Output Tokens",
48
  default_val: -1,
49
  min_val: -1,
50
  max_val: 32768,
@@ -86,6 +100,9 @@ export class NewAgentModalWidget {
86
  <!-- temperature -->
87
  <div id="${this.temperature_widget_id}" class="row mb-0"">
88
  </div>
 
 
 
89
  <!-- max output tokens -->
90
  <div id="${this.max_output_tokens_widget_id}" class="row mb-2">
91
  </div>
@@ -99,6 +116,7 @@ export class NewAgentModalWidget {
99
  </div>
100
  <div class="modal-footer justify-content-end">
101
  <button id="${this.save_button_id}" class="btn btn-success">Save</button>
 
102
  <button id="${this.close_button_id}" class="btn btn-secondary"
103
  data-bs-dismiss="modal">Close</button>
104
  </div>
@@ -109,6 +127,7 @@ export class NewAgentModalWidget {
109
  this.widget = $(this.widget_html);
110
  this.create_model_widget();
111
  this.create_temperature_widget();
 
112
  this.create_max_output_tokens_widget();
113
  }
114
  append_to_body() {
 
8
  this.model_widget_id = `${this.widget_id}-model`;
9
  this.description_widget_id = `${this.widget_id}-description`;
10
  this.temperature_widget_id = `${this.widget_id}-temperature`;
11
+ this.top_p_widget_id = `${this.widget_id}-top-p`;
12
  this.max_output_tokens_widget_id = `${this.widget_id}-max-output-tokens`;
13
  this.system_prompt_widget_id = `${this.widget_id}-system-prompt`;
14
  this.save_button_id = `${this.widget_id}-save-button`;
15
+ this.default_button_id = `${this.widget_id}-default-button`;
16
  this.close_button_id = `${this.widget_id}-close-button`;
17
  }
18
  spawn() {
 
33
  this.temperature_widget = new RangeNumberWidget({
34
  widget_id: this.temperature_widget_id,
35
  label_text: "Temperature",
36
+ default_val: 0.5,
37
  min_val: 0,
38
  max_val: 1,
39
  step_val: 0.1,
 
43
  );
44
  this.temperature_widget.spawn_in_parent(temperature_widget_parent);
45
  }
46
+ create_top_p_widget() {
47
+ this.top_p_widget = new RangeNumberWidget({
48
+ widget_id: this.top_p_widget_id,
49
+ label_text: "Top P",
50
+ default_val: 0.9,
51
+ min_val: 0.0,
52
+ max_val: 1.0,
53
+ step_val: 0.01,
54
+ });
55
+ let top_p_widget_parent = this.widget.find(`#${this.top_p_widget_id}`);
56
+ this.top_p_widget.spawn_in_parent(top_p_widget_parent);
57
+ }
58
  create_max_output_tokens_widget() {
59
  this.max_output_tokens_widget = new RangeNumberWidget({
60
  widget_id: this.max_output_tokens_widget_id,
61
+ label_text: "Max Output Tokens <code>(-1: auto)</code>",
62
  default_val: -1,
63
  min_val: -1,
64
  max_val: 32768,
 
100
  <!-- temperature -->
101
  <div id="${this.temperature_widget_id}" class="row mb-0"">
102
  </div>
103
+ <!-- top_p -->
104
+ <div id="${this.top_p_widget_id}" class="row mb-0"">
105
+ </div>
106
  <!-- max output tokens -->
107
  <div id="${this.max_output_tokens_widget_id}" class="row mb-2">
108
  </div>
 
116
  </div>
117
  <div class="modal-footer justify-content-end">
118
  <button id="${this.save_button_id}" class="btn btn-success">Save</button>
119
+ <button id="${this.default_button_id}" class="btn btn-primary">Set to default</button>
120
  <button id="${this.close_button_id}" class="btn btn-secondary"
121
  data-bs-dismiss="modal">Close</button>
122
  </div>
 
127
  this.widget = $(this.widget_html);
128
  this.create_model_widget();
129
  this.create_temperature_widget();
130
+ this.create_top_p_widget();
131
  this.create_max_output_tokens_widget();
132
  }
133
  append_to_body() {