diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 95ee7d5..d419d9b 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -15,7 +15,7 @@ const InputOutputBackend: React.FC = () => { content: string } - // Define state variables for user preferences and messages + // Define state variables for user preferences and messages const [preferredCurrency, setPreferredCurrency] = useState("USD"); const [preferredLanguage, setPreferredLanguage] = useState("english"); const [timeFormat, setTimeFormat] = useState("24-hour"); @@ -24,8 +24,6 @@ const InputOutputBackend: React.FC = () => { const [dateFormat, setDateFormat] = useState("DD-MM-YYYY"); const [messages, setMessages] = useState([]); const [myBoolean, setMyBoolean] = useState(() => localStorage.getItem('myBoolean') === 'true') || false; - const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create") - apiURL.hostname = window.location.hostname; // Fetch local storage values and update state on component mount useEffect(() => { @@ -57,7 +55,7 @@ const InputOutputBackend: React.FC = () => { { role: "assistant", content: "Hello! How may I help you?" }, ]); }, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]); - + const conversationRef = useRef(null) const [copyClicked, setCopyClicked] = useState(false) @@ -74,7 +72,7 @@ const InputOutputBackend: React.FC = () => { useEffect(() => { getNewToken() - postWorkerRef.current = new Worker(new URL("./threads/PostWorker.ts", import.meta.url)) + postWorkerRef.current = new Worker(new URL("./threads/PostWorker.js", import.meta.url)) postWorkerRef.current.onmessage = (event) => { const status = event.data.status @@ -103,7 +101,7 @@ const InputOutputBackend: React.FC = () => { }, []) const getNewToken = () => { - axios.get(apiURL.href) + axios.get("http://localhost:5000/interstellar_ai/api/ai_create") .then(response => { setAccessToken(response.data.access_token) }) @@ -115,11 +113,9 @@ const InputOutputBackend: React.FC = () => { const startGetWorker = () => { if (!getWorkerRef.current) { - getWorkerRef.current = new Worker(new URL("./threads/GetWorker.ts", import.meta.url)) + getWorkerRef.current = new Worker(new URL("./threads/GetWorker.js", import.meta.url)) - const windowname = window.location.hostname - - getWorkerRef.current.postMessage({ action: "start", access_token: accessToken, windowname }) + getWorkerRef.current.postMessage({ action: "start", access_token: accessToken }) addMessage("assistant", "") getWorkerRef.current.onmessage = (event) => { @@ -182,8 +178,7 @@ const InputOutputBackend: React.FC = () => { } } setInputMessage("") - const windowname = window.location.hostname - postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key, windowname }) + postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key }) startGetWorker() } } @@ -233,7 +228,7 @@ const InputOutputBackend: React.FC = () => { } }; - const handleStopClick = () => { + const handleStopClick = () => { endGetWorker() getNewToken() } @@ -251,7 +246,7 @@ const InputOutputBackend: React.FC = () => { const handleEditClick = () => { let newestMessage = messages[messages.length - 2].content setInputMessage(newestMessage) - const updatedMessages = messages.slice(0, messages.length - 2) + const updatedMessages = messages.slice(0, messages.length-2) setMessages(updatedMessages) endGetWorker() getNewToken() diff --git a/app/backend/database.ts b/app/backend/database.ts index 559179a..90c69cf 100644 --- a/app/backend/database.ts +++ b/app/backend/database.ts @@ -18,12 +18,9 @@ if all went well, you will get the status 200 in response.data.status to check if the request was accepted or declined, check response.data.response, it will be either true or false depending on if it worked, or not. */ -const apiURL = new URL("http://localhost:5000/interstellar_ai/db") -apiURL.hostname = window.location.hostname; - export const sendToDatabase = async (data: any): Promise => { try { - const response = await axios.post(apiURL.href, data); + const response = await axios.post("http://localhost:5000/interstellar_ai/db", data); const status = response.data.status; const success = response.data.response; postMessage({ status, success }); @@ -36,7 +33,7 @@ export const sendToDatabase = async (data: any): Promise => { export const sendToDatabaseAndGetString = async (data: any): Promise => { try { - const response = await axios.post(apiURL.href, data); + const response = await axios.post("http://localhost:5000/interstellar_ai/db", data); const status = response.data.status; const success = response.data.response; postMessage({ status, success }); diff --git a/app/backend/threads/GetWorker.ts b/app/backend/threads/GetWorker.js similarity index 61% rename from app/backend/threads/GetWorker.ts rename to app/backend/threads/GetWorker.js index 2813a93..5eedbb2 100644 --- a/app/backend/threads/GetWorker.ts +++ b/app/backend/threads/GetWorker.js @@ -1,14 +1,10 @@ import axios from "axios"; -let windownameGlobal = "" - -let accesstoken = "" +let accesstoken onmessage = (event) => { - const { action, access_token, windowname } = event.data + const { action, access_token } = event.data accesstoken = access_token - windownameGlobal = windowname - if (action === "start") { fetchData() } else if (action === "terminate") { @@ -18,12 +14,9 @@ onmessage = (event) => { const fetchData = () => { - const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken) - apiURL.hostname = windownameGlobal; + const apiURL = "http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken - console.log(apiURL.href) - - axios.get(apiURL.href) + axios.get(apiURL) .then(response => { const data = response.data postMessage(data) diff --git a/app/backend/threads/PostWorker.ts b/app/backend/threads/PostWorker.js similarity index 69% rename from app/backend/threads/PostWorker.ts rename to app/backend/threads/PostWorker.js index ed0a526..f63ad77 100644 --- a/app/backend/threads/PostWorker.ts +++ b/app/backend/threads/PostWorker.js @@ -1,7 +1,7 @@ import axios from "axios"; 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 } = e.data const Message = { @@ -12,13 +12,7 @@ onmessage = (e) => { api_key: api_key } - const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send") - console.log(windowname) - apiURL.hostname = windowname; - - console.log(apiURL.href) - - axios.post(apiURL.href, Message) + axios.post("http://localhost:5000/interstellar_ai/api/ai_send", Message) .then(response => { const status = response.data.status postMessage({ status }) diff --git a/app/backend/voice_backend.ts b/app/backend/voice_backend.ts index 7716f0d..4bf0092 100644 --- a/app/backend/voice_backend.ts +++ b/app/backend/voice_backend.ts @@ -5,10 +5,7 @@ export const sendToVoiceRecognition = (audio_data: Blob): Promise => { const formdata = new FormData() formdata.append("audio", audio_data) - const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition") - apiURL.hostname = window.location.hostname; - - return axios.post(apiURL.href, formdata) + return axios.post("http://localhost:5000/interstellar_ai/api/voice_recognition", formdata) .then((response) => { return response.data.response }) diff --git a/app/components/Models.tsx b/app/components/Models.tsx index 7c22ab7..24ba852 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -154,15 +154,15 @@ const modelDropdown = { }; const selectedAIFunction = [ - 'Code', - 'Math', - 'Language', - 'Character', - 'Finance', - 'Weather', - 'Time', - 'Image', - 'Custom1', + 'Code', + 'Math', + 'Language', + 'Character', + 'Finance', + 'Weather', + 'Time', + 'Image', + 'Custom1', 'Custom2' ] @@ -172,29 +172,25 @@ const ModelSection: React.FC = () => { const [radioSelection, setRadioSelection] = useState("") const [activeSelectedAIFunction, setActiveSelectedAIFunction] = useState(''); const [currentSelectedAIFunction, setCurrentSelectedAIFunction] = useState(""); - + useEffect(() => { var temp = localStorage.getItem("activeSelectedAIFunction") || "" setActiveSelectedAIFunction(temp) if (!localStorage.getItem('selectedModelDropdown')) { - localStorage.setItem("selectedModelDropdown", "Offline Fast") + localStorage.setItem("selectedModelDropdown", "Offline Fast" ) } if (!localStorage.getItem("activeSelectedAIFunction")) { setActiveSelectedAIFunction('Code') - localStorage.setItem('activeSelectedAIFunction', 'Code') + localStorage.setItem('activeSelectedAIFunction' ,'Code') } if (!localStorage.getItem("model")) { - localStorage.setItem("model", 'starcoder2') + localStorage.setItem("model" ,'starcoder2') } if (!localStorage.getItem("radioSelection")) { - localStorage.setItem("radioSelection", 'None') - } - - if (!localStorage.getItem("type")) { - localStorage.setItem("type", 'local') + localStorage.setItem("radioSelection" ,'None') } const handleStorageChange = () => { @@ -281,7 +277,7 @@ const ModelSection: React.FC = () => { modelDropdown.offlineNonFoss.includes(model) || modelDropdown.offlineFoss.includes(model); const modelClicked = (model: string) => { - localStorage.setItem('activeSelectedAIFunction', model) + localStorage.setItem('activeSelectedAIFunction' , model) setActiveSelectedAIFunction(model) const selectedAIFunction = selectedModelDropdown as keyof typeof modelList; localStorage.setItem("model", modelList[selectedAIFunction][model as keyof typeof modelList[typeof selectedAIFunction]]) @@ -313,7 +309,7 @@ const ModelSection: React.FC = () => { (displayedCategory) => (