interstellar_ai/app/backend/threads/PostWorker.ts

31 lines
No EOL
784 B
TypeScript

import axios from "axios";
onmessage = (e) => {
const { messages, ai_model, model_type, access_token, api_key, windowname } = e.data
const Message = {
messages: messages,
ai_model: ai_model,
model_type: model_type,
access_token: access_token,
api_key: api_key
}
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 })
})
.catch(error => {
console.log("Error calling API:", error)
postMessage({ status: 500 })
})
}