:beers: [Feature] ChatCompletionsRequester: Use cors proxy, and hide secrets in loal
Browse files
apps/llm_mixer/js/llm_requester.js
CHANGED
@@ -2,7 +2,7 @@ import {
|
|
2 |
jsonize_stream_data,
|
3 |
stringify_stream_bytes,
|
4 |
} from "./stream_jsonizer.js";
|
5 |
-
import
|
6 |
import { update_chat, create_chat_block } from "./chat_renderer.js";
|
7 |
|
8 |
export var chat_sessions = [];
|
@@ -27,16 +27,19 @@ export class ChatSession {
|
|
27 |
export class ChatCompletionsRequester {
|
28 |
constructor(
|
29 |
prompt,
|
30 |
-
model = "gpt-3.5-turbo",
|
31 |
temperature = 0,
|
32 |
messages = [],
|
33 |
-
endpoint
|
|
|
34 |
) {
|
35 |
this.prompt = prompt;
|
36 |
this.model = model;
|
37 |
this.temperature = temperature;
|
38 |
this.messages = messages;
|
39 |
-
this.endpoint = endpoint;
|
|
|
|
|
40 |
this.controller = new AbortController();
|
41 |
this.construct_request_params();
|
42 |
}
|
@@ -56,7 +59,7 @@ export class ChatCompletionsRequester {
|
|
56 |
construct_request_headers() {
|
57 |
this.request_headers = {
|
58 |
"Content-Type": "application/json",
|
59 |
-
Authorization: `Bearer ${openai_api_key}`,
|
60 |
};
|
61 |
}
|
62 |
construct_request_body() {
|
@@ -81,7 +84,7 @@ export class ChatCompletionsRequester {
|
|
81 |
post() {
|
82 |
create_chat_block("user", this.prompt);
|
83 |
create_chat_block("assistant");
|
84 |
-
return fetch(this.
|
85 |
.then((response) => response.body)
|
86 |
.then((rb) => {
|
87 |
const reader = rb.getReader();
|
|
|
2 |
jsonize_stream_data,
|
3 |
stringify_stream_bytes,
|
4 |
} from "./stream_jsonizer.js";
|
5 |
+
import * as secrets from "./secrets.js";
|
6 |
import { update_chat, create_chat_block } from "./chat_renderer.js";
|
7 |
|
8 |
export var chat_sessions = [];
|
|
|
27 |
export class ChatCompletionsRequester {
|
28 |
constructor(
|
29 |
prompt,
|
30 |
+
model = "poe-gpt-3.5-turbo",
|
31 |
temperature = 0,
|
32 |
messages = [],
|
33 |
+
endpoint,
|
34 |
+
cors_proxy
|
35 |
) {
|
36 |
this.prompt = prompt;
|
37 |
this.model = model;
|
38 |
this.temperature = temperature;
|
39 |
this.messages = messages;
|
40 |
+
this.endpoint = endpoint || secrets.openai_endpoint;
|
41 |
+
this.cors_proxy = cors_proxy || secrets.cors_proxy;
|
42 |
+
this.request_endpoint = this.cors_proxy + this.endpoint;
|
43 |
this.controller = new AbortController();
|
44 |
this.construct_request_params();
|
45 |
}
|
|
|
59 |
construct_request_headers() {
|
60 |
this.request_headers = {
|
61 |
"Content-Type": "application/json",
|
62 |
+
Authorization: `Bearer ${secrets.openai_api_key}`,
|
63 |
};
|
64 |
}
|
65 |
construct_request_body() {
|
|
|
84 |
post() {
|
85 |
create_chat_block("user", this.prompt);
|
86 |
create_chat_block("assistant");
|
87 |
+
return fetch(this.request_endpoint, this.request_params)
|
88 |
.then((response) => response.body)
|
89 |
.then((rb) => {
|
90 |
const reader = rb.getReader();
|