diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 83c998a..47a6e1f 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -16,17 +16,33 @@ const InputOutputBackend: React.FC = () => { content: string } + /* Variables for System-prompt */ + const [preferredCurrency, setPreferredCurrency] = useState(localStorage.getItem("preferredCurrency") || "") + const [preferredLanguage, setPreferredLanguage] = useState(localStorage.getItem("preferredLanguage") || "") + const [timeFormat, setTimeFormat] = useState(localStorage.getItem("timeFormat") || "") + const [preferredMeasurement, setPreferredMeasurement] = useState(localStorage.getItem("preferredMeasurement") || "") + const [timeZone, setTimeZone] = useState(localStorage.getItem("timeZone") || "") + const [dateFormat, setDateFormat] = useState(localStorage.getItem("dateFormat") || "") + const [copyClicked, setCopyClicked] = useState(false) const [accessToken, setAccessToken] = useState("") const postWorkerRef = useRef(null) const getWorkerRef = useRef(null) - const [messages, setMessages] = useState([{ role: "assistant", content: "Hello! How can I help you?" }]) + 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) const [isRecording, setIsRecording] = useState(false) const [audioURL, setAudioURL] = useState(null) - const mediaRecorderRef = useRef(null) + const mediaRecorderRef = useRef(null) const audioChunks = useRef([]) @@ -127,13 +143,6 @@ const InputOutputBackend: React.FC = () => { }); }; - /* Variables for System-prompt */ - const [preferredCurrency, setPreferredCurrency] = useState(localStorage.getItem("preferredCurrency") || "") - const [preferredLanguage, setPreferredLanguage] = useState(localStorage.getItem("preferredLanguage") || "") - const [timeFormat, setTimeFormat] = useState(localStorage.getItem("timeFormat") || "") - const [preferredMeasurement, setPreferredMeasurement] = useState(localStorage.getItem("preferredMeasurement") || "") - const [timeZone, setTimeZone] = useState(localStorage.getItem("timeZone") || "") - const [dateFormat, setDateFormat] = useState(localStorage.getItem("dateFormat") || "") useEffect(() => { @@ -149,7 +158,7 @@ const InputOutputBackend: React.FC = () => { if (postWorkerRef.current) { addMessage("user", inputValue) console.log("input:", inputValue); - postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "phi3.5", access_token: accessToken }) + postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", access_token: accessToken }) startGetWorker() } } @@ -190,20 +199,6 @@ const InputOutputBackend: React.FC = () => { await ffmpegRef.current.load() } } - - const convertOggToWav = async (oggFile: File | Blob) => { - await loadFFmpeg() - - const ffmpeg = ffmpegRef.current! - - await ffmpeg.writeFile("input.ogg", await fetchFile(oggFile)) - await ffmpeg.exec(["-i", "input.ogg", "output.wav"]) - const wavData = await ffmpeg.readFile("output.wav") - console.log(wavData); - const wavBlob = new Blob([wavData], { type: "audio/wav" }) - audioRef.current = URL.createObjectURL(wavBlob) - return wavBlob - } const stopRecording = () => { mediaRecorderRef.current?.stop() diff --git a/app/backend/threads/PostWorker.js b/app/backend/threads/PostWorker.js index 1127d0d..9fb01e2 100644 --- a/app/backend/threads/PostWorker.js +++ b/app/backend/threads/PostWorker.js @@ -1,12 +1,12 @@ import axios from "axios"; onmessage = (e) => { - const { messages = [{ role: "assistant", content: "Hello! How can I help you?" }], ai_model = "phi3.5", access_token } = e.data - messages.unshift({ role: "system", content: "You are a Helpful assistant. you give short answers" }) + const { messages, ai_model = "llama3.2", access_token } = e.data + const Message = { messages: messages, - ai_model: "phi3.5", + ai_model: "llama3.2", model_type: "local", access_token: access_token } diff --git a/app/components/ConversationFrontend.tsx b/app/components/ConversationFrontend.tsx index dc3114c..3294d09 100644 --- a/app/components/ConversationFrontend.tsx +++ b/app/components/ConversationFrontend.tsx @@ -37,15 +37,19 @@ const ConversationFrontend = React.forwardRef if (message.role == "user") { isUserMessage = message } - return ( -
-

{message.content}

-
- ); + if (index >= 1){ + + return ( +
+

{message.content}

+
+ ); + } })} + {/* Dummy div to mark the end of the conversation for auto-scrolling */}
diff --git a/package-lock.json b/package-lock.json index 85782b8..b935b5d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "interstellar_ai", - "version": "0.1.0", + "version": "0.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "interstellar_ai", - "version": "0.1.0", + "version": "0.2.0", "dependencies": { "@ffmpeg/core-mt": "^0.12.6", "@ffmpeg/ffmpeg": "^0.12.10", @@ -16,11 +16,16 @@ "axios": "^1.7.7", "electron": "^32.1.2", "fs": "^0.0.1-security", + "is-even": "^1.0.0", + "is-odd": "^3.0.1", + "math": "^0.0.3", "next": "14.2.12", "ollama": "^0.5.9", "react": "^18", "react-dom": "^18", - "react-router-dom": "^6.26.2" + "react-router-dom": "^6.26.2", + "swiss": "^2.4.0", + "weather": "^1.0.4" }, "devDependencies": { "@types/node": "^20", @@ -1403,6 +1408,15 @@ ], "license": "CC-BY-4.0" }, + "node_modules/centra": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/centra/-/centra-2.7.0.tgz", + "integrity": "sha512-PbFMgMSrmgx6uxCdm57RUos9Tc3fclMvhLSATYN39XsDV29B89zZ3KA89jmY0vwSGazyU+uerqwa6t+KaodPcg==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -3310,6 +3324,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "license": "MIT" + }, "node_modules/is-bun-module": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-bun-module/-/is-bun-module-1.2.1.tgz", @@ -3381,6 +3401,42 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-even": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-even/-/is-even-1.0.0.tgz", + "integrity": "sha512-LEhnkAdJqic4Dbqn58A0y52IXoHWlsueqQkKfMfdEnIYG8A1sm/GHidKkS6yvXlMoRrkM34csHnXQtOqcb+Jzg==", + "license": "MIT", + "dependencies": { + "is-odd": "^0.1.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-even/node_modules/is-number": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-3.0.0.tgz", + "integrity": "sha512-4cboCqIpliH+mAvFNegjZQ4kgKc3ZUhQVr3HvWbSh5q3WH2v82ct+T2Y1hdU5Gdtorx/cLifQjqCbL7bpznLTg==", + "license": "MIT", + "dependencies": { + "kind-of": "^3.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-even/node_modules/is-odd": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/is-odd/-/is-odd-0.1.2.tgz", + "integrity": "sha512-Ri7C2K7o5IrUU9UEI8losXJCCD/UtsaIrkR5sxIcFg4xQ9cRJXlWA5DQvTE0yDc0krvSNLsRGXN11UPS6KyfBw==", + "license": "MIT", + "dependencies": { + "is-number": "^3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -3495,6 +3551,27 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-odd": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/is-odd/-/is-odd-3.0.1.tgz", + "integrity": "sha512-CQpnWPrDwmP1+SMHXZhtLtJv90yiyVfluGsX5iNCVkrhQtU3TQHsUWPG9wkdk9Lgd5yNpAg9jQEo90CBaXgWMA==", + "license": "MIT", + "dependencies": { + "is-number": "^6.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/is-odd/node_modules/is-number": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-6.0.0.tgz", + "integrity": "sha512-Wu1VHeILBK8KAWJUAiSZQX94GmOE45Rg6/538fKwiloUu21KncEkYGPqob2oSZ5mUT73vLGrHQjKw3KMPwfDzg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/is-path-inside": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", @@ -3792,6 +3869,18 @@ "json-buffer": "3.0.1" } }, + "node_modules/kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha512-NOW9QQXMoZGg/oqnVNoNTTIFEIid1627WCffUBJEdMxYApq7mNE7CpzucIPc+ZQg25Phej7IJSmX3hO+oblOtQ==", + "license": "MIT", + "dependencies": { + "is-buffer": "^1.1.5" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/language-subtag-registry": { "version": "0.3.23", "resolved": "https://registry.npmjs.org/language-subtag-registry/-/language-subtag-registry-0.3.23.tgz", @@ -3907,6 +3996,14 @@ "node": ">=10" } }, + "node_modules/math": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/math/-/math-0.0.3.tgz", + "integrity": "sha512-xyNJxsEwpYBabFmCgwg7TFRljf5oGgV2h1TqP0H9RnykScaSKgoVlBaEz+Gov8NOdxFagoTzRg1aEBfayi8qQQ==", + "engines": { + "node": "> 0.0.0" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -4405,6 +4502,18 @@ "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", "license": "MIT" }, + "node_modules/phin": { + "version": "3.7.1", + "resolved": "https://registry.npmjs.org/phin/-/phin-3.7.1.tgz", + "integrity": "sha512-GEazpTWwTZaEQ9RhL7Nyz0WwqilbqgLahDM3D0hxWwmVDI52nXEybHqiN6/elwpkJBhcuj+WbBu+QfT0uhPGfQ==", + "license": "MIT", + "dependencies": { + "centra": "^2.7.0" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/picocolors": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.0.tgz", @@ -5508,6 +5617,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swiss": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/swiss/-/swiss-2.4.0.tgz", + "integrity": "sha512-XGm/tENVKsBr7JvqjIPJX1hYkklkGm5I8IkcvuSW1tWzWOpcxYnFzJdPeaFBS/e9UpV5pMw/NQ7sTBwfieeFQw==", + "license": "MIT" + }, "node_modules/tailwindcss": { "version": "3.4.12", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.12.tgz", @@ -5803,6 +5918,15 @@ "dev": true, "license": "MIT" }, + "node_modules/weather": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/weather/-/weather-1.0.4.tgz", + "integrity": "sha512-6K4jGKz0Hr5Lsc0UgencI2218kSJsiPahW0VJ/PzblEA0uTNv4AgNyebQUW8vqy2y+Pm3VHMTCkTCrnSe8PeKQ==", + "license": "GPL-3.0-or-later", + "dependencies": { + "phin": "^3.4.0" + } + }, "node_modules/whatwg-fetch": { "version": "3.6.20", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz", diff --git a/package.json b/package.json index b5901e2..6e8091a 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,16 @@ "axios": "^1.7.7", "electron": "^32.1.2", "fs": "^0.0.1-security", + "is-even": "^1.0.0", + "is-odd": "^3.0.1", + "math": "^0.0.3", "next": "14.2.12", "ollama": "^0.5.9", "react": "^18", "react-dom": "^18", - "react-router-dom": "^6.26.2" + "react-router-dom": "^6.26.2", + "swiss": "^2.4.0", + "weather": "^1.0.4" }, "devDependencies": { "@types/node": "^20", diff --git a/py/api.py b/py/api.py index f3e13ea..18af5e4 100644 --- a/py/api.py +++ b/py/api.py @@ -7,7 +7,7 @@ from db import DB from weather import Weather from voice import VoiceRecognition from tts import TTS - + class API: def __init__(self): diff --git a/py/requirements.txt b/py/requirements.txt index 212a41d..3a91239 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -13,6 +13,6 @@ python-weather pycouchdb pyttsx3 pip-licenses -openai-whisper +faster-whisper pydub ffmpeg \ No newline at end of file