diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 8d9d811..e56bbe9 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -5,7 +5,6 @@ import InputFrontend from "../components/InputFrontend"; import { sendToVoiceRecognition } from "./voice_backend" import axios from "axios"; import { useChatHistory } from '../hooks/useChatHistory'; -import { getWeather } from "./weather"; const InputOutputBackend: React.FC = () => { // # variables @@ -25,7 +24,6 @@ const InputOutputBackend: React.FC = () => { const [messages, setMessages] = useState(chatHistory.chats[chatHistory.selectedIndex].messages || []); const [myBoolean, setMyBoolean] = useState(false); const [systemMessage, setSystemMessage] = useState("You are a helpful assistant") - const [weatherData, setWeatherData] = useState("false") const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create") if (typeof window !== 'undefined') { apiURL.hostname = window.location.hostname; @@ -36,7 +34,7 @@ const InputOutputBackend: React.FC = () => { console.log(setSelectedIndex) - useEffect(() => { +useEffect(() => { console.log("History", chatHistory); console.log("Messages", messages); @@ -45,14 +43,14 @@ const InputOutputBackend: React.FC = () => { // If the selected chat has messages, set them if (currentMessages.length > 0) { - setMessages(currentMessages); + setMessages(currentMessages); } else if (currentMessages.length === 0) { // When creating a new chat and no messages exist yet, set default messages addMessage("system", systemMessage) addMessage("assistant", "Hello! How can I help you?") console.log(systemMessage) } - }, [chatHistory, chatHistory.selectedIndex, systemMessage]); +}, [chatHistory, chatHistory.selectedIndex, systemMessage]); // Update messages when any of the settings change useEffect(() => { @@ -64,25 +62,14 @@ const InputOutputBackend: React.FC = () => { setTimeZone(localStorage.getItem("timeZone") || "GMT"); setDateFormat(localStorage.getItem("dateFormat") || "DD-MM-YYYY"); setMyBoolean(localStorage.getItem('myBoolean') === 'true'); - getWeatherHere() } - }, []) - - const getWeatherHere = async () => { - setWeatherData(await getWeather({ "unit_type": preferredMeasurement, "city": localStorage.getItem("weatherInfo") || "New York" })) - console.log(weatherData) - } + },[]) useEffect(() => { const measurementString = (preferredMeasurement == "Metric") ? "All measurements follow the metric system. Refuse to use any other measurement system." : "All measurements follow the imperial system. Refuse to use any other measurement system."; - if (!weatherData && localStorage.getItem("activeSelectedAIFunction") == "Weather") { - setWeatherData("") - console.log("Weather is overrated.") - } - const newSystemMessage = myBoolean ? `You are operating in the timezone: ${timeZone}. Use the ${timeFormat} time format and ${dateFormat} for dates. ${measurementString} @@ -90,8 +77,7 @@ const InputOutputBackend: React.FC = () => { Communicate in the language specified by the user (country code: ${preferredLanguage}), and only in this language. You are only able to change language if the user specifically states you must. Do not answer in multiple languages or multiple measurement systems under any circumstances other than the user requesting it.` - : `You are a helpful assistant. - ${weatherData}`; + : `You are a helpful assistant`; setSystemMessage(newSystemMessage) }, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]); @@ -100,7 +86,7 @@ const InputOutputBackend: React.FC = () => { const messageIndex = 0 // system prompt is the first so index 0 updateMessage(messageIndex, systemMessage) console.log(messages) - }, [systemMessage]) + },[systemMessage]) const conversationRef = useRef(null) @@ -199,8 +185,8 @@ const InputOutputBackend: React.FC = () => { if (newContent == "") { newContent = "Generating answer..." } - const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length - 1 - updateMessage(messageIndex, newContent) + const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length-1 + updateMessage(messageIndex,newContent) }; const addMessage = (role: string, content: string) => { @@ -208,7 +194,7 @@ const InputOutputBackend: React.FC = () => { setMessages((prevMessages) => [...prevMessages, newMessage]) const updatedChats = [...chatHistory.chats] updatedChats[chatHistory.selectedIndex].messages.push(newMessage) - setChatHistory({ ...chatHistory, chats: updatedChats }) + setChatHistory({...chatHistory, chats:updatedChats}) } const handleSendClick = (inputValue: string, override: boolean) => { if (inputValue != "") { @@ -216,7 +202,7 @@ const InputOutputBackend: React.FC = () => { setInputDisabled(true) if (postWorkerRef.current) { addMessage("user", inputValue) - let type: string = "local" + let type:string = "local" let api_key: string = "" if (typeof localStorage !== 'undefined') { type = localStorage.getItem('type') || "local" diff --git a/app/backend/weather.ts b/app/backend/weather.ts deleted file mode 100644 index cda396b..0000000 --- a/app/backend/weather.ts +++ /dev/null @@ -1,22 +0,0 @@ -import axios from "axios"; - -const apiURL = new URL("http://localhost:5000/interstellar_ai/api/weather") -if (typeof window !== 'undefined') { - apiURL.hostname = window.location.hostname; -} else { - apiURL.hostname = "localhost" -} - -export const getWeather = async (data: object): Promise => { - try { - const response = await axios.post(apiURL.href, data); - const status = response.data.status; - const success = response.data.response; - postMessage({ status, success }); - return success; - } catch (error) { - postMessage({ status: 500, success: false }); - console.log(error) - return ""; - } -}; \ No newline at end of file