diff --git a/app/InputOutputHandler.tsx b/app/InputOutputHandler.tsx index 6f428dc..288aaa4 100644 --- a/app/InputOutputHandler.tsx +++ b/app/InputOutputHandler.tsx @@ -31,15 +31,14 @@ const InputOutputBackend: React.FC = () => { role: string content: string } - type SystemPrompt = { - - } 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); - HandlePostRequest(messages, "phi3.5", system) + addMessage("user", message); + console.log("added User Message") + + HandlePostRequest([...messages, { role: "user", content: message }], "phi3.5", system); }; const [messages, setMessages] = useState([ @@ -65,21 +64,12 @@ const InputOutputBackend: React.FC = () => { } } },[]) - - const HandleGetRequest = (messages: Message[], ai_model: string, system_prompt: Message) => { - 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) { + + 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.onmessage = (e) => { - HandleGetRequest(messages,ai_model,system_prompt) + addMessage("assistant",e.data) } } } diff --git a/app/ProcessAPI.js b/app/ProcessAPI.js index bfd94dd..a1f3a6d 100644 --- a/app/ProcessAPI.js +++ b/app/ProcessAPI.js @@ -4,12 +4,21 @@ import { type } from 'os'; 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 - let data = { ai_model: ai_model, messages: messages, 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) { case "getAccess": console.log("getting access...") @@ -26,19 +35,11 @@ onmessage = function (e) { console.log(messages) axios.post('https://localhost:5000/interstellar/api/ai_send', data) .then(Response => { - postMessage(Response.data) + getResponse() }).catch(error => { console.error("Error:", error) }) 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 }