forked from React-Group/interstellar_ai
Merge branch 'main' into main
This commit is contained in:
commit
b8eccfbefe
13 changed files with 65 additions and 68 deletions
|
@ -4,7 +4,6 @@ import ConversationFrontend from '../components/ConversationFrontend';
|
||||||
import InputFrontend from "../components/InputFrontend";
|
import InputFrontend from "../components/InputFrontend";
|
||||||
import { sendToVoiceRecognition } from "./voice_backend"
|
import { sendToVoiceRecognition } from "./voice_backend"
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import { changeHistory, checkCredentials, getHistory } from './database';
|
|
||||||
import { useChatHistory } from '../hooks/useChatHistory';
|
import { useChatHistory } from '../hooks/useChatHistory';
|
||||||
|
|
||||||
const InputOutputBackend: React.FC = () => {
|
const InputOutputBackend: React.FC = () => {
|
||||||
|
@ -15,14 +14,14 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define state variables for user preferences and messages
|
// Define state variables for user preferences and messages
|
||||||
const [chatHistory, setChatHistory, setSelectedIndex, updateMessage] = useChatHistory()
|
const [chatHistory, setSelectedIndex, setChatHistory, 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");
|
||||||
const [preferredMeasurement, setPreferredMeasurement] = useState<string>("metric");
|
const [preferredMeasurement, setPreferredMeasurement] = useState<string>("metric");
|
||||||
const [timeZone, setTimeZone] = useState<string>("GMT");
|
const [timeZone, setTimeZone] = useState<string>("GMT");
|
||||||
const [dateFormat, setDateFormat] = useState<string>("DD-MM-YYYY");
|
const [dateFormat, setDateFormat] = useState<string>("DD-MM-YYYY");
|
||||||
const [messages, setMessages] = useState<Message[]>(chatHistory.chats[chatHistory.selectedIndex]?.messages || []);
|
const [messages, setMessages] = useState<Message[]>(chatHistory.chats[chatHistory.selectedIndex].messages || []);
|
||||||
const [myBoolean, setMyBoolean] = useState<boolean>(false);
|
const [myBoolean, setMyBoolean] = useState<boolean>(false);
|
||||||
const [systemMessage, setSystemMessage] = useState<string>("You are a helpful assistant")
|
const [systemMessage, setSystemMessage] = useState<string>("You are a helpful assistant")
|
||||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create")
|
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create")
|
||||||
|
@ -32,22 +31,26 @@ const InputOutputBackend: React.FC = () => {
|
||||||
apiURL.hostname = "localhost"
|
apiURL.hostname = "localhost"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(setSelectedIndex)
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
console.log("History", chatHistory);
|
console.log("History", chatHistory);
|
||||||
console.log("Messages", messages);
|
console.log("Messages", messages);
|
||||||
|
|
||||||
// Get the current chat's 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 the selected chat has messages, set them
|
||||||
if (currentMessages.length > 0 && JSON.stringify(currentMessages) !== JSON.stringify(messages)) {
|
if (currentMessages.length > 0) {
|
||||||
setMessages(currentMessages);
|
setMessages(currentMessages);
|
||||||
} else if (messages.length === 0) {
|
} else if (currentMessages.length === 0) {
|
||||||
setMessages([{ role: "system", content: systemMessage }, { role: "assistant", content: "Hello! How can I help you?" }]);
|
// 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
|
// Update messages when any of the settings change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -80,13 +83,9 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]);
|
}, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const updateSystemprompt = (prompt: string) => {
|
const messageIndex = 0 // system prompt is the first so index 0
|
||||||
setMessages(prevMessages => {
|
updateMessage(messageIndex, systemMessage)
|
||||||
const newMessage = { role: "system", content: prompt }
|
console.log(messages)
|
||||||
return [newMessage, ...prevMessages]
|
|
||||||
})
|
|
||||||
}
|
|
||||||
updateSystemprompt
|
|
||||||
},[systemMessage])
|
},[systemMessage])
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,17 +187,6 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length-1
|
const messageIndex = chatHistory.chats[chatHistory.selectedIndex].messages.length-1
|
||||||
updateMessage(messageIndex,newContent)
|
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) => {
|
const addMessage = (role: string, content: string) => {
|
||||||
|
|
|
@ -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[]
|
|
||||||
} */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,14 +2,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import InputOutputBackend from '../backend/InputOutputHandler';
|
import InputOutputBackend from '../backend/InputOutputHandler';
|
||||||
|
|
||||||
interface AIProps{
|
const AI: React.FC = () => {
|
||||||
selectedIndex:number
|
|
||||||
}
|
|
||||||
|
|
||||||
const AI: React.FC<AIProps> = ({selectedIndex}) => {
|
|
||||||
return (
|
return (
|
||||||
<div className="ai-container">
|
<div className="ai-container">
|
||||||
<InputOutputBackend selectedIndex={selectedIndex}/>
|
<InputOutputBackend />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,16 +2,13 @@ import React, { useState } from 'react';
|
||||||
import { useChatHistory } from '../hooks/useChatHistory';
|
import { useChatHistory } from '../hooks/useChatHistory';
|
||||||
|
|
||||||
const History: React.FC = () => {
|
const History: React.FC = () => {
|
||||||
const [chatHistory, setChatHistory, setSelectedIndex] = useChatHistory()
|
const [chatHistory, setSelectedIndex] = useChatHistory()
|
||||||
const [isEditing, setIsEditing] = useState(false);
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
const [inputValue, setInputValue] = useState<string>('');
|
const [inputValue, setInputValue] = useState<string>('');
|
||||||
|
|
||||||
|
|
||||||
const handleEditButtonClick = () => {
|
const handleEditButtonClick = () => {
|
||||||
setIsEditing(true);
|
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<HTMLInputElement>) => {
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
|
@ -38,7 +35,10 @@ const History: React.FC = () => {
|
||||||
{/* Populate with history items */}
|
{/* Populate with history items */}
|
||||||
{chatHistory.chats.map((chats, index) => (
|
{chatHistory.chats.map((chats, index) => (
|
||||||
<li key={index}>
|
<li key={index}>
|
||||||
<a href="#" onClick={() => handleHistoryClick(index)}>
|
<a href="#" onClick={() => handleHistoryClick(index)} style={{
|
||||||
|
backgroundColor: chatHistory.selectedIndex == index ? "var(--input-button-color)" : "",
|
||||||
|
borderRadius:"5px"
|
||||||
|
}}>
|
||||||
{chatHistory.chats[index].name}
|
{chatHistory.chats[index].name}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -45,7 +45,6 @@ export const sendToDatabase = async () => {
|
||||||
if (useName && usePassword) {
|
if (useName && usePassword) {
|
||||||
const result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()))
|
const result = await changeSettings(useName, usePassword, JSON.parse(exportSettings()))
|
||||||
if (result == true) {
|
if (result == true) {
|
||||||
alert('Data has been transferred')
|
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@ interface GlobalChatHistory {
|
||||||
|
|
||||||
let globalChatHistory: GlobalChatHistory = {
|
let globalChatHistory: GlobalChatHistory = {
|
||||||
chats: [
|
chats: [
|
||||||
{ name: "Chat 1", 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 },
|
||||||
{ name: "Chat 2", messages: [{role:"system",content:"you are a helpful assistant"},{role:"assistant",content:"how can i help you"}], timestamp: 4 },
|
|
||||||
],
|
],
|
||||||
selectedIndex:0
|
selectedIndex:0
|
||||||
}
|
}
|
||||||
|
@ -31,7 +30,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, (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>(globalChatHistory)
|
const [state, setState] = useState<GlobalChatHistory>(globalChatHistory)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -65,5 +64,5 @@ export const useChatHistory = (): [GlobalChatHistory, (newState:GlobalChatHistor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [state, setGlobalState, setSelectedIndex, updateMessage]
|
return [state, setSelectedIndex, setGlobalState, updateMessage]
|
||||||
}
|
}
|
|
@ -14,7 +14,6 @@ const LandingPage: React.FC = () => {
|
||||||
const [showDivs, setShowDivs] = useState(true);
|
const [showDivs, setShowDivs] = useState(true);
|
||||||
const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI');
|
const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI');
|
||||||
const conversationRef = useRef<HTMLDivElement>(null);
|
const conversationRef = useRef<HTMLDivElement>(null);
|
||||||
const [selectedHistoryIndex, setSelectedHistoryIndex] = useState<number>(0)
|
|
||||||
|
|
||||||
const [primaryColor, setPrimaryColor] = useState("#fefefe");
|
const [primaryColor, setPrimaryColor] = useState("#fefefe");
|
||||||
const [secondaryColor, setSecondaryColor] = useState("#fefefe");
|
const [secondaryColor, setSecondaryColor] = useState("#fefefe");
|
||||||
|
@ -92,13 +91,13 @@ const LandingPage: React.FC = () => {
|
||||||
<div className={`left-panel ${showDivs ? 'visible' : 'hidden'}`}>
|
<div className={`left-panel ${showDivs ? 'visible' : 'hidden'}`}>
|
||||||
{showDivs && (
|
{showDivs && (
|
||||||
<div className="history-models">
|
<div className="history-models">
|
||||||
<History selectedIndex={selectedHistoryIndex} setSelectedIndex={setSelectedHistoryIndex}/>
|
<History />
|
||||||
<Models />
|
<Models />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className={`conversation-container ${showDivs ? 'collapsed' : 'expanded'}`} ref={conversationRef}>
|
<div className={`conversation-container ${showDivs ? 'collapsed' : 'expanded'}`} ref={conversationRef}>
|
||||||
{view === 'AI' && <AI selectedIndex={selectedHistoryIndex} />}
|
{view === 'AI' && <AI />}
|
||||||
{view === 'FAQ' && <FAQ />}
|
{view === 'FAQ' && <FAQ />}
|
||||||
{view === 'Documentation' && <Documentation />}
|
{view === 'Documentation' && <Documentation />}
|
||||||
{view === 'Credits' && <Credits />}
|
{view === 'Credits' && <Credits />}
|
||||||
|
|
30
deployment_scripts/linux/prepare_all.sh
Normal file
30
deployment_scripts/linux/prepare_all.sh
Normal file
|
@ -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
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/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
|
if ! ollama; then
|
||||||
curl -fsSL https://ollama.com/install.sh | sh
|
curl -fsSL https://ollama.com/install.sh | sh
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -9,6 +9,7 @@ cd ..
|
||||||
npm start &
|
npm start &
|
||||||
pid_node=$!
|
pid_node=$!
|
||||||
|
|
||||||
|
sleep 2
|
||||||
npx electron .
|
npx electron .
|
||||||
|
|
||||||
kill $pid_py
|
kill $pid_py
|
||||||
|
|
4
deployment_scripts/windows/prepare_all.bat
Normal file
4
deployment_scripts/windows/prepare_all.bat
Normal file
|
@ -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
|
Loading…
Reference in a new issue