:gem: [Feature] Enable post with api_key per endpoint
Browse files
configs/endpoints_template.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
[
|
2 |
{
|
3 |
"endpoint": "https://hansimov-hf-llm-api.hf.space/api",
|
4 |
-
"api_key": "
|
5 |
"api_type": "openai",
|
6 |
"need_protect": false
|
7 |
}
|
|
|
1 |
[
|
2 |
{
|
3 |
"endpoint": "https://hansimov-hf-llm-api.hf.space/api",
|
4 |
+
"api_key": "Hansimov",
|
5 |
"api_type": "openai",
|
6 |
"need_protect": false
|
7 |
}
|
networks/llm_requester.js
CHANGED
@@ -27,6 +27,7 @@ export class ChatCompletionsRequester {
|
|
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.system_prompt = this.agent_info.system_prompt;
|
31 |
this.temperature = temperature || this.agent_info.temperature;
|
32 |
this.top_p = top_p || this.agent_info.top_p;
|
@@ -36,9 +37,11 @@ export class ChatCompletionsRequester {
|
|
36 |
this.controller = new AbortController();
|
37 |
}
|
38 |
extract_openai_endpoint_and_model() {
|
39 |
-
let
|
40 |
-
let
|
41 |
-
|
|
|
|
|
42 |
}
|
43 |
construct_openai_request_headers() {
|
44 |
this.backend_request_headers = {
|
@@ -46,7 +49,7 @@ export class ChatCompletionsRequester {
|
|
46 |
};
|
47 |
this.openai_request_headers = {
|
48 |
"Content-Type": "application/json",
|
49 |
-
Authorization: `Bearer ${
|
50 |
};
|
51 |
}
|
52 |
construct_backend_request_body() {
|
|
|
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.openai_api_key = this.extract_openai_endpoint_and_model()[2];
|
31 |
this.system_prompt = this.agent_info.system_prompt;
|
32 |
this.temperature = temperature || this.agent_info.temperature;
|
33 |
this.top_p = top_p || this.agent_info.top_p;
|
|
|
37 |
this.controller = new AbortController();
|
38 |
}
|
39 |
extract_openai_endpoint_and_model() {
|
40 |
+
let splits = this.model_id_with_endpoint.split("|");
|
41 |
+
let openai_endpoint = splits[0];
|
42 |
+
let model = splits[1];
|
43 |
+
let openai_api_key = splits[2];
|
44 |
+
return [openai_endpoint, model, openai_api_key];
|
45 |
}
|
46 |
construct_openai_request_headers() {
|
47 |
this.backend_request_headers = {
|
|
|
49 |
};
|
50 |
this.openai_request_headers = {
|
51 |
"Content-Type": "application/json",
|
52 |
+
Authorization: `Bearer ${this.openai_api_key}`,
|
53 |
};
|
54 |
}
|
55 |
construct_backend_request_body() {
|