Compare commits

...

14 commits

Author SHA1 Message Date
dbcf1f7d0c Merge pull request 'main' (#36) from React-Group/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/sageTheDm/interstellar_ai/pulls/36
2024-10-03 16:16:34 +02:00
Patrick_Pluto
c56c3c802d Merge branch 'sageTheDm-main' 2024-10-03 16:15:15 +02:00
Patrick_Pluto
091744d75b typescriptified and also removed hardcoded addresses 2024-10-03 14:10:21 +02:00
Patrick_Pluto
61919ad094 Merge branch 'main' of interstellardevelopment.org:React-Group/interstellar_ai 2024-10-03 13:33:24 +02:00
Patrick_Pluto
ce4dac8227 HelloWorld 2024-10-03 13:33:07 +02:00
d295968b10 Merge pull request 'main' (#94) from YasinOnm08/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/interstellar_ai/pulls/94
2024-10-03 13:33:00 +02:00
9373fa8e59 lol 2024-10-03 13:32:27 +02:00
82fe1285bf Merge branch 'main' of interstellardevelopment.org:YasinOnm08/interstellar_ai 2024-10-03 13:17:06 +02:00
0c952ec06e Merge pull request 'main' (#43) from React-Group/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/YasinOnm08/interstellar_ai/pulls/43
2024-10-03 13:16:59 +02:00
014658cfcb Merge branch 'main' of interstellardevelopment.org:YasinOnm08/interstellar_ai 2024-10-02 14:17:37 +02:00
ca07cfebd4 Merge pull request 'history backend tweaks' (#42) from React-Group/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/YasinOnm08/interstellar_ai/pulls/42
2024-10-02 14:17:31 +02:00
9f70227082 Merge branch 'main' of interstellardevelopment.org:YasinOnm08/interstellar_ai 2024-10-02 14:05:16 +02:00
20f7251f77 Merge pull request 'main' (#41) from React-Group/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/YasinOnm08/interstellar_ai/pulls/41
2024-10-02 14:05:13 +02:00
5f8a18878d settings button visual fix 2024-10-02 14:05:06 +02:00
8 changed files with 149 additions and 125 deletions

View file

@ -6,7 +6,7 @@ type ChatMessage = {
let chatHistory: ChatMessage[] = [];
function addMessageHistory(name: string, message: any): void {
function addMessageToHistory(name: string, message: any): void {
const newMessage: ChatMessage = {
name: name,
messages: message,
@ -16,7 +16,7 @@ function addMessageHistory(name: string, message: any): void {
console.log(`Added message from ${name}: ${message}`);
}
function removeMessageHistory(timestamp: number): void {
function removeMessageFromHistory(timestamp: number): void {
const index = chatHistory.findIndex((msg) => msg.timestamp === timestamp);
if (index > -1) {
chatHistory.splice(index, 1);

View file

@ -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(() => {
@ -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()
}
}

View file

@ -18,9 +18,12 @@ 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.
*/
const apiURL = new URL("http://localhost:5000/interstellar_ai/db")
apiURL.hostname = window.location.hostname;
export const sendToDatabase = async (data: any): Promise<boolean> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const response = await axios.post(apiURL.href, data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });
@ -33,7 +36,7 @@ export const sendToDatabase = async (data: any): Promise<boolean> => {
export const sendToDatabaseAndGetString = async (data: any): Promise<string> => {
try {
const response = await axios.post("http://localhost:5000/interstellar_ai/db", data);
const response = await axios.post(apiURL.href, data);
const status = response.data.status;
const success = response.data.response;
postMessage({ status, success });

View file

@ -1,10 +1,14 @@
import axios from "axios";
let accesstoken
let windownameGlobal = ""
let accesstoken = ""
onmessage = (event) => {
const { action, access_token } = event.data
const { action, access_token, windowname } = event.data
accesstoken = access_token
windownameGlobal = windowname
if (action === "start") {
fetchData()
} else if (action === "terminate") {
@ -14,9 +18,12 @@ onmessage = (event) => {
const fetchData = () => {
const apiURL = "http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_get?access_token=" + accesstoken)
apiURL.hostname = windownameGlobal;
axios.get(apiURL)
console.log(apiURL.href)
axios.get(apiURL.href)
.then(response => {
const data = response.data
postMessage(data)

View file

@ -1,7 +1,7 @@
import axios from "axios";
onmessage = (e) => {
const { messages, ai_model, model_type, access_token, api_key } = e.data
const { messages, ai_model, model_type, access_token, api_key, windowname } = e.data
const Message = {
@ -12,7 +12,13 @@ onmessage = (e) => {
api_key: api_key
}
axios.post("http://localhost:5000/interstellar_ai/api/ai_send", Message)
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/ai_send")
console.log(windowname)
apiURL.hostname = windowname;
console.log(apiURL.href)
axios.post(apiURL.href, Message)
.then(response => {
const status = response.data.status
postMessage({ status })

View file

@ -5,7 +5,10 @@ export const sendToVoiceRecognition = (audio_data: Blob): Promise<string> => {
const formdata = new FormData()
formdata.append("audio", audio_data)
return axios.post("http://localhost:5000/interstellar_ai/api/voice_recognition", formdata)
const apiURL = new URL("http://localhost:5000/interstellar_ai/api/voice_recognition")
apiURL.hostname = window.location.hostname;
return axios.post(apiURL.href, formdata)
.then((response) => {
return response.data.response
})

View file

@ -84,9 +84,9 @@ header{
.header-login-button{
height: 100%;
width:4vw;
width:max-content;
font-size: var(--font-size);
padding: 3px;
padding: 0.5vw 1vw;
background-color: var(--input-button-color);
color: var(--text-color);
border: none;