aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/(dash)/chat/chatWindow.tsx
diff options
context:
space:
mode:
authorDhravya Shah <[email protected]>2024-07-25 17:35:15 -0500
committerDhravya Shah <[email protected]>2024-07-25 17:35:15 -0500
commitc57719446ae95c2bbd432d7b2b6648a23b35c351 (patch)
treec6f7aca777c7f4748cc6dc335fe56fba8725af02 /apps/web/app/(dash)/chat/chatWindow.tsx
parentadd try catch in api/add for better error handling (diff)
parentughh, regenerated migrations. my bad. (diff)
downloadsupermemory-kush/experimental-thread.tar.xz
supermemory-kush/experimental-thread.zip
solve merge conflictskush/experimental-thread
Diffstat (limited to 'apps/web/app/(dash)/chat/chatWindow.tsx')
-rw-r--r--apps/web/app/(dash)/chat/chatWindow.tsx48
1 files changed, 45 insertions, 3 deletions
diff --git a/apps/web/app/(dash)/chat/chatWindow.tsx b/apps/web/app/(dash)/chat/chatWindow.tsx
index 28b99c9d..ed65bf7a 100644
--- a/apps/web/app/(dash)/chat/chatWindow.tsx
+++ b/apps/web/app/(dash)/chat/chatWindow.tsx
@@ -35,14 +35,19 @@ function ChatWindow({
parts: [],
sources: [],
},
+ proModeProcessing: {
+ queries: [],
+ },
},
],
threadId,
+ proMode,
}: {
q: string;
spaces: { id: number; name: string }[];
initialChat?: ChatHistory[];
threadId: string;
+ proMode: boolean;
}) {
const [layout, setLayout] = useState<"chat" | "initial">("chat");
const [chatHistory, setChatHistory] = useState<ChatHistory[]>(initialChat);
@@ -63,13 +68,17 @@ function ChatWindow({
const router = useRouter();
- const getAnswer = async (query: string, spaces: string[]) => {
+ const getAnswer = async (
+ query: string,
+ spaces: string[],
+ proMode: boolean = false,
+ ) => {
if (query.trim() === "from_loading" || query.trim().length === 0) {
return;
}
const sourcesFetch = await fetch(
- `/api/chat?q=${query}&spaces=${spaces}&sourcesOnly=true&threadId=${threadId}`,
+ `/api/chat?q=${query}&spaces=${spaces}&sourcesOnly=true&threadId=${threadId}&proMode=${proMode}`,
{
method: "POST",
body: JSON.stringify({ chatHistory }),
@@ -91,6 +100,8 @@ function ChatWindow({
behavior: "smooth",
});
+ let proModeListedQueries: string[] = [];
+
const updateChatHistoryAndFetch = async () => {
// Step 1: Update chat history with the assistant's response
await new Promise((resolve) => {
@@ -123,6 +134,11 @@ function ChatWindow({
).length,
}));
+ lastAnswer.proModeProcessing.queries =
+ sourcesParsed.data.proModeListedQueries ?? [];
+
+ proModeListedQueries = lastAnswer.proModeProcessing.queries;
+
resolve(newChatHistory);
return newChatHistory;
});
@@ -130,7 +146,7 @@ function ChatWindow({
// Step 2: Fetch data from the API
const resp = await fetch(
- `/api/chat?q=${query}&spaces=${spaces}&threadId=${threadId}`,
+ `/api/chat?q=${(query += proModeListedQueries.join(" "))}&spaces=${spaces}&threadId=${threadId}`,
{
method: "POST",
body: JSON.stringify({ chatHistory, sources: sourcesParsed.data }),
@@ -181,6 +197,7 @@ function ChatWindow({
getAnswer(
q,
spaces.map((s) => `${s.id}`),
+ proMode,
);
}
} else {
@@ -224,6 +241,28 @@ function ChatWindow({
{chat.question}
</h2>
+ {chat.proModeProcessing?.queries?.length > 0 && (
+ <div className="flex flex-col mt-2">
+ <div className="text-foreground-menu py-2">
+ Pro Mode
+ </div>
+ <div className="text-base">
+ <div className="flex gap-2 text-base">
+ {chat.proModeProcessing.queries.map(
+ (query, idx) => (
+ <div
+ className="bg-secondary rounded-md p-2"
+ key={`promode-query-${idx}`}
+ >
+ {query}
+ </div>
+ ),
+ )}
+ </div>
+ </div>
+ </div>
+ )}
+
<div className="flex flex-col mt-2">
<div>
<div className="text-foreground-menu py-2">Answer</div>
@@ -407,6 +446,9 @@ function ChatWindow({
parts: [],
sources: [],
},
+ proModeProcessing: {
+ queries: [],
+ },
},
];
});