Remove partially implemented reply cancellation (#2031)

* fix: remove partially implemented response cancellation

* feat: notify user when unsupported chat cancellation is requested

* fix: correct ChatInputBar streaming detection logic
This commit is contained in:
Nathan Schwerdfeger 2024-08-03 11:12:04 -07:00 committed by GitHub
parent ed455394fc
commit 52c505c210
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 36 deletions

View File

@ -207,10 +207,6 @@ export function ChatPage({
if (chatSessionIdRef.current !== null) {
setHasPerformedInitialScroll(false);
}
if (isStreaming) {
setIsCancelled(true);
}
}
async function initialSessionFetch() {
@ -451,8 +447,6 @@ export function ChatPage({
const [sharingModalVisible, setSharingModalVisible] =
useState<boolean>(false);
// state for cancelling streaming
const [isCancelled, setIsCancelled] = useState(false);
const [aboveHorizon, setAboveHorizon] = useState(false);
const scrollableDivRef = useRef<HTMLDivElement>(null);
@ -517,11 +511,6 @@ export function ChatPage({
}, 50);
};
const isCancelledRef = useRef<boolean>(isCancelled); // scroll is cancelled
useEffect(() => {
isCancelledRef.current = isCancelled;
}, [isCancelled]);
const distance = 500; // distance that should "engage" the scroll
const debounce = 100; // time for debouncing
@ -599,11 +588,6 @@ export function ChatPage({
for (const packet of packetBunch) {
stack.push(packet);
}
if (isCancelledRef.current) {
setIsCancelled(false);
break;
}
}
} catch (error) {
stack.error = String(error);
@ -635,6 +619,15 @@ export function ChatPage({
isSeededChat?: boolean;
alternativeAssistantOverride?: Persona | null;
} = {}) => {
if (isStreaming) {
setPopup({
message: "Please wait for the response to complete",
type: "error",
});
return;
}
setAlternativeGeneratingAssistant(alternativeAssistantOverride);
clientScrollToBottom();
let currChatSessionId: number;
@ -873,10 +866,6 @@ export function ChatPage({
},
]);
}
if (isCancelledRef.current) {
setIsCancelled(false);
break;
}
}
}
} catch (e: any) {
@ -1614,7 +1603,6 @@ export function ChatPage({
setMessage={setMessage}
onSubmit={onSubmit}
isStreaming={isStreaming}
setIsCancelled={setIsCancelled}
filterManager={filterManager}
llmOverrideManager={llmOverrideManager}
files={currentMessageFiles}

View File

@ -40,7 +40,6 @@ export function ChatInputBar({
setMessage,
onSubmit,
isStreaming,
setIsCancelled,
filterManager,
llmOverrideManager,
@ -68,7 +67,6 @@ export function ChatInputBar({
setMessage: (message: string) => void;
onSubmit: () => void;
isStreaming: boolean;
setIsCancelled: (value: boolean) => void;
filterManager: FilterManager;
llmOverrideManager: LlmOverrideManager;
selectedAssistant: Persona;
@ -328,7 +326,9 @@ export function ChatInputBar({
{filteredPrompts.map((currentPrompt, index) => (
<button
key={index}
className={`px-2 ${tabbingIconIndex == index && "bg-hover"} rounded content-start flex gap-x-1 py-1.5 w-full hover:bg-hover cursor-pointer`}
className={`px-2 ${
tabbingIconIndex == index && "bg-hover"
} rounded content-start flex gap-x-1 py-1.5 w-full hover:bg-hover cursor-pointer`}
onClick={() => {
updateInputPrompt(currentPrompt);
}}
@ -344,7 +344,9 @@ export function ChatInputBar({
<a
key={filteredPrompts.length}
target="_self"
className={`${tabbingIconIndex == filteredPrompts.length && "bg-hover"} px-3 flex gap-x-1 py-2 w-full items-center hover:bg-hover-light cursor-pointer"`}
className={`${
tabbingIconIndex == filteredPrompts.length && "bg-hover"
} px-3 flex gap-x-1 py-2 w-full items-center hover:bg-hover-light cursor-pointer"`}
href="/prompts"
>
<FiPlus size={17} />
@ -485,7 +487,9 @@ export function ChatInputBar({
style={{ scrollbarWidth: "thin" }}
role="textarea"
aria-multiline
placeholder={`Send a message ${!settings?.isMobile ? "or try using @ or /" : ""}`}
placeholder={`Send a message ${
!settings?.isMobile ? "or try using @ or /" : ""
}`}
value={message}
onKeyDown={(event) => {
if (
@ -493,12 +497,12 @@ export function ChatInputBar({
!showPrompts &&
!showSuggestions &&
!event.shiftKey &&
message &&
!isStreaming &&
!(event.nativeEvent as any).isComposing
) {
onSubmit();
event.preventDefault();
if (message) {
onSubmit();
}
}
}}
suppressContentEditableWarning={true}
@ -592,19 +596,17 @@ export function ChatInputBar({
<div
className="cursor-pointer"
onClick={() => {
if (!isStreaming) {
if (message) {
onSubmit();
}
} else {
setIsCancelled(true);
if (message) {
onSubmit();
}
}}
>
<SendIcon
size={28}
className={`text-emphasis text-white p-1 rounded-full ${
message ? "bg-background-800" : "bg-[#D7D7D7]"
message && !isStreaming
? "bg-background-800"
: "bg-[#D7D7D7]"
}`}
/>
</div>