Spaces:
Sleeping
Sleeping
Update application/static/js/components/chat.js
Browse files
application/static/js/components/chat.js
CHANGED
@@ -1,44 +1,50 @@
|
|
1 |
-
import requests from "./request.js";
|
2 |
-
|
3 |
-
class Chat{
|
4 |
-
constructor(uiManager){
|
5 |
-
this.uiManager = uiManager;
|
6 |
-
}
|
7 |
-
async chat(){
|
8 |
-
let payload = {
|
9 |
-
"model": this.uiManager.initializer.model,
|
10 |
-
"prompt": this.uiManager.userP.innerText.trim(),
|
11 |
-
"convId": this.uiManager.initializer.convId,
|
12 |
-
"system": this.uiManager.initializer.systemPrompt,
|
13 |
-
"temperature": 0.7,
|
14 |
-
"top_p": 0.9,
|
15 |
-
"webSearch": this.uiManager.webSearch
|
16 |
-
};
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
this.uiManager.
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
this.uiManager.
|
37 |
-
this.uiManager.
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
export default Chat
|
|
|
1 |
+
import requests from "./request.js";
|
2 |
+
|
3 |
+
class Chat{
|
4 |
+
constructor(uiManager){
|
5 |
+
this.uiManager = uiManager;
|
6 |
+
}
|
7 |
+
async chat(){
|
8 |
+
let payload = {
|
9 |
+
"model": this.uiManager.initializer.model,
|
10 |
+
"prompt": this.uiManager.userP.innerText.trim(),
|
11 |
+
"convId": this.uiManager.initializer.convId,
|
12 |
+
"system": this.uiManager.initializer.systemPrompt,
|
13 |
+
"temperature": 0.7,
|
14 |
+
"top_p": 0.9,
|
15 |
+
"webSearch": this.uiManager.webSearch
|
16 |
+
};
|
17 |
+
|
18 |
+
if (this.uiManager.imageMode) {
|
19 |
+
payload.image = this.uiManager.userDiv.querySelector('img')?.src || null;
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
+
try {
|
24 |
+
if(this.uiManager.initializer.convId==null){
|
25 |
+
await this.uiManager.initializer.createConv();
|
26 |
+
payload["convId"] = this.uiManager.initializer.convId;
|
27 |
+
}
|
28 |
+
this.uiManager.textBox.value='';
|
29 |
+
this.uiManager.sendBtn.disabled = true;
|
30 |
+
const response = await requests.request('POST','/completions',{"Content-Type": "application/json"},JSON.stringify(payload),true);
|
31 |
+
for await (const chunk of response){
|
32 |
+
this.uiManager.aiP.innerHTML+=chunk;
|
33 |
+
this.uiManager.renderSymbols.renderAll(this.uiManager.aiP)
|
34 |
+
};
|
35 |
+
} catch (error) {
|
36 |
+
this.uiManager.sendBtn.disabled = false;
|
37 |
+
this.uiManager.aiP.innerHTML+= `<span class="error" style="color: red;">${error}</span>`;
|
38 |
+
return
|
39 |
+
}
|
40 |
+
this.uiManager.renderSymbols.renderCode(this.uiManager.aiP);
|
41 |
+
if(this.uiManager.initializer.convTitle==null){
|
42 |
+
this.uiManager.initializer.convTitle = this.uiManager.userP.innerText.substring(0,23);
|
43 |
+
this.uiManager.addChat();
|
44 |
+
}
|
45 |
+
this.uiManager.sendBtn.disabled = false;
|
46 |
+
|
47 |
+
}
|
48 |
+
}
|
49 |
+
|
50 |
export default Chat
|