Merge pull request 'main' (#47) from React-Group/interstellar_ai:main into main

Reviewed-on: https://interstellardevelopment.org/code/code/sageTheDm/interstellar_ai/pulls/47
This commit is contained in:
Patrick 2024-10-09 13:36:39 +02:00
commit 9ee165c5c5
4 changed files with 33 additions and 16 deletions

View file

@ -15,7 +15,7 @@ const InputOutputBackend: React.FC = () => {
} }
// Define state variables for user preferences and messages // Define state variables for user preferences and messages
const [chatHistory, setChatHistory, setSelectedIndex] = useChatHistory() const [chatHistory, setChatHistory, setSelectedIndex, updateMessage] = useChatHistory()
const [preferredCurrency, setPreferredCurrency] = useState<string>("USD"); const [preferredCurrency, setPreferredCurrency] = useState<string>("USD");
const [preferredLanguage, setPreferredLanguage] = useState<string>("english"); const [preferredLanguage, setPreferredLanguage] = useState<string>("english");
const [timeFormat, setTimeFormat] = useState<string>("24-hour"); const [timeFormat, setTimeFormat] = useState<string>("24-hour");
@ -186,17 +186,19 @@ const InputOutputBackend: React.FC = () => {
if (newContent == "") { if (newContent == "") {
newContent = "Generating answer..." newContent = "Generating answer..."
} }
setMessages((prevMessages) => { const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length-1
const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages updateMessage(messageIndex,newContent)
if (updatedMessages.length > 0) { // setMessages((prevMessages) => {
const lastMessage = updatedMessages[updatedMessages.length - 1]; // const updatedMessages = prevMessages.slice(); // Create a shallow copy of the current messages
updatedMessages[updatedMessages.length - 1] = { // if (updatedMessages.length > 0) {
...lastMessage, // Keep the existing role and other properties // const lastMessage = updatedMessages[updatedMessages.length - 1];
content: newContent, // Update only the content // updatedMessages[updatedMessages.length - 1] = {
}; // ...lastMessage, // Keep the existing role and other properties
} // content: newContent, // Update only the content
return updatedMessages; // Return the updated array // };
}); // }
// return updatedMessages; // Return the updated array
// });
}; };
const addMessage = (role: string, content: string) => { const addMessage = (role: string, content: string) => {

View file

@ -31,7 +31,7 @@ const setGlobalState = (newState: GlobalChatHistory): void => {
listeners.forEach((listener) => listener(globalChatHistory)) listeners.forEach((listener) => listener(globalChatHistory))
} }
export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistory) => void, (index:number)=>void] => { export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistory) => void, (index:number)=>void, (messageIndex: number, newContent:string)=> void] => {
const [state, setState] = useState<GlobalChatHistory>(globalChatHistory) const [state, setState] = useState<GlobalChatHistory>(globalChatHistory)
useEffect(() => { useEffect(() => {
@ -52,5 +52,18 @@ export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistor
setGlobalState({...state,selectedIndex:index}) setGlobalState({...state,selectedIndex:index})
} }
return [state, setGlobalState, setSelectedIndex] const updateMessage = (messageIndex: number, newContent: string) => {
const updatedChats = [...state.chats]
const chatIndex = globalChatHistory.selectedIndex
if (chatIndex >= 0 && chatIndex < updatedChats.length) {
const updatedMessages = [...updatedChats[chatIndex].messages]
if (messageIndex >= 0 && messageIndex < updatedMessages.length) {
updatedMessages[messageIndex] = { ...updatedMessages[messageIndex], content: newContent }
updatedChats[chatIndex] = { ...updatedChats[chatIndex], messages: updatedMessages }
setGlobalState({...state, chats: updatedChats})
}
}
}
return [state, setGlobalState, setSelectedIndex, updateMessage]
} }

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
apt install npm nodejs python3-full -y apt install npm nodejs python3-full ffmpeg libgtk-3-0 libnotify4 libgconf-2-4 libnss3 libxss1 libasound2 build-essential cmake -y
if ! ollama; then if ! ollama; then
curl -fsSL https://ollama.com/install.sh | sh curl -fsSL https://ollama.com/install.sh | sh
fi fi

View file

@ -1,8 +1,10 @@
#!/bin/bash #!/bin/bash
cd py cd py
python api.py & source venv/bin/activate
python3 api.py &
pid_py=$! pid_py=$!
cd ..
npm start & npm start &
pid_node=$! pid_node=$!