interstellar_ai/app/backend/threads/PostWorker.js

29 lines
873 B
JavaScript
Raw Normal View History

2024-09-23 11:11:45 +02:00
import axios from "axios";
onmessage = (e) => {
2024-09-23 14:54:13 +02:00
const { messages = [{ role: "assistant", content: "Hello! How can I help you?" }], ai_model = "phi3.5", access_token } = e.data
2024-09-24 10:58:14 +02:00
messages.unshift({ role: "system", content: "You are a Helpful assistant. you give short answers" })
2024-09-23 14:54:13 +02:00
const Message = {
2024-09-23 16:34:55 +02:00
messages: messages,
2024-09-23 14:54:13 +02:00
ai_model: "phi3.5",
2024-09-24 16:42:36 +02:00
model_type: "local",
access_token: access_token
2024-09-23 14:54:13 +02:00
}
2024-09-23 16:34:55 +02:00
console.log(Message);
2024-09-24 16:42:36 +02:00
axios.post("http://localhost:5000/interstellar_ai/api/ai_send", Message)
2024-09-23 11:11:45 +02:00
.then(response => {
const status = response.data.status
2024-09-23 14:54:13 +02:00
console.log(status);
postMessage({ status })
console.log('message posted');
2024-09-24 16:42:36 +02:00
2024-09-23 11:11:45 +02:00
})
.catch(error => {
console.log("Error calling API:", error)
2024-09-24 16:42:36 +02:00
postMessage({ status: 500 })
})
2024-09-23 11:11:45 +02:00
}