:gem: [Feature] Request with parameters of current agent
Browse files- components/chat_operator.js +1 -7
- index.html +1 -1
- networks/llm_requester.js +20 -15
- storages/agent_storage.js +29 -0
- widgets/agent_info_widget.js +4 -4
components/chat_operator.js
CHANGED
@@ -19,17 +19,11 @@ export function get_latest_messager() {
|
|
19 |
return get_active_messager_list().messagers.slice(-1)[0];
|
20 |
}
|
21 |
|
22 |
-
export function create_messager(
|
23 |
-
role,
|
24 |
-
content = "",
|
25 |
-
model = "",
|
26 |
-
temperature = ""
|
27 |
-
) {
|
28 |
let message = {
|
29 |
role: role,
|
30 |
content: content,
|
31 |
model: model,
|
32 |
-
temperature: temperature,
|
33 |
};
|
34 |
let messager = new Messager(message);
|
35 |
get_active_messager_list().push(messager);
|
|
|
19 |
return get_active_messager_list().messagers.slice(-1)[0];
|
20 |
}
|
21 |
|
22 |
+
export function create_messager(role, content = "", model = "") {
|
|
|
|
|
|
|
|
|
|
|
23 |
let message = {
|
24 |
role: role,
|
25 |
content: content,
|
26 |
model: model,
|
|
|
27 |
};
|
28 |
let messager = new Messager(message);
|
29 |
get_active_messager_list().push(messager);
|
index.html
CHANGED
@@ -73,7 +73,7 @@
|
|
73 |
<i class="fa fa-plus"></i> New Agent
|
74 |
</button>
|
75 |
</div>
|
76 |
-
<div id="agent-info"></div>
|
77 |
</div>
|
78 |
<div class="my-2 row no-gutters justify-content-start">
|
79 |
<div class="col">
|
|
|
73 |
<i class="fa fa-plus"></i> New Agent
|
74 |
</button>
|
75 |
</div>
|
76 |
+
<div id="agent-info-container"></div>
|
77 |
</div>
|
78 |
<div class="my-2 row no-gutters justify-content-start">
|
79 |
<div class="col">
|
networks/llm_requester.js
CHANGED
@@ -6,33 +6,38 @@ import {
|
|
6 |
update_message,
|
7 |
create_messager,
|
8 |
get_request_messages,
|
9 |
-
get_selected_llm_model,
|
10 |
-
get_selected_temperature,
|
11 |
ContentDisplayerUpdater,
|
12 |
} from "../components/chat_operator.js";
|
13 |
|
|
|
|
|
14 |
export class ChatCompletionsRequester {
|
15 |
constructor({
|
16 |
prompt,
|
17 |
model = null,
|
18 |
-
temperature = 0.5,
|
19 |
-
top_p = 0.95,
|
20 |
openai_endpoint = null,
|
|
|
|
|
|
|
21 |
} = {}) {
|
|
|
|
|
22 |
this.prompt = prompt;
|
|
|
23 |
this.openai_endpoint =
|
24 |
-
openai_endpoint || this.
|
25 |
-
this.model = model || this.
|
26 |
-
this.temperature = temperature;
|
27 |
-
this.top_p = top_p;
|
|
|
|
|
28 |
this.backend_request_endpoint = "/chat/completions";
|
29 |
this.controller = new AbortController();
|
30 |
}
|
31 |
-
|
32 |
-
let
|
33 |
-
|
34 |
-
|
35 |
-
return [this.openai_endpoint, this.model];
|
36 |
}
|
37 |
construct_openai_request_headers() {
|
38 |
this.backend_request_headers = {
|
@@ -54,6 +59,7 @@ export class ChatCompletionsRequester {
|
|
54 |
messages: this.openai_request_messages,
|
55 |
temperature: this.temperature,
|
56 |
top_p: this.top_p,
|
|
|
57 |
stream: true,
|
58 |
},
|
59 |
};
|
@@ -71,7 +77,7 @@ export class ChatCompletionsRequester {
|
|
71 |
}
|
72 |
create_messager_components() {
|
73 |
create_messager("user", this.prompt);
|
74 |
-
create_messager("assistant", "", this.model
|
75 |
}
|
76 |
async handle_read_stream_data(reader) {
|
77 |
let buffer = "";
|
@@ -112,7 +118,6 @@ export class ChatCompletionsRequester {
|
|
112 |
}
|
113 |
}
|
114 |
|
115 |
-
// export var available_models = { "user-customized": ["notes"] };
|
116 |
export class AvailableModelsRequester {
|
117 |
constructor(openai_endpoint) {
|
118 |
this.openai_endpoint = openai_endpoint;
|
|
|
6 |
update_message,
|
7 |
create_messager,
|
8 |
get_request_messages,
|
|
|
|
|
9 |
ContentDisplayerUpdater,
|
10 |
} from "../components/chat_operator.js";
|
11 |
|
12 |
+
import { get_current_agent_info } from "../storages/agent_storage.js";
|
13 |
+
|
14 |
export class ChatCompletionsRequester {
|
15 |
constructor({
|
16 |
prompt,
|
17 |
model = null,
|
|
|
|
|
18 |
openai_endpoint = null,
|
19 |
+
temperature = null,
|
20 |
+
top_p = null,
|
21 |
+
max_output_tokens = null,
|
22 |
} = {}) {
|
23 |
+
this.agent_info = get_current_agent_info();
|
24 |
+
console.log("agent_info:", this.agent_info);
|
25 |
this.prompt = prompt;
|
26 |
+
this.model_id_with_endpoint = this.agent_info.model;
|
27 |
this.openai_endpoint =
|
28 |
+
openai_endpoint || this.extract_openai_endpoint_and_model()[0];
|
29 |
+
this.model = model || this.extract_openai_endpoint_and_model()[1];
|
30 |
+
this.temperature = temperature || this.agent_info.temperature;
|
31 |
+
this.top_p = top_p || this.agent_info.top_p;
|
32 |
+
this.max_output_tokens =
|
33 |
+
max_output_tokens || this.agent_info.max_output_tokens;
|
34 |
this.backend_request_endpoint = "/chat/completions";
|
35 |
this.controller = new AbortController();
|
36 |
}
|
37 |
+
extract_openai_endpoint_and_model() {
|
38 |
+
let openai_endpoint = this.model_id_with_endpoint.split("|")[0];
|
39 |
+
let model = this.model_id_with_endpoint.split("|")[1];
|
40 |
+
return [openai_endpoint, model];
|
|
|
41 |
}
|
42 |
construct_openai_request_headers() {
|
43 |
this.backend_request_headers = {
|
|
|
59 |
messages: this.openai_request_messages,
|
60 |
temperature: this.temperature,
|
61 |
top_p: this.top_p,
|
62 |
+
max_tokens: this.max_output_tokens,
|
63 |
stream: true,
|
64 |
},
|
65 |
};
|
|
|
77 |
}
|
78 |
create_messager_components() {
|
79 |
create_messager("user", this.prompt);
|
80 |
+
create_messager("assistant", "", this.model);
|
81 |
}
|
82 |
async handle_read_stream_data(reader) {
|
83 |
let buffer = "";
|
|
|
118 |
}
|
119 |
}
|
120 |
|
|
|
121 |
export class AvailableModelsRequester {
|
122 |
constructor(openai_endpoint) {
|
123 |
this.openai_endpoint = openai_endpoint;
|
storages/agent_storage.js
CHANGED
@@ -6,6 +6,35 @@ class AgentStorageItem {
|
|
6 |
}
|
7 |
}
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class AgentStorage {
|
10 |
constructor() {
|
11 |
this.init_database();
|
|
|
6 |
}
|
7 |
}
|
8 |
|
9 |
+
export function get_current_agent_info() {
|
10 |
+
let widget_id = "agent-info";
|
11 |
+
let agent_info_widget = $(`#${widget_id}`);
|
12 |
+
let name = agent_info_widget.find(`#${widget_id}-name`).val();
|
13 |
+
let model = agent_info_widget.find(`#${widget_id}-model-select`).val();
|
14 |
+
let system_prompt = agent_info_widget
|
15 |
+
.find(`#${widget_id}-system-prompt`)
|
16 |
+
.val();
|
17 |
+
let description = agent_info_widget.find(`#${widget_id}-description`).val();
|
18 |
+
let temperature = parseFloat(
|
19 |
+
agent_info_widget.find(`#${widget_id}-temperature-number`).val()
|
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 |
+
agent_info_widget.find(`#${widget_id}-max-output-tokens-number`).val()
|
26 |
+
);
|
27 |
+
return {
|
28 |
+
name: name,
|
29 |
+
model: model,
|
30 |
+
system_prompt: system_prompt,
|
31 |
+
description: description,
|
32 |
+
temperature: temperature,
|
33 |
+
top_p: top_p,
|
34 |
+
max_output_tokens: max_output_tokens,
|
35 |
+
};
|
36 |
+
}
|
37 |
+
|
38 |
class AgentStorage {
|
39 |
constructor() {
|
40 |
this.init_database();
|
widgets/agent_info_widget.js
CHANGED
@@ -4,7 +4,7 @@ import { AvailableModelsSelectWidget } from "./available_models_select_widget.js
|
|
4 |
export class AgentInfoWidget {
|
5 |
constructor({ agent } = {}) {
|
6 |
this.agent = agent;
|
7 |
-
this.widget_id = `agent-
|
8 |
this.name_widget_id = `${this.widget_id}-name`;
|
9 |
this.model_widget_id = `${this.widget_id}-model`;
|
10 |
this.description_widget_id = `${this.widget_id}-description`;
|
@@ -18,9 +18,9 @@ export class AgentInfoWidget {
|
|
18 |
this.append_to_agent_sidebar();
|
19 |
}
|
20 |
append_to_agent_sidebar() {
|
21 |
-
let
|
22 |
-
|
23 |
-
|
24 |
document
|
25 |
.getElementById(`${this.system_prompt_widget_id}`)
|
26 |
.addEventListener(
|
|
|
4 |
export class AgentInfoWidget {
|
5 |
constructor({ agent } = {}) {
|
6 |
this.agent = agent;
|
7 |
+
this.widget_id = `agent-info`;
|
8 |
this.name_widget_id = `${this.widget_id}-name`;
|
9 |
this.model_widget_id = `${this.widget_id}-model`;
|
10 |
this.description_widget_id = `${this.widget_id}-description`;
|
|
|
18 |
this.append_to_agent_sidebar();
|
19 |
}
|
20 |
append_to_agent_sidebar() {
|
21 |
+
let agent_info_container = $("#agent-info-container");
|
22 |
+
agent_info_container.empty();
|
23 |
+
agent_info_container.append(this.widget);
|
24 |
document
|
25 |
.getElementById(`${this.system_prompt_widget_id}`)
|
26 |
.addEventListener(
|