Skip to content

Commit

Permalink
disable input while streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashacker committed Nov 13, 2023
1 parent 5503d79 commit 2f08172
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions frontend/components/ChatComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ChatComponentProps {
onUserMessageSubmit: Message[];
isFetching: boolean;
setHandleGenerateStreamMessageRef: (ref: React.MutableRefObject<Function | null>) => void;
setIsFetching: (isFetching: boolean) => void;
apiHost: string;
}

Expand All @@ -26,6 +27,7 @@ export function ChatComponent({
isFetching,
setHandleGenerateStreamMessageRef,
apiHost,
setIsFetching,
}: ChatComponentProps) {
const [messageHistory, setMessageHistory] = useState<Message[]>([]);
const lastMessageRef = useRef<null | HTMLDivElement>(null);
Expand Down Expand Up @@ -90,6 +92,7 @@ export function ChatComponent({
setPreviewMessage(prev => prev + newMessageContent);

if (data.finish_reason === "stop") {
setIsFetching(false);
const full_text = data.full_text
if (data.cached) {
const distance = data.distance
Expand Down
3 changes: 2 additions & 1 deletion frontend/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ export default function Home() {
if (queryData.context != "") {
if (streamable) {
handleGenerateStreamMessage(sendInput, queryData.context)
setIsFetching(false)
} else {
handleGenerateMessage(sendInput, queryData.context)
}
Expand Down Expand Up @@ -412,6 +411,7 @@ export default function Home() {
isFetching={isFetching}
apiHost={getApiHostNoHttp()}
setHandleGenerateStreamMessageRef={setHandleGenerateStreamMessage}
setIsFetching={setIsFetching}
/>

{/* Input area */}
Expand All @@ -423,6 +423,7 @@ export default function Home() {
type="text"
value={userInput}
onChange={handleInputChange}
disabled={isFetching}
placeholder="What is a vector database?"
className="w-full p-2 rounded-md bg-white text-gray-900 placeholder-gray-400"
/>
Expand Down

0 comments on commit 2f08172

Please sign in to comment.