forked from React-Group/interstellar_ai
commented input output handler
This commit is contained in:
parent
157e838b01
commit
cdd4b80a43
1 changed files with 9 additions and 8 deletions
|
@ -9,7 +9,7 @@ import { getWeather } from "./weather";
|
||||||
import { changeHistory, getHistory } from "./database";
|
import { changeHistory, getHistory } from "./database";
|
||||||
|
|
||||||
const InputOutputBackend: React.FC = () => {
|
const InputOutputBackend: React.FC = () => {
|
||||||
// # variables
|
//#region variables
|
||||||
type Message = {
|
type Message = {
|
||||||
role: string
|
role: string
|
||||||
content: string
|
content: string
|
||||||
|
@ -37,7 +37,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(setSelectedIndex)
|
console.log(setSelectedIndex)
|
||||||
|
//#region useEffect
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setMessages(chatHistory.chats[chatHistory.selectedIndex].messages)
|
setMessages(chatHistory.chats[chatHistory.selectedIndex].messages)
|
||||||
}, [chatHistory.selectedIndex])
|
}, [chatHistory.selectedIndex])
|
||||||
|
@ -86,6 +86,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
}, [chatHistory])
|
}, [chatHistory])
|
||||||
|
|
||||||
|
//#region functions
|
||||||
const getWeatherHere = async () => {
|
const getWeatherHere = async () => {
|
||||||
setWeatherData(await getWeather({ "unit_type": preferredMeasurement, "city": localStorage.getItem("weatherInfo") || "New York" }))
|
setWeatherData(await getWeather({ "unit_type": preferredMeasurement, "city": localStorage.getItem("weatherInfo") || "New York" }))
|
||||||
console.log("Got the Data!")
|
console.log("Got the Data!")
|
||||||
|
@ -104,7 +105,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
setChatHistoryTriggered(true)
|
setChatHistoryTriggered(true)
|
||||||
}
|
}
|
||||||
|
//#region system-prompt
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("creating system prompt")
|
console.log("creating system prompt")
|
||||||
console.log(weatherData)
|
console.log(weatherData)
|
||||||
|
@ -133,7 +134,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
console.log(messages)
|
console.log(messages)
|
||||||
}, [systemMessage])
|
}, [systemMessage])
|
||||||
|
|
||||||
|
//#region more variables and functions
|
||||||
const conversationRef = useRef<HTMLDivElement>(null)
|
const conversationRef = useRef<HTMLDivElement>(null)
|
||||||
const [copyClicked, setCopyClicked] = useState(false)
|
const [copyClicked, setCopyClicked] = useState(false)
|
||||||
const [accessToken, setAccessToken] = useState("")
|
const [accessToken, setAccessToken] = useState("")
|
||||||
|
@ -144,7 +145,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
const [isRecording, setIsRecording] = useState(false)
|
const [isRecording, setIsRecording] = useState(false)
|
||||||
const mediaRecorderRef = useRef<MediaRecorder | null>(null)
|
const mediaRecorderRef = useRef<MediaRecorder | null>(null)
|
||||||
const audioChunks = useRef<Blob[]>([])
|
const audioChunks = useRef<Blob[]>([])
|
||||||
|
//#region chat functions
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getNewToken()
|
getNewToken()
|
||||||
|
|
||||||
|
@ -266,7 +267,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//#region speech recognition
|
||||||
const startRecording = async (): Promise<string> => {
|
const startRecording = async (): Promise<string> => {
|
||||||
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
||||||
const mediaRecorder = new MediaRecorder(stream);
|
const mediaRecorder = new MediaRecorder(stream);
|
||||||
|
@ -309,7 +310,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
stopRecording();
|
stopRecording();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//#region chat buttons
|
||||||
const handleStopClick = () => {
|
const handleStopClick = () => {
|
||||||
endGetWorker()
|
endGetWorker()
|
||||||
getNewToken()
|
getNewToken()
|
||||||
|
@ -356,7 +357,7 @@ const InputOutputBackend: React.FC = () => {
|
||||||
setCopyClicked(false)
|
setCopyClicked(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//#region The "html" return
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ConversationFrontend
|
<ConversationFrontend
|
||||||
|
|
Loading…
Reference in a new issue