main (#137)
Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/interstellar_ai/pulls/137 Reviewed-by: Patrick <patrick_pluto@noreply.localhost> Co-authored-by: sageTheDM <info@photofuel.tech> Co-committed-by: sageTheDM <info@photofuel.tech>
This commit is contained in:
parent
f9bce3b22a
commit
91353bd051
34 changed files with 682 additions and 567 deletions
|
@ -1,37 +1,32 @@
|
|||
import axios from "axios";
|
||||
|
||||
let windownameGlobal = ""
|
||||
let windownameGlobal = ""; // Global variable to hold the window name
|
||||
let accesstoken = ""; // Variable to store the access token
|
||||
|
||||
let accesstoken = ""
|
||||
onmessage = (event) => {
|
||||
const { action, access_token, windowname } = event.data
|
||||
accesstoken = access_token
|
||||
|
||||
windownameGlobal = windowname
|
||||
const { action, access_token, windowname } = event.data;
|
||||
accesstoken = access_token;
|
||||
windownameGlobal = windowname;
|
||||
|
||||
if (action === "start") {
|
||||
fetchData()
|
||||
} else if (action === "terminate") {
|
||||
fetchData(); // Start fetching data on 'start' action
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const fetchData = () => {
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken);
|
||||
apiURL.hostname = windownameGlobal; // Set the hostname
|
||||
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken)
|
||||
apiURL.hostname = windownameGlobal;
|
||||
|
||||
console.log(apiURL.href)
|
||||
console.log(apiURL.href); // Log the constructed URL
|
||||
|
||||
axios.get(apiURL.href)
|
||||
.then(response => {
|
||||
const data = response.data
|
||||
postMessage(data)
|
||||
setTimeout(fetchData, 100)
|
||||
postMessage(response.data); // Send data back on success
|
||||
setTimeout(fetchData, 100); // Schedule next fetch
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('Error fetching data:', error);
|
||||
postMessage({ error: "failed fetching data" })
|
||||
setTimeout(() => fetchData(), 1000)
|
||||
})
|
||||
}
|
||||
postMessage({ error: "failed fetching data" }); // Send error message
|
||||
setTimeout(() => fetchData(), 1000); // Retry after 1 second
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
})
|
||||
}
|
||||
console.log("Error calling API:", error);
|
||||
postMessage({ status: 500 }); // Send error status if API call fails
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue