From db4a24b5cde5d557063f1b237e5ef0295c758ffe Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Wed, 9 Oct 2024 14:01:48 +0200 Subject: [PATCH 1/5] npm build fixes half --- app/backend/InputOutputHandler.tsx | 22 +++------------------- app/components/AI.tsx | 8 ++------ app/components/History.tsx | 2 ++ app/page.tsx | 5 ++--- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 68e552a..d40f9fb 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -4,7 +4,6 @@ import ConversationFrontend from '../components/ConversationFrontend'; import InputFrontend from "../components/InputFrontend"; import { sendToVoiceRecognition } from "./voice_backend" import axios from "axios"; -import { changeHistory, checkCredentials, getHistory } from './database'; import { useChatHistory } from '../hooks/useChatHistory'; const InputOutputBackend: React.FC = () => { @@ -80,13 +79,9 @@ const InputOutputBackend: React.FC = () => { }, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]); useEffect(() => { - const updateSystemprompt = (prompt: string) => { - setMessages(prevMessages => { - const newMessage = { role: "system", content: prompt } - return [newMessage, ...prevMessages] - }) - } - updateSystemprompt + const messageIndex = 0 // system prompt is the first so index 0 + updateMessage(messageIndex, systemMessage) + console.log(messages) },[systemMessage]) @@ -188,17 +183,6 @@ const InputOutputBackend: React.FC = () => { } const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length-1 updateMessage(messageIndex,newContent) - // setMessages((prevMessages) => { - // const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages - // if (updatedMessages.length > 0) { - // const lastMessage = updatedMessages[updatedMessages.length - 1]; - // updatedMessages[updatedMessages.length - 1] = { - // ...lastMessage, // Keep the existing role and other properties - // content: newContent, // Update only the content - // }; - // } - // return updatedMessages; // Return the updated array - // }); }; const addMessage = (role: string, content: string) => { diff --git a/app/components/AI.tsx b/app/components/AI.tsx index a4db7fa..824f6d6 100644 --- a/app/components/AI.tsx +++ b/app/components/AI.tsx @@ -2,14 +2,10 @@ import React from 'react'; import InputOutputBackend from '../backend/InputOutputHandler'; -interface AIProps{ - selectedIndex:number -} - -const AI: React.FC = ({selectedIndex}) => { +const AI: React.FC = () => { return (
- +
); }; diff --git a/app/components/History.tsx b/app/components/History.tsx index d109f24..e719aeb 100644 --- a/app/components/History.tsx +++ b/app/components/History.tsx @@ -6,6 +6,8 @@ const History: React.FC = () => { const [isEditing, setIsEditing] = useState(false); const [inputValue, setInputValue] = useState(''); + setChatHistory(chatHistory) + const handleEditButtonClick = () => { setIsEditing(true); }; diff --git a/app/page.tsx b/app/page.tsx index 832fbb7..3c77911 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -14,7 +14,6 @@ const LandingPage: React.FC = () => { const [showDivs, setShowDivs] = useState(true); const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI'); const conversationRef = useRef(null); - const [selectedHistoryIndex, setSelectedHistoryIndex] = useState(0) const [primaryColor, setPrimaryColor] = useState("#fefefe"); const [secondaryColor, setSecondaryColor] = useState("#fefefe"); @@ -92,13 +91,13 @@ const LandingPage: React.FC = () => {
{showDivs && (
- +
)}
- {view === 'AI' && } + {view === 'AI' && } {view === 'FAQ' && } {view === 'Documentation' && } {view === 'Credits' && } From b9137c2a10e819e0954f6b8ec158633cb3d718e3 Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Wed, 9 Oct 2024 14:22:31 +0200 Subject: [PATCH 2/5] build fix for sure for sure --- app/backend/InputOutputHandler.tsx | 2 +- app/components/History.tsx | 7 +------ app/hooks/useChatHistory.tsx | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index d40f9fb..1a4817b 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -14,7 +14,7 @@ const InputOutputBackend: React.FC = () => { } // Define state variables for user preferences and messages - const [chatHistory, setChatHistory, setSelectedIndex, updateMessage] = useChatHistory() + const [chatHistory, setSelectedIndex, setChatHistory, updateMessage] = useChatHistory() const [preferredCurrency, setPreferredCurrency] = useState("USD"); const [preferredLanguage, setPreferredLanguage] = useState("english"); const [timeFormat, setTimeFormat] = useState("24-hour"); diff --git a/app/components/History.tsx b/app/components/History.tsx index b3cf197..0aae50f 100644 --- a/app/components/History.tsx +++ b/app/components/History.tsx @@ -2,18 +2,13 @@ import React, { useState } from 'react'; import { useChatHistory } from '../hooks/useChatHistory'; const History: React.FC = () => { - const [chatHistory, setChatHistory, setSelectedIndex] = useChatHistory() + const [chatHistory, setSelectedIndex] = useChatHistory() const [isEditing, setIsEditing] = useState(false); const [inputValue, setInputValue] = useState(''); - setChatHistory(chatHistory) const handleEditButtonClick = () => { setIsEditing(true); - - /* Thank you Eslint for this masterpiece of a code snippet */ - setChatHistory(chatHistory) - /* Wow i feel so secure now */ }; const handleInputChange = (e: React.ChangeEvent) => { diff --git a/app/hooks/useChatHistory.tsx b/app/hooks/useChatHistory.tsx index b153eef..29f9b97 100644 --- a/app/hooks/useChatHistory.tsx +++ b/app/hooks/useChatHistory.tsx @@ -31,7 +31,7 @@ const setGlobalState = (newState: GlobalChatHistory): void => { listeners.forEach((listener) => listener(globalChatHistory)) } -export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistory) => void, (index:number)=>void, (messageIndex: number, newContent:string)=> void] => { +export const useChatHistory = (): [GlobalChatHistory, (index:number)=>void, (newState:GlobalChatHistory) => void,(messageIndex: number, newContent:string)=> void] => { const [state, setState] = useState(globalChatHistory) useEffect(() => { @@ -65,5 +65,5 @@ export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistor } } - return [state, setGlobalState, setSelectedIndex, updateMessage] + return [state, setSelectedIndex, setGlobalState, updateMessage] } \ No newline at end of file From 416dcb17ef9a5e5db1c04a1e735bfcbb607af384 Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Wed, 9 Oct 2024 15:07:05 +0200 Subject: [PATCH 3/5] show selected chat --- app/backend/ProcessMemory.ts | 19 ------------------- app/components/History.tsx | 5 ++++- app/components/settings/settingUtils.ts | 1 - 3 files changed, 4 insertions(+), 21 deletions(-) delete mode 100644 app/backend/ProcessMemory.ts diff --git a/app/backend/ProcessMemory.ts b/app/backend/ProcessMemory.ts deleted file mode 100644 index 5765138..0000000 --- a/app/backend/ProcessMemory.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* import { Settings } from 'electron' - -type Message = { - role: string - content: string -} - -type Chat = { - name: string - messages: Message[] -} - -type Data = { - chats: Chat[] - settings: Settings[] -} */ - - - diff --git a/app/components/History.tsx b/app/components/History.tsx index 0aae50f..7e23d6b 100644 --- a/app/components/History.tsx +++ b/app/components/History.tsx @@ -35,7 +35,10 @@ const History: React.FC = () => { {/* Populate with history items */} {chatHistory.chats.map((chats, index) => (
  • - handleHistoryClick(index)}> + handleHistoryClick(index)} style={{ + backgroundColor: chatHistory.selectedIndex == index ? "var(--input-button-color)" : "", + borderRadius:"5px" + }}> {chatHistory.chats[index].name}
  • diff --git a/app/components/settings/settingUtils.ts b/app/components/settings/settingUtils.ts index de08012..f6cd00d 100644 --- a/app/components/settings/settingUtils.ts +++ b/app/components/settings/settingUtils.ts @@ -45,7 +45,6 @@ export const sendToDatabase = async () => { if (useName && usePassword) { const result = await changeSettings(useName, usePassword, JSON.parse(exportSettings())) if (result == true) { - alert('Data has been transferred') window.location.reload(); } } From 227469129126f69412d3768e13db7c60e284b3e8 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Wed, 9 Oct 2024 15:34:44 +0200 Subject: [PATCH 4/5] deployment changes --- deployment_scripts/linux/prepare_all.sh | 30 +++++++++++++++++++ .../{prepare-free.sh => prepare_free.sh} | 0 ...{prepare-nonfree.sh => prepare_nonfree.sh} | 0 deployment_scripts/linux/root.sh | 2 +- deployment_scripts/linux/run.sh | 1 + deployment_scripts/windows/prepare_all.bat | 4 +++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 deployment_scripts/linux/prepare_all.sh rename deployment_scripts/linux/{prepare-free.sh => prepare_free.sh} (100%) rename deployment_scripts/linux/{prepare-nonfree.sh => prepare_nonfree.sh} (100%) create mode 100644 deployment_scripts/windows/prepare_all.bat diff --git a/deployment_scripts/linux/prepare_all.sh b/deployment_scripts/linux/prepare_all.sh new file mode 100644 index 0000000..03dd10c --- /dev/null +++ b/deployment_scripts/linux/prepare_all.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +chmod +x root.sh +pkexec ./root.sh +npm install +npm run build + +cd py +python3 -m venv venv +source venv/bin/activate +python3 -m pip install -r requirements.txt + +ollama pull qwen2-math:1.5b +ollama pull qwen2.5-coder:1.5b +ollama pull phi3.5 + +ollama pull mathstral +ollama pull qwen2.5-coder +ollama pull qwen2.5 + +ollama pull qwen2-math:1.5b +ollama pull starcoder2 +ollama pull llama3.2 + +ollama pull wizard-math +ollama pull starcoder2:7b +ollama pull llama3.1 + +cd .. +chmod +x run.sh \ No newline at end of file diff --git a/deployment_scripts/linux/prepare-free.sh b/deployment_scripts/linux/prepare_free.sh similarity index 100% rename from deployment_scripts/linux/prepare-free.sh rename to deployment_scripts/linux/prepare_free.sh diff --git a/deployment_scripts/linux/prepare-nonfree.sh b/deployment_scripts/linux/prepare_nonfree.sh similarity index 100% rename from deployment_scripts/linux/prepare-nonfree.sh rename to deployment_scripts/linux/prepare_nonfree.sh diff --git a/deployment_scripts/linux/root.sh b/deployment_scripts/linux/root.sh index 7fc9b13..312679d 100644 --- a/deployment_scripts/linux/root.sh +++ b/deployment_scripts/linux/root.sh @@ -1,6 +1,6 @@ #!/bin/bash -apt install npm nodejs python3-full ffmpeg libgtk-3-0t64 libnotify4 libnss3 libxss1 libasound2 build-essential cmake -y +apt install npm nodejs python3-full ffmpeg libgtk-3-0t64 libnotify4 libnss3 libxss1 libasound2t64 build-essential cmake -y if ! ollama; then curl -fsSL https://ollama.com/install.sh | sh fi diff --git a/deployment_scripts/linux/run.sh b/deployment_scripts/linux/run.sh index 1220bae..a4ad3f9 100644 --- a/deployment_scripts/linux/run.sh +++ b/deployment_scripts/linux/run.sh @@ -9,6 +9,7 @@ cd .. npm start & pid_node=$! +sleep 2 npx electron . kill $pid_py diff --git a/deployment_scripts/windows/prepare_all.bat b/deployment_scripts/windows/prepare_all.bat new file mode 100644 index 0000000..e610454 --- /dev/null +++ b/deployment_scripts/windows/prepare_all.bat @@ -0,0 +1,4 @@ +start /b scripts\prepare_py.bat +start /b scripts\prepare_npm.bat +start /b scripts\prepare_ollama_free.bat +start /b scripts\prepare_ollama_nonfree.bat \ No newline at end of file From 299539dc868841b6682080c2630a2553b6e73df6 Mon Sep 17 00:00:00 2001 From: YasinOnm08 Date: Wed, 9 Oct 2024 15:56:06 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A4=AB=F0=9F=A4=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/backend/InputOutputHandler.tsx | 20 ++++++++++++-------- app/hooks/useChatHistory.tsx | 3 +-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/backend/InputOutputHandler.tsx b/app/backend/InputOutputHandler.tsx index 1a4817b..e56bbe9 100644 --- a/app/backend/InputOutputHandler.tsx +++ b/app/backend/InputOutputHandler.tsx @@ -21,7 +21,7 @@ const InputOutputBackend: React.FC = () => { const [preferredMeasurement, setPreferredMeasurement] = useState("metric"); const [timeZone, setTimeZone] = useState("GMT"); const [dateFormat, setDateFormat] = useState("DD-MM-YYYY"); - const [messages, setMessages] = useState(chatHistory.chats[chatHistory.selectedIndex]?.messages || []); + const [messages, setMessages] = useState(chatHistory.chats[chatHistory.selectedIndex].messages || []); const [myBoolean, setMyBoolean] = useState(false); const [systemMessage, setSystemMessage] = useState("You are a helpful assistant") const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create") @@ -31,22 +31,26 @@ const InputOutputBackend: React.FC = () => { apiURL.hostname = "localhost" } + console.log(setSelectedIndex) - useEffect(() => { +useEffect(() => { console.log("History", chatHistory); console.log("Messages", messages); // Get the current chat's messages - const currentMessages = chatHistory.chats[chatHistory.selectedIndex]?.messages || []; + const currentMessages = chatHistory.chats[chatHistory.selectedIndex].messages || []; - // If currentMessages is not empty, update messages only if it's not the same - if (currentMessages.length > 0 && JSON.stringify(currentMessages) !== JSON.stringify(messages)) { + // If the selected chat has messages, set them + if (currentMessages.length > 0) { setMessages(currentMessages); - } else if (messages.length === 0) { - setMessages([{ role: "system", content: systemMessage }, { role: "assistant", content: "Hello! How can I help you?" }]); + } 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, setSelectedIndex]); +}, [chatHistory, chatHistory.selectedIndex, systemMessage]); // Update messages when any of the settings change useEffect(() => { diff --git a/app/hooks/useChatHistory.tsx b/app/hooks/useChatHistory.tsx index 29f9b97..b2aceb0 100644 --- a/app/hooks/useChatHistory.tsx +++ b/app/hooks/useChatHistory.tsx @@ -19,8 +19,7 @@ interface GlobalChatHistory { let globalChatHistory: GlobalChatHistory = { chats: [ - { name: "Chat 1", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"how can i help you"}], timestamp: 4 }, - { name: "Chat 2", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"how can i help you"}], timestamp: 4 }, + { name: "Welcome!", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"Hello! How can I help you?"}], timestamp: 4 }, ], selectedIndex:0 }