From 75f735e50a3551baebc36e21f87414be99ab5078 Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Fri, 27 Sep 2024 16:51:44 +0200 Subject: [PATCH] The settings are now changing the system prompt --- app/backend/InputOutputHandler.tsx | 25 ++++++++++++++++--------- app/backend/threads/PostWorker.js | 6 +++--- app/components/ConversationFrontend.tsx | 20 ++++++++++++-------- py/api.py | 2 +- py/requirements.txt | 2 +- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 83c998a..0a1d891 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -16,11 +16,25 @@ 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 anwser in ${preferredLanguage}.` + },{ role: "assistant", content: "Hello! How can I help you?" }]) const [liveMessage, setLiveMessage] = useState("") const [inputMessage, setInputMessage] = useState("") const [inputDisabled, setInputDisabled] = useState(false) @@ -127,13 +141,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 +156,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() } } 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/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