diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 8529202..92fa6df 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -17,37 +17,48 @@ const InputOutputBackend: React.FC = () => { content: string } - /* Variables for System-prompt */ - const [preferredCurrency, setPreferredCurrency] = useState("") - const [preferredLanguage, setPreferredLanguage] = useState("") - const [timeFormat, setTimeFormat] = useState("") - const [preferredMeasurement, setPreferredMeasurement] = useState("") - const [timeZone, setTimeZone] = useState("") - const [dateFormat, setDateFormat] = useState("") + const [preferredCurrency, setPreferredCurrency] = useState(null); + const [preferredLanguage, setPreferredLanguage] = useState(null); + const [timeFormat, setTimeFormat] = useState(null); + const [preferredMeasurement, setPreferredMeasurement] = useState(null); + const [timeZone, setTimeZone] = useState(null); + const [dateFormat, setDateFormat] = useState(null); + const [messages, setMessages] = useState([]); useEffect(() => { - setPreferredCurrency(localStorage.getItem("preferredCurrency")) - setPreferredLanguage(localStorage.getItem("preferredLanguage")) - setTimeFormat(localStorage.getItem("timeFormat")) - setPreferredMeasurement(localStorage.getItem("preferredMeasurement")) - setTimeZone(localStorage.getItem("timeZone")) - setDateFormat(localStorage.getItem("dateFormat")) - }, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat]) + setPreferredCurrency(localStorage.getItem("preferredCurrency")); + setPreferredLanguage(localStorage.getItem("preferredLanguage")); + setTimeFormat(localStorage.getItem("timeFormat")); + setPreferredMeasurement(localStorage.getItem("preferredMeasurement")); + setTimeZone(localStorage.getItem("timeZone")); + setDateFormat(localStorage.getItem("dateFormat")); + }, []); + + useEffect(() => { + if (preferredCurrency && preferredLanguage && timeFormat && dateFormat && preferredMeasurement && timeZone) { + setMessages([ + { + role: "system", + content: `You are in the timezone: ${timeZone}. + You use the time format ${timeFormat}. + You use the date format ${dateFormat} for all references of dates. + You use the ${preferredMeasurement} system. + You use the currency ${preferredCurrency}. + You will only answer in the language (you will receive the country code) ${preferredLanguage}. + But in the case the user specifically states to answer in another language, do that. Speaking in + another language is not stating you should answer in that language. + Additionally, under no circumstances translate your answer into multiple languages.`, + }, + { role: "assistant", content: "Hello! How can I help you?" }, + ]); + } + }, [preferredCurrency, preferredLanguage, timeFormat, dateFormat, preferredMeasurement, timeZone]); + const [copyClicked, setCopyClicked] = useState(false) const [accessToken, setAccessToken] = useState("") const postWorkerRef = useRef(null) const getWorkerRef = useRef(null) - const [messages, setMessages] = useState([{ - role: "system", - content: `You are in the timezone: ${timeZone}. - You use the time format ${timeFormat}. - You use the date format ${dateFormat} for all references of dates. - You use the ${preferredMeasurement} system. You use the currency ${preferredCurrency}. - You will only answer in the language (you will receive the country code) ${preferredLanguage}. - But in the case the user specifically states to answer in an other language do that speaking in a - nother language is not stating you should answer in that language. Additionally do not translate your answer into multiple languages` - }, { role: "assistant", content: "Hello! How can I help you?" }]) const [liveMessage, setLiveMessage] = useState("") const [inputMessage, setInputMessage] = useState("") const [inputDisabled, setInputDisabled] = useState(false)