From dce4e6a64b831e318fbea237970d1e6504a7a130 Mon Sep 17 00:00:00 2001 From: HanishKVC Date: Wed, 29 May 2024 20:15:40 +0530 Subject: [PATCH] SimpleChat: Move request headers into Me and gMe Inturn allow Authorization to be sent, if not empty. --- .../server/public_simplechat/simplechat.js | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/examples/server/public_simplechat/simplechat.js b/examples/server/public_simplechat/simplechat.js index f5e57f879..794d1f296 100644 --- a/examples/server/public_simplechat/simplechat.js +++ b/examples/server/public_simplechat/simplechat.js @@ -164,6 +164,18 @@ class SimpleChat { return last; } + fetch_headers(apiEP) { + let headers = new Headers(); + for(let k in gMe.headers) { + let v = gMe.headers[k]; + if ((k == "Authorization") && (v.trim() == "")) { + continue; + } + headers[k] = v; + } + return headers; + } + /** * Add needed fields wrt json object to be sent wrt LLM web services completions endpoint. * The needed fields/options are picked from a global object. @@ -559,11 +571,10 @@ class MultiChatUI { this.elInUser.value = "working..."; this.elInUser.disabled = true; console.debug(`DBUG:SimpleChat:MCUI:${chatId}:HandleUserSubmit:${theUrl}:ReqBody:${theBody}`); + let theHeaders = chat.fetch_headers(apiEP); let resp = await fetch(theUrl, { method: "POST", - headers: { - "Content-Type": "application/json", - }, + headers: theHeaders, body: theBody, }); @@ -676,6 +687,10 @@ class Me { "Last4": 5, }; this.apiEP = ApiEP.Type.Chat; + this.headers = { + "Content-Type": "application/json", + "Authorization": "", // Authorization: Bearer OPENAI_API_KEY + } // Add needed fields wrt json object to be sent wrt LLM web services completions endpoint. this.chatRequestOptions = { "temperature": 0.7,