SimpleChat:JS: Messages/Prompt, indicate working to end user
This commit is contained in:
parent
c6653479fc
commit
564469e4f6
1 changed files with 14 additions and 6 deletions
|
@ -85,15 +85,21 @@ class SimpleChat {
|
||||||
* @param {HTMLInputElement} inputUser
|
* @param {HTMLInputElement} inputUser
|
||||||
* @param {HTMLDivElement} divChat
|
* @param {HTMLDivElement} divChat
|
||||||
* @param {RequestInfo | URL} urlApi
|
* @param {RequestInfo | URL} urlApi
|
||||||
|
* @param {boolean} [bMessages]
|
||||||
*/
|
*/
|
||||||
async function handle_submit(inputUser, divChat, urlApi) {
|
async function handle_submit(inputUser, divChat, urlApi, bMessages=true) {
|
||||||
let content = inputUser?.value;
|
let content = inputUser?.value;
|
||||||
console.debug("DBUG:BtnSubmit:Click:", content)
|
|
||||||
gChat.add(Roles.User, content);
|
gChat.add(Roles.User, content);
|
||||||
gChat.show(divChat);
|
gChat.show(divChat);
|
||||||
console.log("DBUG:BtnSubmit:Messages:", gChat.request_messages_jsonstr());
|
let theBody;
|
||||||
console.log("DBUG:BtnSubmit:Messages:", gChat.request_prompt_jsonstr());
|
if (bMessages) {
|
||||||
inputUser.value = "";
|
theBody = gChat.request_messages_jsonstr();
|
||||||
|
} else {
|
||||||
|
theBody = gChat.request_prompt_jsonstr();
|
||||||
|
}
|
||||||
|
inputUser.value = "working...";
|
||||||
|
inputUser.disabled = true;
|
||||||
|
console.debug("DBUG:HandleSubmit:ReqBody:", theBody);
|
||||||
let resp = await fetch(urlApi, {
|
let resp = await fetch(urlApi, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -101,8 +107,10 @@ async function handle_submit(inputUser, divChat, urlApi) {
|
||||||
},
|
},
|
||||||
body: gChat.request_messages_jsonstr(),
|
body: gChat.request_messages_jsonstr(),
|
||||||
});
|
});
|
||||||
|
inputUser.value = "";
|
||||||
|
inputUser.disabled = false;
|
||||||
let respBody = await resp.json();
|
let respBody = await resp.json();
|
||||||
console.log("DBUG:HandleSubmit:Resp:", respBody);
|
console.log("DBUG:HandleSubmit:RespBody:", respBody);
|
||||||
let assistantMsg = respBody["choices"][0]["message"]["content"];
|
let assistantMsg = respBody["choices"][0]["message"]["content"];
|
||||||
gChat.add(Roles.Assistant, assistantMsg);
|
gChat.add(Roles.Assistant, assistantMsg);
|
||||||
gChat.show(divChat);
|
gChat.show(divChat);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue