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
switch (functionName) {
case "getAccess":
axios.get('http://localhost:5000/interstellar/api/ai_create')
.then(Response => {
postMessage(Response.data.access_token)
}).catch(error => {
console.error("Error with GET Token request:", error)
})
break
case "postRequest":
const data = {
ai_model: ai_model,
message: message,
system_prompt: system_prompt,
access_token: access_token
};
axios.post('http://localhost:5000/interstellar/api/ai_send', data)
.then(Response => {
postMessage(Response.data)
}).catch(error => {
console.error("Error:", error)
})
break
case "getResponse":
axios.get('http://localhost:5000/interstellar/api/ai_get')
.then(Response => {
postMessage(Response.data.response)
}).catch(error => {
console.error("Error with GET response request:", error)
})
break
}
}