forked from React-Group/interstellar_ai
delete logs and fix hydration error
This commit is contained in:
parent
4ed2756b9a
commit
891dabcabf
10 changed files with 37 additions and 70 deletions
|
@ -4,7 +4,7 @@ import ConversationFrontend from '../components/ConversationFrontend';
|
|||
import InputFrontend from "../components/InputFrontend";
|
||||
import { sendToVoiceRecognition } from "./voice_backend"
|
||||
import axios from "axios";
|
||||
import { useChatHistory } from '../hooks/useChatHistory';
|
||||
import { updateMessage, useChatHistory } from '../hooks/useChatHistory';
|
||||
import { getWeather } from "./weather";
|
||||
import { changeHistory, getHistory } from "./database";
|
||||
|
||||
|
@ -16,7 +16,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
}
|
||||
|
||||
// Define state variables for user preferences and messages
|
||||
const [chatHistory, setSelectedIndex, setChatHistory, updateMessage] = useChatHistory()
|
||||
const [chatHistory, setChatHistory] = useChatHistory()
|
||||
const [preferredCurrency, setPreferredCurrency] = useState<string>("USD");
|
||||
const [preferredLanguage, setPreferredLanguage] = useState<string>("english");
|
||||
const [timeFormat, setTimeFormat] = useState<string>("24-hour");
|
||||
|
@ -36,7 +36,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
apiURL.hostname = "localhost"
|
||||
}
|
||||
|
||||
console.log(setSelectedIndex)
|
||||
//#region useEffect
|
||||
useEffect(() => {
|
||||
setMessages(chatHistory.chats[chatHistory.selectedIndex].messages)
|
||||
|
@ -44,10 +43,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
|
||||
|
||||
useEffect(() => {
|
||||
console.log("History", chatHistory);
|
||||
console.log("Messages", messages);
|
||||
|
||||
|
||||
// Get the current chat's messages
|
||||
const currentMessages = chatHistory.chats[chatHistory.selectedIndex].messages || [];
|
||||
|
||||
|
@ -58,7 +53,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
// When creating a new chat and no messages exist yet, set default messages
|
||||
addMessage("system", systemMessage)
|
||||
addMessage("assistant", "Hello! How can I help you?")
|
||||
console.log(systemMessage)
|
||||
}
|
||||
}, [chatHistory, chatHistory.selectedIndex, systemMessage]);
|
||||
|
||||
|
@ -82,14 +76,12 @@ const InputOutputBackend: React.FC = () => {
|
|||
const password = localStorage.getItem("accountPassword")
|
||||
if (username && password && chatHistoryTriggered) {
|
||||
changeHistory(username, password, chatHistory)
|
||||
console.log("changed history in backend")
|
||||
}
|
||||
}, [chatHistory])
|
||||
|
||||
//#region functions
|
||||
const getWeatherHere = async () => {
|
||||
setWeatherData(await getWeather({ "unit_type": preferredMeasurement, "city": localStorage.getItem("weatherInfo") || "New York" }))
|
||||
console.log("Got the Data!")
|
||||
setWeatherTriggered(true)
|
||||
}
|
||||
|
||||
|
@ -100,15 +92,12 @@ const InputOutputBackend: React.FC = () => {
|
|||
const tempChatHistory = await getHistory(username, password)
|
||||
if (tempChatHistory && typeof tempChatHistory == "object") {
|
||||
setChatHistory(tempChatHistory)
|
||||
console.log("got history from backend")
|
||||
}
|
||||
}
|
||||
setChatHistoryTriggered(true)
|
||||
}
|
||||
//#region system-prompt
|
||||
useEffect(() => {
|
||||
console.log("creating system prompt")
|
||||
console.log(weatherData)
|
||||
|
||||
const measurementString = (preferredMeasurement == "Metric")
|
||||
? "All measurements follow the metric system. Refuse to use any other measurement system."
|
||||
|
@ -124,14 +113,12 @@ const InputOutputBackend: React.FC = () => {
|
|||
These are the currently newest Weather infos for the region. Only for the case when the user asks about anything weather related,
|
||||
you can use the following data to help the user: ${weatherData}. If there is nothing there say there is no data`
|
||||
: `You are a helpful assistant.`;
|
||||
console.log(newSystemMessage)
|
||||
setSystemMessage(newSystemMessage)
|
||||
}, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean, weatherTriggered]);
|
||||
|
||||
useEffect(() => {
|
||||
const messageIndex = 0 // system prompt is the first so index 0
|
||||
updateMessage(messageIndex, systemMessage)
|
||||
console.log(messages)
|
||||
}, [systemMessage])
|
||||
|
||||
//#region more variables and functions
|
||||
|
@ -208,7 +195,6 @@ const InputOutputBackend: React.FC = () => {
|
|||
if (event.data == "error") {
|
||||
console.log("Error getting ai message.")
|
||||
} else {
|
||||
console.log("Received data:", data);
|
||||
editLastMessage(data.response)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@ const fetchData = () => {
|
|||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken);
|
||||
apiURL.hostname = windownameGlobal; // Set the hostname
|
||||
|
||||
console.log(apiURL.href); // Log the constructed URL
|
||||
|
||||
axios.get(apiURL.href)
|
||||
.then(response => {
|
||||
postMessage(response.data); // Send data back on success
|
||||
|
|
|
@ -14,10 +14,8 @@ onmessage = (e) => {
|
|||
};
|
||||
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send");
|
||||
console.log(windowname); // Log the window name
|
||||
apiURL.hostname = windowname; // Set the hostname for the API request
|
||||
|
||||
console.log(apiURL.href); // Log the constructed API URL
|
||||
|
||||
// Make a POST request to the API with the message object
|
||||
axios.post(apiURL.href, Message)
|
||||
|
|
|
@ -18,7 +18,6 @@ export const getWeather = async (data: object): Promise<string> => {
|
|||
|
||||
// Send the status and success response back to the worker
|
||||
postMessage({ status, success });
|
||||
console.log(JSON.stringify(success)); // Log the successful response for debugging
|
||||
return JSON.stringify(success); // Return the weather data as a JSON string
|
||||
} catch (error) {
|
||||
// Handle any errors that occur during the request
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue