forked from React-Group/interstellar_ai
Merge branch 'main' into main
This commit is contained in:
commit
3d42572120
8 changed files with 58 additions and 41 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue