forked from React-Group/interstellar_ai
typescriptified and also removed hardcoded addresses
This commit is contained in:
parent
61919ad094
commit
091744d75b
5 changed files with 42 additions and 18 deletions
|
@ -15,7 +15,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
content: string
|
||||
}
|
||||
|
||||
// Define state variables for user preferences and messages
|
||||
// Define state variables for user preferences and messages
|
||||
const [preferredCurrency, setPreferredCurrency] = useState<string>("USD");
|
||||
const [preferredLanguage, setPreferredLanguage] = useState<string>("english");
|
||||
const [timeFormat, setTimeFormat] = useState<string>("24-hour");
|
||||
|
@ -24,6 +24,8 @@ const InputOutputBackend: React.FC = () => {
|
|||
const [dateFormat, setDateFormat] = useState<string>("DD-MM-YYYY");
|
||||
const [messages, setMessages] = useState<Message[]>([]);
|
||||
const [myBoolean, setMyBoolean] = useState<boolean>(() => localStorage.getItem('myBoolean') === 'true') || false;
|
||||
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_create")
|
||||
apiURL.hostname = window.location.hostname;
|
||||
|
||||
// Fetch local storage values and update state on component mount
|
||||
useEffect(() => {
|
||||
|
@ -55,7 +57,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
{ role: "assistant", content: "Hello! How may I help you?" },
|
||||
]);
|
||||
}, [preferredCurrency, preferredLanguage, timeFormat, preferredMeasurement, timeZone, dateFormat, myBoolean]);
|
||||
|
||||
|
||||
|
||||
const conversationRef = useRef<HTMLDivElement>(null)
|
||||
const [copyClicked, setCopyClicked] = useState(false)
|
||||
|
@ -72,7 +74,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
useEffect(() => {
|
||||
getNewToken()
|
||||
|
||||
postWorkerRef.current = new Worker(new URL("./threads/PostWorker.js", import.meta.url))
|
||||
postWorkerRef.current = new Worker(new URL("./threads/PostWorker.ts", import.meta.url))
|
||||
|
||||
postWorkerRef.current.onmessage = (event) => {
|
||||
const status = event.data.status
|
||||
|
@ -101,7 +103,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
}, [])
|
||||
|
||||
const getNewToken = () => {
|
||||
axios.get("http://localhost:5000/interstellar_ai/api/ai_create")
|
||||
axios.get(apiURL.href)
|
||||
.then(response => {
|
||||
setAccessToken(response.data.access_token)
|
||||
})
|
||||
|
@ -113,9 +115,11 @@ const InputOutputBackend: React.FC = () => {
|
|||
|
||||
const startGetWorker = () => {
|
||||
if (!getWorkerRef.current) {
|
||||
getWorkerRef.current = new Worker(new URL("./threads/GetWorker.js", import.meta.url))
|
||||
getWorkerRef.current = new Worker(new URL("./threads/GetWorker.ts", import.meta.url))
|
||||
|
||||
getWorkerRef.current.postMessage({ action: "start", access_token: accessToken })
|
||||
const windowname = window.location.hostname
|
||||
|
||||
getWorkerRef.current.postMessage({ action: "start", access_token: accessToken, windowname })
|
||||
|
||||
addMessage("assistant", "")
|
||||
getWorkerRef.current.onmessage = (event) => {
|
||||
|
@ -178,7 +182,8 @@ const InputOutputBackend: React.FC = () => {
|
|||
}
|
||||
}
|
||||
setInputMessage("")
|
||||
postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key })
|
||||
const windowname = window.location.hostname
|
||||
postWorkerRef.current.postMessage({ messages: [...messages, { role: "user", content: inputValue }], ai_model: "llama3.2", model_type: type, access_token: accessToken, api_key: api_key, windowname })
|
||||
startGetWorker()
|
||||
}
|
||||
}
|
||||
|
@ -228,7 +233,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
}
|
||||
};
|
||||
|
||||
const handleStopClick = () => {
|
||||
const handleStopClick = () => {
|
||||
endGetWorker()
|
||||
getNewToken()
|
||||
}
|
||||
|
@ -246,7 +251,7 @@ const InputOutputBackend: React.FC = () => {
|
|||
const handleEditClick = () => {
|
||||
let newestMessage = messages[messages.length - 2].content
|
||||
setInputMessage(newestMessage)
|
||||
const updatedMessages = messages.slice(0, messages.length-2)
|
||||
const updatedMessages = messages.slice(0, messages.length - 2)
|
||||
setMessages(updatedMessages)
|
||||
endGetWorker()
|
||||
getNewToken()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue