Refactoring
This commit is contained in:
commit
ae4034bb98
8 changed files with 15 additions and 42 deletions
|
@ -3,9 +3,8 @@ import React, { use, useEffect, useRef, useState } from "react";
|
|||
import ConversationFrontend from "../components/ConversationFrontend";
|
||||
import InputFrontend from "../components/InputFrontend";
|
||||
import { sendToVoiceRecognition } from "./voice_backend"
|
||||
import { AudioRecorder } from "./AudioRecorder";
|
||||
import axios from "axios";
|
||||
import { resolve } from "path";
|
||||
import { resolve } from "path";
|
||||
import { FFmpeg } from "@ffmpeg/ffmpeg";
|
||||
import { fetchFile, toBlobURL } from "@ffmpeg/util"
|
||||
|
||||
|
@ -67,10 +66,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
const mediaRecorderRef = useRef<MediaRecorder | null>(null)
|
||||
const audioChunks = useRef<Blob[]>([])
|
||||
|
||||
|
||||
console.log(messages);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
getNewToken()
|
||||
|
||||
|
@ -103,11 +98,9 @@ const InputOutputBackend: React.FC = () => {
|
|||
}, [])
|
||||
|
||||
const getNewToken = () => {
|
||||
console.log("getting access");
|
||||
axios.get("http://localhost:5000/interstellar_ai/api/ai_create")
|
||||
.then(response => {
|
||||
setAccessToken(response.data.access_token)
|
||||
console.log(response.data.access_token);
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("error:", error.message);
|
||||
|
@ -144,7 +137,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
getWorkerRef.current.postMessage({ action: "terminate" })
|
||||
getWorkerRef.current.terminate()
|
||||
getWorkerRef.current = null
|
||||
console.log(messages);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +166,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
setInputDisabled(true)
|
||||
if (postWorkerRef.current) {
|
||||
addMessage("user", inputValue)
|
||||
console.log("input:", inputValue);
|
||||
const type = localStorage.getItem('type')
|
||||
var api_key: string = ""
|
||||
if (type != null && type != 'local') {
|
||||
|
@ -209,7 +200,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
audioChunks.current = [];
|
||||
|
||||
const text_voice = await sendToVoiceRecognition(audioBlob);
|
||||
console.log(text_voice);
|
||||
resolve(text_voice); // Resolve the promise with the recognized text
|
||||
};
|
||||
});
|
||||
|
@ -230,7 +220,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
if (!isRecording) {
|
||||
const recognizedText = await startRecording();
|
||||
setInputMessage(recognizedText); // Set the recognized text after recording
|
||||
console.log("Set!")
|
||||
} else {
|
||||
stopRecording();
|
||||
}
|
||||
|
@ -247,8 +236,9 @@ const InputOutputBackend: React.FC = () => {
|
|||
}
|
||||
|
||||
const handleEditClick = () => {
|
||||
setInputMessage(messages[messages.length - 2]['content'])
|
||||
const updatedMessages = messages.slice(0, -2)
|
||||
let newestMessage = messages[messages.length - 2].content
|
||||
setInputMessage(newestMessage)
|
||||
const updatedMessages = messages.slice(0, messages.length-2)
|
||||
setMessages(updatedMessages)
|
||||
endGetWorker()
|
||||
getNewToken()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue