From cb6298476aef1708ca2151bf79ea6af64920c404 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 30 Sep 2024 09:35:58 +0200 Subject: [PATCH 1/5] very good documentation --- app/backend/ProcessMemory.ts | 20 ++++++++++++++++++++ app/backend/ProcessMemory.tsx | 13 ------------- app/backend/database.ts | 21 +++++++++++++++++---- py/api.py | 2 ++ py/voice.py | 3 +-- 5 files changed, 40 insertions(+), 19 deletions(-) create mode 100644 app/backend/ProcessMemory.ts delete mode 100644 app/backend/ProcessMemory.tsx diff --git a/app/backend/ProcessMemory.ts b/app/backend/ProcessMemory.ts new file mode 100644 index 0000000..d66d8e5 --- /dev/null +++ b/app/backend/ProcessMemory.ts @@ -0,0 +1,20 @@ +import { Settings } from 'electron' +import React from 'react' + +type Message = { + role: string + content: string +} + +type Chat = { + name: string + messages: Message[] +} + +type Data = { + chats: Chat[] + settings: Settings[] +} + + + diff --git a/app/backend/ProcessMemory.tsx b/app/backend/ProcessMemory.tsx deleted file mode 100644 index c402e15..0000000 --- a/app/backend/ProcessMemory.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react' - -type Chat = { - name:string - messages:string[] -} - -type History = { - chats:Chat[] -} - - - diff --git a/app/backend/database.ts b/app/backend/database.ts index 7b7437d..28e2f04 100644 --- a/app/backend/database.ts +++ b/app/backend/database.ts @@ -1,16 +1,29 @@ import axios from "axios"; +/* +This is the guide on how to user this function: + +data should be the json containing everything relevant, the json can contain the following keys: + +action -> contains the action you want to do, there are: create_account, change_password, get_data, change_data, check_credentials, delete_account +username -> contains the current username, required for create_account, but can be omitted in favor of email in other requests. Preffered over email authentication. +email -> contains the current email, required for create_account, but just like the username, it can be ommitted, in favor of the other, sending both is possible too. +password -> contains the password, required for all requests. +new_password -> in the case you are changing your password, you will need to use this in addition to password, to specify the new password. +data -> data contains all the data you want to store, you have to always give the entire data, because the data you give here overwrites the data in the database, so if you only give the chat history for example, all settings will be deleted, and if you only give settings, all chat histories will get deleted. + + +if all went well, you will get the status 200 in response.data.status +to check if the request was accepted or declined, check response.data.response, it will be either true or false depending on if it worked, or not. +*/ + const sendToDatabase = (data: any) => { axios.post("http://localhost:5000/interstellar_ai/db", data) .then(response => { const status = response.data.status - console.log(status); postMessage({ status }) - console.log('message posted'); - }) .catch(error => { - console.log("Error calling Database:", error) postMessage({ status: 500 }) }) } \ No newline at end of file diff --git a/py/api.py b/py/api.py index 18af5e4..84df891 100644 --- a/py/api.py +++ b/py/api.py @@ -94,6 +94,8 @@ class API: return jsonify({'status': 200, 'response': self.db.change_data(data)}) elif action == "check_credentials": return jsonify({'status': 200, 'response': self.db.check_credentials(data)}) + elif action == "delete_account": + return jsonify({'status': 200, 'response': self.db.delete_user(data)}) return jsonify({'status': 401, 'response': "Invalid action"}) diff --git a/py/voice.py b/py/voice.py index dc0d28b..24d12ac 100644 --- a/py/voice.py +++ b/py/voice.py @@ -1,5 +1,4 @@ import io -import numpy as np from faster_whisper import WhisperModel from pydub import AudioSegment @@ -19,7 +18,7 @@ class VoiceRecognition: print("audio to wav failed") model_size = "base" - model = WhisperModel(model_size, device="cpu", compute_type="int8") + model = WhisperModel(model_size, device="cpu", compute_type=" ") segments, _ = model.transcribe(wav_io) transcription = "" From 36ca833f735441a191722e87488f17affc6fb6e9 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 30 Sep 2024 10:43:22 +0200 Subject: [PATCH 2/5] yesyes very good commit --- app/components/Models.tsx | 138 +++++++++++++++++++++++++++++++++++++- 1 file changed, 135 insertions(+), 3 deletions(-) diff --git a/app/components/Models.tsx b/app/components/Models.tsx index 894623a..fefd765 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -1,7 +1,131 @@ "use client"; import React, { useState, useEffect } from 'react'; -// Define the available model options +// Define all models that should be available. +const modelList = { + 'Offline Fast': { + 'Math': 'qwen2-math:1.5b', + 'Code': 'starcoder2', + 'Language': 'llama3.2', + 'Character': 'dolphin-phi', + 'Finance': 'qwen2-math:1.5b', + 'Weather': 'llama3.2', + 'Time': 'llama3.2', + 'Image': 'llava-phi3' + }, + 'Offline Slow': { + 'Math': 'wizard-math', + 'Code': 'starcoder2:7b', + 'Language': 'llama3.1', + 'Character': 'dolphin-llama3', + 'Finance': 'wizard-math', + 'Weather': 'llama3.1', + 'Time': 'llama3.1', + 'Image': 'llava' + }, + 'Offline Fast (FOSS)': { + 'Math': 'qwen2-math:1.5b', + 'Code': 'qwen2.5-coder:1.5b', + 'Language': 'phi3.5', + 'Character': 'dolphin-mistral', + 'Finance': 'qwen2-math:1.5b', + 'Weather': 'phi3.5', + 'Time': 'phi3.5', + 'Image': 'llava' + }, + 'Offline Slow (FOSS)': { + 'Math': 'mathstral', + 'Code': 'qwen2.5-coder', + 'Language': 'qwen2.5', + 'Character': 'dolphin-mistral', + 'Finance': 'mathstral', + 'Weather': 'qwen2.5', + 'Time': 'qwen2.5', + 'Image': 'llava' + }, + 'Online Cheap (OpenAI)': { + 'Math': 'gpt-4o-mini', + 'Code': 'gpt-4o-mini', + 'Language': 'gpt-4o-mini', + 'Character': 'gpt-4o-mini', + 'Finance': 'gpt-4o-mini', + 'Weather': 'gpt-4o-mini', + 'Time': 'gpt-4o-mini', + 'Image': 'gpt-4o-mini' + }, + 'Online Expensive (OpenAI)': { + 'Math': 'gpt-4o', + 'Code': 'gpt-4o', + 'Language': 'gpt-4o', + 'Character': 'gpt-4o', + 'Finance': 'gpt-4o', + 'Weather': 'gpt-4o', + 'Time': 'gpt-4o', + 'Image': 'gpt-4o' + }, + 'Online Cheap (Anthropic)': { + 'Math': 'claude-3-haiku', + 'Code': 'claude-3-haiku', + 'Language': 'claude-3-haiku', + 'Character': 'claude-3-haiku', + 'Finance': 'claude-3-haiku', + 'Weather': 'claude-3-haiku', + 'Time': 'claude-3-haiku', + 'Image': 'claude-3-haiku' + }, + 'Online Expensive (Anthropic)': { + 'Math': 'claude-3-5-sonnet', + 'Code': 'claude-3-5-sonnet', + 'Language': 'claude-3-5-sonnet', + 'Character': 'claude-3-5-sonnet', + 'Finance': 'claude-3-5-sonnet', + 'Weather': 'claude-3-5-sonnet', + 'Time': 'claude-3-5-sonnet', + 'Image': 'claude-3-5-sonnet' + }, + 'Online Cheap (Google)': { + 'Math': 'gemini-1.5-flash-latest', + 'Code': 'gemini-1.5-flash-latest', + 'Language': 'gemini-1.5-flash-latest', + 'Character': 'gemini-1.5-flash-latest', + 'Finance': 'gemini-1.5-flash-latest', + 'Weather': 'gemini-1.5-flash-latest', + 'Time': 'gemini-1.5-flash-latest', + 'Image': 'gemini-1.5-flash-latest' + }, + 'Online Expensive (Google)': { + 'Math': 'gemini-1.5-pro-latest', + 'Code': 'gemini-1.5-pro-latest', + 'Language': 'gemini-1.5-pro-latest', + 'Character': 'gemini-1.5-pro-latest', + 'Finance': 'gemini-1.5-pro-latest', + 'Weather': 'gemini-1.5-pro-latest', + 'Time': 'gemini-1.5-pro-latest', + 'Image': 'gemini-1.5-pro-latest' + }, + 'Online (La Plateforme)': { + 'Math': 'open-mistral-nemo', + 'Code': 'codestral-latest', + 'Language': 'mistral-small-latest', + 'Character': 'mistral-large-latest', + 'Finance': 'open-mistral-nemo', + 'Weather': 'mistral-small-latest', + 'Time': 'mistral-small-latest', + 'Image': 'pixtral-12b-2409' + }, + 'Online (FOSS) (La Plateforme)': { + 'Math': 'open-mistral-nemo', + 'Code': 'open-codestral-mamba', + 'Language': 'open-mistral-nemo', + 'Character': 'open-mixtral-8x22b', + 'Finance': 'open-mixtral-8x22b', + 'Weather': 'open-mistral-nemo', + 'Time': 'open-mistral-nemo', + 'Image': 'pixtral-12b-2409' + } +} + +// Define the available category options const modelDropdown = { offlineWithoutFoss: ['Offline Fast', 'Offline Slow'], offlineFoss: ['Offline Fast (FOSS)', 'Offline Slow (FOSS)'], @@ -12,6 +136,7 @@ const modelDropdown = { 'Online Expensive (Anthropic)', 'Online Cheap (Google)', 'Online Expensive (Google)', + 'Online (La Plateforme)' ], onlineFoss: ['Online (FOSS) (La Plateforme)'], }; @@ -20,7 +145,7 @@ const Models: React.FC = () => { // Initialize state with value from localStorage or default to '' const [selectedModel, setSelectedModel] = useState(''); const [radioSelection, setRadioSelection] = useState("") - + useEffect(() => { setRadioSelection(localStorage.getItem('radioSelection')) const handleStorageChange = () => { @@ -98,6 +223,13 @@ const Models: React.FC = () => { const isOfflineModel = (model: string) => modelDropdown.offlineWithoutFoss.includes(model) || modelDropdown.offlineFoss.includes(model); + const modelClicked = (model: string) => { + const category = selectedModel as keyof typeof modelList; + console.log(model) + console.log(category) + console.log(modelList[category][model as keyof typeof modelList[typeof category]]); + } + return (
@@ -122,7 +254,7 @@ const Models: React.FC = () => {
{['Code', 'Math', 'Language', 'Character', 'Finance', 'Weather', 'Time', 'Image', 'Custom1', 'Custom2'].map( (category) => ( - +
+
+
From d83aeb2c7400ea4e99664822d2a7281b4f310254 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 30 Sep 2024 11:30:30 +0200 Subject: [PATCH 4/5] mild changes to the ais and added models to models.tsx --- app/components/Models.tsx | 12 ++++++++++++ py/ai.py | 9 ++------- py/api.py | 7 +++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/components/Models.tsx b/app/components/Models.tsx index fefd765..1f9dc56 100644 --- a/app/components/Models.tsx +++ b/app/components/Models.tsx @@ -4,6 +4,7 @@ import React, { useState, useEffect } from 'react'; // Define all models that should be available. const modelList = { 'Offline Fast': { + 'model_type': 'local', 'Math': 'qwen2-math:1.5b', 'Code': 'starcoder2', 'Language': 'llama3.2', @@ -14,6 +15,7 @@ const modelList = { 'Image': 'llava-phi3' }, 'Offline Slow': { + 'model_type': 'local', 'Math': 'wizard-math', 'Code': 'starcoder2:7b', 'Language': 'llama3.1', @@ -24,6 +26,7 @@ const modelList = { 'Image': 'llava' }, 'Offline Fast (FOSS)': { + 'model_type': 'local', 'Math': 'qwen2-math:1.5b', 'Code': 'qwen2.5-coder:1.5b', 'Language': 'phi3.5', @@ -34,6 +37,7 @@ const modelList = { 'Image': 'llava' }, 'Offline Slow (FOSS)': { + 'model_type': 'local', 'Math': 'mathstral', 'Code': 'qwen2.5-coder', 'Language': 'qwen2.5', @@ -44,6 +48,7 @@ const modelList = { 'Image': 'llava' }, 'Online Cheap (OpenAI)': { + 'model_type': 'openai', 'Math': 'gpt-4o-mini', 'Code': 'gpt-4o-mini', 'Language': 'gpt-4o-mini', @@ -54,6 +59,7 @@ const modelList = { 'Image': 'gpt-4o-mini' }, 'Online Expensive (OpenAI)': { + 'model_type': 'openai', 'Math': 'gpt-4o', 'Code': 'gpt-4o', 'Language': 'gpt-4o', @@ -64,6 +70,7 @@ const modelList = { 'Image': 'gpt-4o' }, 'Online Cheap (Anthropic)': { + 'model_type': 'anthropic', 'Math': 'claude-3-haiku', 'Code': 'claude-3-haiku', 'Language': 'claude-3-haiku', @@ -74,6 +81,7 @@ const modelList = { 'Image': 'claude-3-haiku' }, 'Online Expensive (Anthropic)': { + 'model_type': 'anthropic', 'Math': 'claude-3-5-sonnet', 'Code': 'claude-3-5-sonnet', 'Language': 'claude-3-5-sonnet', @@ -84,6 +92,7 @@ const modelList = { 'Image': 'claude-3-5-sonnet' }, 'Online Cheap (Google)': { + 'model_type': 'google', 'Math': 'gemini-1.5-flash-latest', 'Code': 'gemini-1.5-flash-latest', 'Language': 'gemini-1.5-flash-latest', @@ -94,6 +103,7 @@ const modelList = { 'Image': 'gemini-1.5-flash-latest' }, 'Online Expensive (Google)': { + 'model_type': 'google', 'Math': 'gemini-1.5-pro-latest', 'Code': 'gemini-1.5-pro-latest', 'Language': 'gemini-1.5-pro-latest', @@ -104,6 +114,7 @@ const modelList = { 'Image': 'gemini-1.5-pro-latest' }, 'Online (La Plateforme)': { + 'model_type': 'mistral', 'Math': 'open-mistral-nemo', 'Code': 'codestral-latest', 'Language': 'mistral-small-latest', @@ -114,6 +125,7 @@ const modelList = { 'Image': 'pixtral-12b-2409' }, 'Online (FOSS) (La Plateforme)': { + 'model_type': 'mistral', 'Math': 'open-mistral-nemo', 'Code': 'open-codestral-mamba', 'Language': 'open-mistral-nemo', diff --git a/py/ai.py b/py/ai.py index 5879e9d..2554fd5 100644 --- a/py/ai.py +++ b/py/ai.py @@ -80,11 +80,6 @@ class AI: message = messages[-1]['content'] messages.pop() - system = None - if messages and messages[0]['role'] == 'system': - system = messages[0]['content'] - messages.pop(0) - for msg in messages: msg['parts'] = msg.pop('content') @@ -97,8 +92,8 @@ class AI: model = genai.GenerativeModel(model) chat = model.start_chat( - system_instruction=system, - history=messages + history=messages, + ) response = chat.send_message(message, stream=True) diff --git a/py/api.py b/py/api.py index 84df891..75fbfd4 100644 --- a/py/api.py +++ b/py/api.py @@ -70,6 +70,13 @@ class API: thread.start() thread.join() return jsonify({'status': 200}) + elif model_type == "google": + api_key = data.get('api_key') + thread = threading.Thread(target=self.ai.process_google, + args=(ai_model, messages, self, access_token, api_key)) + thread.start() + thread.join() + return jsonify({'status': 200}) return jsonify({'status': 401, 'error': 'Invalid AI model type'}) From 43fdeb815b12c3b725d8ffaa0531f2923aa828cf Mon Sep 17 00:00:00 2001 From: sageTheDM Date: Mon, 30 Sep 2024 11:36:47 +0200 Subject: [PATCH 5/5] Changed the local storage of API keys for reassons --- app/components/Settings.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/app/components/Settings.tsx b/app/components/Settings.tsx index 556a416..48e452c 100644 --- a/app/components/Settings.tsx +++ b/app/components/Settings.tsx @@ -90,8 +90,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( const [selectedTheme, setSelectedTheme] = useState(() => localStorage.getItem('selectedTheme') || 'default'); // API Keys - const [laPlateforme, setLaPlateforme] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-la-plateforme').trim()); - const [openAI, setOpenAI] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-openai').trim()); + const [mistral, setmistral] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-la-plateforme').trim()); + const [openai, setopenai] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-openai').trim()); const [anthropic, setAnthropic] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-anthropic').trim()); const [google, setGoogle] = useState(() => getComputedStyle(document.documentElement).getPropertyValue('--online-cheap-google').trim()); @@ -142,8 +142,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( fontSize, burgerMenu, selectedTheme, - laPlateforme, - openAI, + mistral, + openai, anthropic, google, }; @@ -192,8 +192,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( fontSize, burgerMenu, selectedTheme, - laPlateforme, - openAI, + mistral, + openai, anthropic, google, ]); @@ -938,16 +938,16 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( setLaPlateforme(e.target.value)} + value={mistral} + onChange={(e) => setmistral(e.target.value)} />
setOpenAI(e.target.value)} + value={openai} + onChange={(e) => setopenai(e.target.value)} />
@@ -1030,8 +1030,8 @@ const Settings: React.FC<{ closeSettings: () => void; accountName: string }> = ( openSourceMode, // API Keys - laPlateforme, - openAI, + mistral, + openai, anthropic, google };