Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bug fixes #87

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"drizzle-orm": "0.26.5",
"drizzle-orm": "0.30.9",
"drizzle-zod": "0.4.2",
"encoding": "^0.1.13",
"eslint": "8.37.0",
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/chats/[chatid]/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export async function GET(

const msg = fetchedChat[0].messages;
const chatlog = JSON.parse(msg as string) as ChatLog;
console.log("fetchedChat route", chatlog);
// console.log("fetchedChat route", chatlog);
return NextResponse.json({ chats: chatlog ? chatlog : [] });
}
8 changes: 3 additions & 5 deletions src/app/api/patentsearch/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -56,8 +55,6 @@ export async function POST(request: Request) {
chatlog.log.length,
);

console.log("prevChatData", nextChatData);

const res = await axios.get(`${baseUrl}/search/102`, {
params: {
q: query,
Expand All @@ -71,6 +68,9 @@ export async function POST(request: Request) {

console.log("data", data);

if (data?.length === 0) {
return NextResponse.json({ data: null }, { status: 404 });
}
const patentMessage = {
role: "assistant",
subRole: "patent-search",
Expand All @@ -90,7 +90,5 @@ export async function POST(request: Request) {
.where(eq(chats.id, Number(chatId)))
.run();

// console.log(data)

return NextResponse.json({ data: updatedChatLog });
}
18 changes: 1 addition & 17 deletions src/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -41,7 +40,6 @@ export default function Chat(props: ChatProps) {
onClickOpenChatSheet,
} = useImageState();
const [choosenAI, setChoosenAI] = useState<AIType>("universal");
const [isChatCompleted, setIsChatCompleted] = useState<boolean>(false);
const [calculatedMessages, setCalculatedMessages] = useState<Message[][]>([]);
// const { presenceData, updateStatus } = usePresence(`channel_${props.chatId}`);
const [dropZoneActive, setDropzoneActive] = useState<boolean>(false);
Expand Down Expand Up @@ -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);
Expand All @@ -154,7 +151,6 @@ export default function Chat(props: ChatProps) {
},
sendExtraMessageFields: true,
});
console.log("messages", messages);

useEffect(() => {
let mainArray: Message[][] = [];
Expand Down Expand Up @@ -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)}
Expand Down Expand Up @@ -304,15 +298,6 @@ export default function Chat(props: ChatProps) {
</div>
</>
) : null}

{isChatCompleted && (
<div>
<Startnewchatbutton
org_slug={props.org_slug}
org_id={props.orgId}
/>
</div>
)}
<InputBar
onClickOpenChatSheet={props.onClickOpenChatSheet}
onClickOpen={open}
Expand All @@ -331,7 +316,6 @@ export default function Chat(props: ChatProps) {
onChange={handleInputChange}
setInput={setInput}
append={append}
isChatCompleted={isChatCompleted}
isLoading={isLoading}
chattype={props.type}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/chatcard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
66 changes: 31 additions & 35 deletions src/components/chatmessagecombinator.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,8 +23,6 @@ type Props = {
chatTitle: string;
imageUrl: string;
setMessages: (messages: Message[]) => void;
isChatCompleted: boolean;
setIsChatCompleted: React.Dispatch<SetStateAction<boolean>>;
append: (
message: Message | CreateMessage,
chatRequestOptions?: ChatRequestOptions | undefined,
Expand All @@ -42,8 +39,6 @@ const ChatMessageCombinator = ({
calculatedMessages,
messages,
name,
isChatCompleted,
setIsChatCompleted,
append,
setMessages,
chatId,
Expand All @@ -65,28 +60,33 @@ const ChatMessageCombinator = ({
const queryClient = useQueryClient();
const sheetContentRef = useRef<HTMLDivElement>(null); // Specify the type as HTMLDivElement

const mutation = useMutation(
async (data: { id: string; msgs: Message[]; lastMessageIndex: number }) => {
const mutation = useMutation<
Message[] | null,
unknown,
{ msgs: Message[]; id: string; lastMessageIndex: number }
>({
mutationFn: async (data) => {
const res = await axios.post(`/api/patentsearch`, {
msgs: data.msgs,
orgId: orgId,
chatId: chatId,
lastMessageIndex: data.lastMessageIndex,
});
const result = res.data;
console.log("patentresult", result);
console.log("patentresult", res.data);
return res.data;
},
{
onSuccess: () => {
// Invalidate and refetch
queryClient.invalidateQueries(["chats", chatId]);
},
onSuccess: (data, variables) => {
if (!data) {
console.log("no patients found");
}
queryClient.invalidateQueries({ queryKey: ["chats", chatId] });
},
);
onError: (_error: any) => {},
});

const titleSplit = chatTitle.replaceAll('"', "").split(":");
const chat_title = titleSplit[0];
const chat_sub_title = titleSplit.length > 1 ? titleSplit[1] : "";
const titleSplit = chatTitle?.replaceAll('"', "").split(":");
const chat_title = titleSplit?.[0];
const chat_sub_title = titleSplit?.length > 1 ? titleSplit?.[1] : "";
const scrollToBottom = () => {
if (sheetContentRef.current) {
sheetContentRef.current.scrollIntoView({ behavior: "smooth" });
Expand Down Expand Up @@ -201,11 +201,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;
Expand Down Expand Up @@ -246,6 +241,14 @@ const ChatMessageCombinator = ({
preferences.showSubRoll ? (
patentMessage ? (
<PatentData index={index} message={patentMessage} />
) : mutation.isLoading &&
mutation.variables?.id === msg.id ? (
<div>
<div className="w-[150px]">
<Skeleton className=" w-[150px] h-[225px] rounded object-cover" />
</div>
<Skeleton className="scroll-m-20 tracking-tight text-xs line-clamp-2 w-[150px]"></Skeleton>
</div>
) : (
<Button
disabled={mutation.isLoading}
Expand All @@ -258,17 +261,10 @@ const ChatMessageCombinator = ({
}
className={cn("mx-4 my-3", isLoading && "hidden")}
>
{mutation.isLoading &&
mutation.variables?.id === msg.id ? (
<div>
<div className="w-[150px]">
<Skeleton className=" w-[150px] h-[225px] rounded object-cover" />
</div>
<Skeleton className="scroll-m-20 tracking-tight text-xs line-clamp-2 w-[150px]"></Skeleton>
</div>
) : (
"Search For Patents"
)}
{mutation?.isError &&
mutation?.variables?.id === msg.id
? "No patents found. Search Again"
: "Search For Patents"}
</Button>
)
) : null
Expand Down
16 changes: 2 additions & 14 deletions src/components/inputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ interface InputBarProps {
chatRequestOptions?: ChatRequestOptions | undefined,
) => Promise<string | null | undefined>;
setInput: Dispatch<SetStateAction<string>>;
isChatCompleted: boolean;
chatId: string;
messages: Message[];
orgId: string;
Expand Down Expand Up @@ -498,7 +497,6 @@ const InputBar = (props: InputBarProps) => {
>
{/* <ModelSwitcher
disabled={
props.isChatCompleted ||
isRecording ||
isTranscribing ||
disableInputs
Expand Down Expand Up @@ -541,12 +539,7 @@ const InputBar = (props: InputBarProps) => {
</div>
)}
<TextareaAutosize
disabled={
props.isChatCompleted ||
isRecording ||
isTranscribing ||
disableInputs
}
disabled={isRecording || isTranscribing || disableInputs}
maxRows={10}
placeholder={
isTranscribing
Expand Down Expand Up @@ -600,12 +593,7 @@ const InputBar = (props: InputBarProps) => {
<Button
size="icon"
variant="secondary"
disabled={
props.isChatCompleted ||
isRecording ||
isTranscribing ||
disableInputs
}
disabled={isRecording || isTranscribing || disableInputs}
type="submit"
className="disabled:text-muted"
>
Expand Down
1 change: 0 additions & 1 deletion src/components/patentdata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const PatentData = ({
"item",
parseAsInteger,
);
console.log(parsedInput);
const [open, setOpen] = React.useState(
isOpen && dialogIndex === dialogNumber ? isOpen : false,
);
Expand Down
3 changes: 0 additions & 3 deletions src/components/room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const RoomWrapper = (props: Props) => {
const { channel } = useChannel("room_5", (message) => {
console.log(message);
});
console.log("props.Chat", props.chat);

console.log("props.Chat.tldraw_snapshot", props.snapShot);

const preferences = usePreferences();
const { presenceData, updateStatus } = usePresence(
Expand Down
8 changes: 3 additions & 5 deletions src/components/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<CommandDialog open={showSearchDialog} onOpenChange={toggleSearchDialog}>
<CommandInput
onValueChange={(val) => {
console.log("got the input value");
setValue(val);
}}
value={value}
Expand Down Expand Up @@ -100,7 +98,7 @@ const Search = (props: Props) => {
<CommandGroup heading="Chat History">
{results.length
? results.map((result: any, index: number) => (
<CommandItem key={index}>
<CommandItem key={index} value={`${result?.id}`}>
<Link
href={
result.id
Expand All @@ -113,7 +111,7 @@ const Search = (props: Props) => {
>
<div>
<p className="text-md text-muted-foreground">
{result.chatTitle
{result?.chatTitle
.replace('"', "")
.replace('"', "")
.split(" ")
Expand Down
Loading