SimpleChatTC:Move chat server handshake to SimpleChat
This commit is contained in:
parent
482517543b
commit
91f39b7197
|
|
@ -735,6 +735,31 @@ class SimpleChat {
|
||||||
return theResp;
|
return theResp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the chat handshake with the ai server
|
||||||
|
* @param {string} baseURL
|
||||||
|
* @param {string} apiEP
|
||||||
|
* @param {HTMLDivElement} elDivChat - used to show chat response as it is being generated/recieved in streaming mode
|
||||||
|
*/
|
||||||
|
async handle_chat_hs(baseURL, apiEP, elDivChat) {
|
||||||
|
let theUrl = ApiEP.Url(baseURL, apiEP);
|
||||||
|
let theBody = this.request_jsonstr(apiEP);
|
||||||
|
console.debug(`DBUG:SimpleChat:${this.chatId}:HandleChatHS:${theUrl}:ReqBody:${theBody}`);
|
||||||
|
|
||||||
|
let theHeaders = this.fetch_headers(apiEP);
|
||||||
|
let resp = await fetch(theUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers: theHeaders,
|
||||||
|
body: theBody,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (resp.status >= 300) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.handle_response(resp, apiEP, elDivChat);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call the requested tool/function.
|
* Call the requested tool/function.
|
||||||
* Returns undefined, if the call was placed successfully
|
* Returns undefined, if the call was placed successfully
|
||||||
|
|
@ -1109,30 +1134,6 @@ class MultiChatUI {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {SimpleChat} chat
|
|
||||||
* @param {string} apiEP
|
|
||||||
*/
|
|
||||||
async handle_chat_hs(chat, apiEP) {
|
|
||||||
let theUrl = ApiEP.Url(gMe.baseURL, apiEP);
|
|
||||||
let theBody = chat.request_jsonstr(apiEP);
|
|
||||||
console.debug(`DBUG:SimpleChat:MCUI:${chat.chatId}:HandleUserSubmit:${theUrl}:ReqBody:${theBody}`);
|
|
||||||
|
|
||||||
let theHeaders = chat.fetch_headers(apiEP);
|
|
||||||
let resp = await fetch(theUrl, {
|
|
||||||
method: "POST",
|
|
||||||
headers: theHeaders,
|
|
||||||
body: theBody,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (resp.status >= 300) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return chat.handle_response(resp, apiEP, this.elDivChat);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle user query submit request, wrt specified chat session.
|
* Handle user query submit request, wrt specified chat session.
|
||||||
*
|
*
|
||||||
|
|
@ -1180,7 +1181,7 @@ class MultiChatUI {
|
||||||
this.elInUser.disabled = true;
|
this.elInUser.disabled = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let theResp = await this.handle_chat_hs(chat, apiEP)
|
let theResp = await chat.handle_chat_hs(gMe.baseURL, apiEP, this.elDivChat)
|
||||||
if (chatId == this.curChatId) {
|
if (chatId == this.curChatId) {
|
||||||
this.chat_show(chatId);
|
this.chat_show(chatId);
|
||||||
if (theResp.trimmedContent.length > 0) {
|
if (theResp.trimmedContent.length > 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue