From 505255d72b116a0d43fa6191922232be98cd733e Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Fri, 11 Oct 2024 09:14:03 +0200 Subject: [PATCH] Post worker comments --- app/backend/threads/PostWorker.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/backend/threads/PostWorker.ts b/app/backend/threads/PostWorker.ts index ed0a526..6e05d7d 100644 --- a/app/backend/threads/PostWorker.ts +++ b/app/backend/threads/PostWorker.ts @@ -1,31 +1,32 @@ import axios from "axios"; +// Event listener for incoming messages onmessage = (e) => { - const { messages, ai_model, model_type, access_token, api_key, windowname } = e.data - + const { messages, ai_model, model_type, access_token, api_key, windowname } = e.data; + // Construct the message object to send to the API const Message = { messages: messages, ai_model: ai_model, model_type: model_type, access_token: access_token, api_key: api_key - } + }; - const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send") - console.log(windowname) - apiURL.hostname = windowname; + const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send"); + console.log(windowname); // Log the window name + apiURL.hostname = windowname; // Set the hostname for the API request - console.log(apiURL.href) + console.log(apiURL.href); // Log the constructed API URL + // Make a POST request to the API with the message object axios.post(apiURL.href, Message) .then(response => { - const status = response.data.status - postMessage({ status }) - + const status = response.data.status; + postMessage({ status }); // Send the response status back }) .catch(error => { - console.log("Error calling API:", error) - postMessage({ status: 500 }) - }) -} \ No newline at end of file + console.log("Error calling API:", error); + postMessage({ status: 500 }); // Send error status if API call fails + }); +}