fixed some database backend stuff

This commit is contained in:
Patrick_Pluto 2024-09-30 15:26:31 +02:00
parent 26b69a1cb6
commit 223f953648
8 changed files with 58 additions and 41 deletions

View file

@ -9,7 +9,6 @@ import { resolve } from "path";
import { FFmpeg } from "@ffmpeg/ffmpeg";
import { fetchFile, toBlobURL } from "@ffmpeg/util"
const InputOutputBackend: React.FC = () => {
// # variables
type Message = {
@ -174,7 +173,15 @@ const InputOutputBackend: React.FC = () => {
if (postWorkerRef.current) {
addMessage("user", inputValue)
console.log("input:", inputValue);
postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", access_token: accessToken })
const type = localStorage.getItem('type')
var api_key: string = ""
if (type != null && type != 'local') {
const try_key = localStorage.getItem(type)
if (try_key) {
api_key = try_key
}
}
postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: localStorage.getItem('model'), model_type: type, access_token: accessToken, api_key: api_key })
startGetWorker()
}
}

View file

@ -18,27 +18,28 @@ 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.
*/
export const sendToDatabase = (data: any): Promise<boolean> => {
return axios.post("http://localhost:5000/interstellar_ai/db", data)
.then(response => {
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
return success; // Ensure success is returned to the caller
})
.catch(error => {
postMessage({ status: 500, success: false });
return false; // Return false in case of an error
});
export const sendToDatabase = async (data: any): Promise<boolean> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
console.log(status);
return success;
} catch (error) {
postMessage({ status: 500, success: false });
console.log("NO");
return false;
}
};
// Functions for each action
export const createAccount = async (username: string, email: string, password: string) => {
const data = {
action: "create_account",
username,
email,
password,
username: username,
email: email,
password: password,
};
return await sendToDatabase(data);
};

View file

@ -1,14 +1,15 @@
import axios from "axios";
onmessage = (e) => {
const { messages, ai_model = "llama3.2", access_token } = e.data
const { messages, ai_model, model_type, access_token, api_key } = e.data
const Message = {
messages: messages,
ai_model: "llama3.2",
model_type: "local",
access_token: access_token
ai_model: ai_model,
model_type: model_type,
access_token: access_token,
api_key: api_key
}
console.log(Message);

View file

@ -6,7 +6,6 @@ export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
const formdata = new FormData()
formdata.append("audio", audio_data)
const dataSend = { option: "offline", type: "basic", audio: audio_data }
return axios.post("http://localhost:5000/interstellar_ai/api/voice_recognition", formdata)
.then((response) => {
console.log(response.data)

View file

@ -240,6 +240,9 @@ const Models: React.FC = () => {
console.log(model)
console.log(category)
console.log(modelList[category][model as keyof typeof modelList[typeof category]]);
console.log(modelList[category]['model_type' as keyof typeof modelList[typeof category]])
localStorage.setItem("model", modelList[category][model as keyof typeof modelList[typeof category]])
localStorage.setItem("type", modelList[category]['model_type' as keyof typeof modelList[typeof category]])
}
return (