ai works again?

This commit is contained in:
YasinOnm08 2024-09-20 09:58:13 +02:00
parent 44cd249421
commit f9d3a1f235
2 changed files with 20 additions and 29 deletions

View file

@ -31,15 +31,14 @@ const InputOutputBackend: React.FC = () => {
role: string role: string
content: string content: string
} }
type SystemPrompt = {
}
const handleSendClick = (message:string) => { const handleSendClick = (message:string) => {
var system:Message = {role:"system" ,content:"You are a helpful assistant that gives short answers."} var system:Message = {role:"system" ,content:"You are a helpful assistant."}
addMessage("user",message); addMessage("user", message);
HandlePostRequest(messages, "phi3.5", system) console.log("added User Message")
HandlePostRequest([...messages, { role: "user", content: message }], "phi3.5", system);
}; };
const [messages, setMessages] = useState([ const [messages, setMessages] = useState([
@ -65,21 +64,12 @@ const InputOutputBackend: React.FC = () => {
} }
} }
},[]) },[])
const HandleGetRequest = (messages: Message[], ai_model: string, system_prompt: Message) => { const HandlePostRequest = (messages: Message[], ai_model: string, system_prompt: Message) => {
if (workerRef.current) { if (workerRef.current) {
workerRef.current.postMessage({ functionName: "getResponse", access_token: accessToken, messages: messages, ai_model: ai_model, system_prompt: system_prompt })
workerRef.current.onmessage = (e) => {
addMessage("assistant",e.data)
}
}
}
const HandlePostRequest = (messages: Message[], ai_model: string, system_prompt: Message) => {
if (workerRef.current) {
workerRef.current.postMessage({ functionName: "postRequest", access_token: accessToken, messages: messages, ai_model: ai_model, system_prompt: system_prompt }) workerRef.current.postMessage({ functionName: "postRequest", access_token: accessToken, messages: messages, ai_model: ai_model, system_prompt: system_prompt })
workerRef.current.onmessage = (e) => { workerRef.current.onmessage = (e) => {
HandleGetRequest(messages,ai_model,system_prompt) addMessage("assistant",e.data)
} }
} }
} }

View file

@ -4,12 +4,21 @@ import { type } from 'os';
onmessage = function (e) { onmessage = function (e) {
const { functionName = "getAccess", access_token = "", messages = [], ai_model = "phi3.5", system_prompt = {role:"system" ,content: "You are a helpful assistant that gives short answers"}} = e.data const { functionName = "getAccess", access_token = "", messages = [], ai_model = "phi3.5", system_prompt = {role:"system" ,content: "You are a helpful assistant that gives short answers"}} = e.data
let data = { let data = {
ai_model: ai_model, ai_model: ai_model,
messages: messages, messages: messages,
access_token: access_token access_token: access_token
}; };
const getResponse = () => {
axios.get('https://localhost: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)
})
}
switch (functionName) { switch (functionName) {
case "getAccess": case "getAccess":
console.log("getting access...") console.log("getting access...")
@ -26,19 +35,11 @@ onmessage = function (e) {
console.log(messages) console.log(messages)
axios.post('https://localhost:5000/interstellar/api/ai_send', data) axios.post('https://localhost:5000/interstellar/api/ai_send', data)
.then(Response => { .then(Response => {
postMessage(Response.data) getResponse()
}).catch(error => { }).catch(error => {
console.error("Error:", error) console.error("Error:", error)
}) })
break break
case "getResponse":
axios.get('https://localhost: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)
})
break
} }