Only 1 msg at a time
This commit is contained in:
parent
b034292e64
commit
b4713ea3b2
1 changed files with 13 additions and 6 deletions
|
@ -3,7 +3,9 @@ import React, { useEffect, useRef, useState } from "react";
|
|||
import ConversationFrontend from "../components/ConversationFrontend";
|
||||
import InputFrontend from "../components/InputFrontend";
|
||||
import axios from "axios";
|
||||
import { log } from 'console';
|
||||
|
||||
|
||||
let sendable = true
|
||||
|
||||
const InputOutputBackend: React.FC = () => {
|
||||
type Message = {
|
||||
|
@ -37,8 +39,10 @@ const InputOutputBackend: React.FC = () => {
|
|||
postWorkerRef.current.onmessage = (event) => {
|
||||
const status = event.data.status
|
||||
if (status == 200) {
|
||||
sendable = true
|
||||
endGetWorker()
|
||||
} else if (status == 500) {
|
||||
sendable = true
|
||||
if (getWorkerRef.current) {
|
||||
addMessage("assistant", "There was an Error with the AI response")
|
||||
getWorkerRef.current.postMessage("terminate")
|
||||
|
@ -109,11 +113,14 @@ const InputOutputBackend: React.FC = () => {
|
|||
setMessages(previous => [...previous,{role,content}])
|
||||
}
|
||||
const handleSendClick = (inputValue: string) => {
|
||||
if (postWorkerRef.current) {
|
||||
addMessage("user", inputValue)
|
||||
console.log("input:",inputValue);
|
||||
postWorkerRef.current.postMessage({messages:[...messages, { role: "user", content: inputValue }], ai_model:"phi3.5", access_token:accessToken})
|
||||
startGetWorker()
|
||||
if (sendable) {
|
||||
sendable=false
|
||||
if (postWorkerRef.current) {
|
||||
addMessage("user", inputValue)
|
||||
console.log("input:",inputValue);
|
||||
postWorkerRef.current.postMessage({messages:[...messages, { role: "user", content: inputValue }], ai_model:"phi3.5", access_token:accessToken})
|
||||
startGetWorker()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue