msl 1 year ago
parent 332627eddd
commit bd2b81d8f9

@ -41,18 +41,17 @@
if (message) { if (message) {
$$("#messageInput").val(''); $$("#messageInput").val('');
$$("#hidep").append("{'role': 'user', 'content':'"+message+"'},") $$("#hidep").append("{'role': 'user', 'content':'''"+message+"'''},")
allMessages=$$("#hidep").text() allMessages=$$("#hidep").text()
$$(".chat-content").append(`<div class="text-right mb-2"><span class="badge badge-primary" ><p style="white-space: pre-wrap; width:220px; word-wrap: break-word; word-break:break-all;">$${message}<p></span></div>`); $$(".chat-content").append(`<div class="text-right mb-2"><span class="badge badge-primary" ><p align="left" style="white-space: pre-wrap; width:220px; word-wrap: break-word; word-break:break-all;">$${message}<p></span></div>`);
$$("#sendButton").prop("disabled", true); $$("#sendButton").prop("disabled", true);
// Show loading spinner // Show loading spinner
$$(".chat-content").append('<div id="loadingSpinner" class="text-left mb-2"><span class="spinner-border spinner-border-sm"></span> Loading...</div>'); $$(".chat-content").append('<div id="loadingSpinner" class="text-left mb-2"><span class="spinner-border spinner-border-sm"></span> Loading...</div>');
$$.post("/chat", { messages: allMessages }, function(response){ $$.post("/chat", { messages: allMessages }, function(response){
if(response) { if(response) {
$$("#hidep").append("{'role': 'assistant', 'content':'"+response+"'},"); $$("#hidep").append("{'role': 'assistant', 'content':'''"+response+"'''},");
response=response.replace("\n","<br>") $$(".chat-content").append(`<div class="text-left mb-2"><span class="badge badge-secondary"><p align="left" style="white-space: pre-wrap; width:220px; word-wrap: break-word; word-break:break-all;">$${response}</p></span></div>`);
$$(".chat-content").append(`<div class="text-left mb-2"><span class="badge badge-secondary"><p style="white-space: pre-wrap; width:220px; word-wrap: break-word; word-break:break-all;">$${response}</p></span></div>`);
$$("#sendButton").prop("disabled", false); $$("#sendButton").prop("disabled", false);
$$('#loadingSpinner').remove(); $$('#loadingSpinner').remove();

@ -39,7 +39,7 @@ class chat:
def POST(self): def POST(self):
i=web.input().messages i=web.input().messages
i=list(eval(i)) i=list(eval(i))
print(i)
x=chatgpt(i) x=chatgpt(i)
print(x) print(x)
return x return x

Loading…
Cancel
Save