From e34b99982015355e1d86d422dba425b4806782a3 Mon Sep 17 00:00:00 2001 From: Prince Baghel Date: Wed, 1 May 2024 12:07:14 +0530 Subject: [PATCH 1/4] fix; chat complete --- src/app/api/patentsearch/route.ts | 1 - src/components/chat.tsx | 18 +----------------- src/components/chatcard.tsx | 1 - src/components/chatmessagecombinator.tsx | 12 +----------- src/components/inputBar.tsx | 16 ++-------------- src/components/room.tsx | 3 --- 6 files changed, 4 insertions(+), 47 deletions(-) diff --git a/src/app/api/patentsearch/route.ts b/src/app/api/patentsearch/route.ts index d0ea241e..95fa8c30 100644 --- a/src/app/api/patentsearch/route.ts +++ b/src/app/api/patentsearch/route.ts @@ -27,7 +27,6 @@ export async function POST(request: Request) { console.log("chatId", chatId); console.log("lastMessageIndex", lastMessageIndex); - // console.log("messages", msgs) const query = msgs.map((msg) => msg.content).join(" "); console.log("query", query); diff --git a/src/components/chat.tsx b/src/components/chat.tsx index d6781465..a940d291 100644 --- a/src/components/chat.tsx +++ b/src/components/chat.tsx @@ -3,7 +3,6 @@ import { useState, useEffect, useCallback, useRef } from "react"; import { AIType, ChatType } from "@/lib/types"; import InputBar from "@/components/inputBar"; import { Message, useChat } from "ai/react"; -import Startnewchatbutton from "@/components/startnewchatbutton"; import ChatMessageCombinator from "@/components/chatmessagecombinator"; import { useMutation, useQuery } from "@tanstack/react-query"; import axios from "axios"; @@ -41,7 +40,6 @@ export default function Chat(props: ChatProps) { onClickOpenChatSheet, } = useImageState(); const [choosenAI, setChoosenAI] = useState("universal"); - const [isChatCompleted, setIsChatCompleted] = useState(false); const [calculatedMessages, setCalculatedMessages] = useState([]); // const { presenceData, updateStatus } = usePresence(`channel_${props.chatId}`); const [dropZoneActive, setDropzoneActive] = useState(false); @@ -143,8 +141,7 @@ export default function Chat(props: ChatProps) { chattype: props.type, }, onError: (error) => { - console.log("got the error", error); - setIsChatCompleted(true); + console.log("got the error from api", error); }, onResponse(response) { console.log("got the response", response); @@ -154,7 +151,6 @@ export default function Chat(props: ChatProps) { }, sendExtraMessageFields: true, }); - console.log("messages", messages); useEffect(() => { let mainArray: Message[][] = []; @@ -270,8 +266,6 @@ export default function Chat(props: ChatProps) { setMessages={setMessages} chatTitle={props.chatTitle} imageUrl={props.imageUrl} - isChatCompleted={isChatCompleted} - setIsChatCompleted={setIsChatCompleted} append={append} isLoading={isLoading} shouldShowConfidentialToggler={userIds.includes(props.uid)} @@ -304,15 +298,6 @@ export default function Chat(props: ChatProps) { ) : null} - - {isChatCompleted && ( -
- -
- )} diff --git a/src/components/chatcard.tsx b/src/components/chatcard.tsx index 3448c3c9..2a43369a 100644 --- a/src/components/chatcard.tsx +++ b/src/components/chatcard.tsx @@ -44,7 +44,6 @@ const Chatcard = ({ chat, uid, org_id, org_slug, priority, type }: Props) => { const chatlog = JSON.parse(chat.messages as string) as ChatLog; console.log("chatlog", chatlog.log); const msgs = chatlog.log as ChatEntry[]; - console.log("messages", msgs); const chats = msgs.slice(0, 2); const res = await fetch(`/api/generateTitle/${chat.id}/${org_id}`, { method: "POST", diff --git a/src/components/chatmessagecombinator.tsx b/src/components/chatmessagecombinator.tsx index a89f8af5..94e3a527 100644 --- a/src/components/chatmessagecombinator.tsx +++ b/src/components/chatmessagecombinator.tsx @@ -1,8 +1,7 @@ -import React, { SetStateAction, useEffect, useRef } from "react"; +import React, { useEffect, useRef } from "react"; import Image from "next/image"; import { ContextWrapper } from "@/components/contextwrapper"; import { ChatRequestOptions, CreateMessage, Message } from "ai"; -import { CHAT_COMPLETION_CONTENT } from "@/lib/types"; import ChatMessage from "@/components/chatmessage"; import { cn } from "@/lib/utils"; import { Button } from "@/components/button"; @@ -24,8 +23,6 @@ type Props = { chatTitle: string; imageUrl: string; setMessages: (messages: Message[]) => void; - isChatCompleted: boolean; - setIsChatCompleted: React.Dispatch>; append: ( message: Message | CreateMessage, chatRequestOptions?: ChatRequestOptions | undefined, @@ -42,8 +39,6 @@ const ChatMessageCombinator = ({ calculatedMessages, messages, name, - isChatCompleted, - setIsChatCompleted, append, setMessages, chatId, @@ -201,11 +196,6 @@ const ChatMessageCombinator = ({ )} > {msgs.map((msg, idx) => { - if (index === messages.length - 1 && !isChatCompleted) { - if (messages[index].content === CHAT_COMPLETION_CONTENT) { - setIsChatCompleted(true); - } - } messageIndex++; const msgIdx = messageIndex; if (msg.subRole === "patent-search") return null; diff --git a/src/components/inputBar.tsx b/src/components/inputBar.tsx index b90fe2e5..4fb293bf 100644 --- a/src/components/inputBar.tsx +++ b/src/components/inputBar.tsx @@ -75,7 +75,6 @@ interface InputBarProps { chatRequestOptions?: ChatRequestOptions | undefined, ) => Promise; setInput: Dispatch>; - isChatCompleted: boolean; chatId: string; messages: Message[]; orgId: string; @@ -498,7 +497,6 @@ const InputBar = (props: InputBarProps) => { > {/* { )} { ) ) : null diff --git a/src/components/patentdata.tsx b/src/components/patentdata.tsx index 3bbcca89..f31fec56 100644 --- a/src/components/patentdata.tsx +++ b/src/components/patentdata.tsx @@ -42,7 +42,6 @@ const PatentData = ({ "item", parseAsInteger, ); - console.log(parsedInput); const [open, setOpen] = React.useState( isOpen && dialogIndex === dialogNumber ? isOpen : false, ); diff --git a/src/components/search.tsx b/src/components/search.tsx index 27f81399..234fa869 100644 --- a/src/components/search.tsx +++ b/src/components/search.tsx @@ -62,16 +62,14 @@ const Search = (props: Props) => { filters: `orgSlug: "${props.orgSlug}"`, }) .then((response) => { - console.log(response); return setResults(response.hits); }); - }, [throttledValue]); + }, [throttledValue, props?.orgSlug]); return ( { - console.log("got the input value"); setValue(val); }} value={value} From 0514f93cc007ed2e963398b046039a185d3022c7 Mon Sep 17 00:00:00 2001 From: Prince Baghel Date: Thu, 2 May 2024 10:57:19 +0530 Subject: [PATCH 4/4] chore: back to annoying scroll again --- src/components/chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/chat.tsx b/src/components/chat.tsx index 2171708a..a940d291 100644 --- a/src/components/chat.tsx +++ b/src/components/chat.tsx @@ -322,7 +322,7 @@ export default function Chat(props: ChatProps) { )}
- {/* {scrollToBottom()} */} + {scrollToBottom()}
); }