Spaces:
Runtime error
Runtime error
Update application/static/js/components/chat.js
Browse files
application/static/js/components/chat.js
CHANGED
|
@@ -1,43 +1,43 @@
|
|
| 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.
|
| 14 |
-
"top_p": 0.9
|
| 15 |
-
};
|
| 16 |
-
try {
|
| 17 |
-
if(this.uiManager.initializer.convId==null){
|
| 18 |
-
await this.uiManager.initializer.createConv();
|
| 19 |
-
payload["convId"] = this.uiManager.initializer.convId;
|
| 20 |
-
}
|
| 21 |
-
this.uiManager.textBox.value='';
|
| 22 |
-
this.uiManager.sendBtn.disabled = true;
|
| 23 |
-
const response = await requests.request('POST','/completions',{"Content-Type": "application/json"},JSON.stringify(payload),true);
|
| 24 |
-
for await (const chunk of response){
|
| 25 |
-
this.uiManager.aiP.innerHTML+=chunk;
|
| 26 |
-
this.uiManager.renderSymbols.renderAll(this.uiManager.aiP)
|
| 27 |
-
};
|
| 28 |
-
} catch (error) {
|
| 29 |
-
this.uiManager.sendBtn.disabled = false;
|
| 30 |
-
this.uiManager.aiP.innerHTML+= `<span class="error" style="color: red;">${error}</span>`;
|
| 31 |
-
return
|
| 32 |
-
}
|
| 33 |
-
this.uiManager.renderSymbols.renderCode(this.uiManager.aiP);
|
| 34 |
-
if(this.uiManager.initializer.convTitle==null){
|
| 35 |
-
this.uiManager.initializer.convTitle = this.uiManager.userP.innerText.substring(0,23);
|
| 36 |
-
this.uiManager.addChat();
|
| 37 |
-
}
|
| 38 |
-
this.uiManager.sendBtn.disabled = false;
|
| 39 |
-
|
| 40 |
-
}
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
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 |
+
};
|
| 16 |
+
try {
|
| 17 |
+
if(this.uiManager.initializer.convId==null){
|
| 18 |
+
await this.uiManager.initializer.createConv();
|
| 19 |
+
payload["convId"] = this.uiManager.initializer.convId;
|
| 20 |
+
}
|
| 21 |
+
this.uiManager.textBox.value='';
|
| 22 |
+
this.uiManager.sendBtn.disabled = true;
|
| 23 |
+
const response = await requests.request('POST','/completions',{"Content-Type": "application/json"},JSON.stringify(payload),true);
|
| 24 |
+
for await (const chunk of response){
|
| 25 |
+
this.uiManager.aiP.innerHTML+=chunk;
|
| 26 |
+
this.uiManager.renderSymbols.renderAll(this.uiManager.aiP)
|
| 27 |
+
};
|
| 28 |
+
} catch (error) {
|
| 29 |
+
this.uiManager.sendBtn.disabled = false;
|
| 30 |
+
this.uiManager.aiP.innerHTML+= `<span class="error" style="color: red;">${error}</span>`;
|
| 31 |
+
return
|
| 32 |
+
}
|
| 33 |
+
this.uiManager.renderSymbols.renderCode(this.uiManager.aiP);
|
| 34 |
+
if(this.uiManager.initializer.convTitle==null){
|
| 35 |
+
this.uiManager.initializer.convTitle = this.uiManager.userP.innerText.substring(0,23);
|
| 36 |
+
this.uiManager.addChat();
|
| 37 |
+
}
|
| 38 |
+
this.uiManager.sendBtn.disabled = false;
|
| 39 |
+
|
| 40 |
+
}
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
export default Chat
|