ai works again?
This commit is contained in:
parent
44cd249421
commit
f9d3a1f235
2 changed files with 20 additions and 29 deletions
|
@ -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)
|
||||
console.log("added User Message")
|
||||
|
||||
HandlePostRequest([...messages, { role: "user", content: message }], "phi3.5", system);
|
||||
};
|
||||
|
||||
const [messages, setMessages] = useState([
|
||||
|
@ -66,20 +65,11 @@ 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) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue