interstellar_ai/app/ProcessAPI.js

39 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-09-19 13:02:56 +02:00
import axios from 'axios'
onmessage = function (e) {
const { functionName = "getAccess", access_token = "", message = "", ai_model = "phi3.5", system_prompt = "You are a helpful assistant" } = e.data
2024-09-19 15:56:26 +02:00
const data = {
"ai_model": ai_model,
"message": message,
"system_prompt": system_prompt,
"access_token": access_token
};
2024-09-19 13:02:56 +02:00
switch (functionName) {
case "getAccess":
2024-09-19 16:24:16 +02:00
axios.get('https://127.0.0.1:5000/interstellar/api/ai_create')
2024-09-19 15:56:26 +02:00
.then(Response => {
2024-09-19 16:24:16 +02:00
postMessage(Response.data.access_token)
}).catch(error => {
console.error("Error with GET Token request:", error)
})
2024-09-19 13:02:56 +02:00
break
case "postRequest":
2024-09-19 16:24:16 +02:00
axios.post('https://127.0.0.1:5000/interstellar/api/ai_send', data)
2024-09-19 13:02:56 +02:00
.then(Response => {
postMessage(Response.data)
}).catch(error => {
2024-09-19 16:24:16 +02:00
console.error("Error:", error)
2024-09-19 13:02:56 +02:00
})
break
case "getResponse":
2024-09-19 16:24:16 +02:00
axios.get('https://127.0.0.1:5000/interstellar/api/ai_get?access_token=' + access_token)
.then(Response => {
postMessage(Response.data.response)
}).catch(error => {
console.error("Error with GET response request:", error)
})
2024-09-19 13:02:56 +02:00
break
}
2024-09-19 16:24:16 +02:00
2024-09-19 13:02:56 +02:00
}