From cb6298476aef1708ca2151bf79ea6af64920c404 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 30 Sep 2024 09:35:58 +0200 Subject: [PATCH] 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 = ""