From b90ea030f879df2ad3c69f48bc9b37a9173541b3 Mon Sep 17 00:00:00 2001 From: Lucas Janon Date: Wed, 31 Jul 2024 10:42:39 -0300 Subject: [PATCH] Polish --- src/app/api/chat/route.ts | 14 +++++++++++++- src/components/Cmdk/components/ArrowIcon.tsx | 3 +-- src/components/Cmdk/components/Cmdk.tsx | 2 +- src/components/Cmdk/components/CmdkChat.tsx | 14 +++++--------- src/components/Cmdk/components/MarkdownMesage.tsx | 10 ++++------ src/components/Cmdk/components/ZetaAiIcon.tsx | 12 +++++------- src/lib/generate-embeddings.ts | 6 ++++-- 7 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/app/api/chat/route.ts b/src/app/api/chat/route.ts index ed964456..2ba484ed 100644 --- a/src/app/api/chat/route.ts +++ b/src/app/api/chat/route.ts @@ -6,7 +6,19 @@ import { CoreMessage, embed, streamText } from "ai"; import { supabaseClient } from "~/lib/supabase/client"; -const getPrompt = (userPrompt: string, pageSections: any[] | null) => { +const getPrompt = ( + userPrompt: string, + pageSections: + | { + id: number; + page_id: number; + slug: string; + heading: string; + content: string; + similarity: number; + }[] + | null +) => { if (typeof process.env.ZETA_AI_PROMPT !== "string") throw new Error("ZETA_AI_PROMPT is not a string"); return Buffer.from(process.env.ZETA_AI_PROMPT, "base64") diff --git a/src/components/Cmdk/components/ArrowIcon.tsx b/src/components/Cmdk/components/ArrowIcon.tsx index cdd1b5fb..b571db9f 100644 --- a/src/components/Cmdk/components/ArrowIcon.tsx +++ b/src/components/Cmdk/components/ArrowIcon.tsx @@ -1,6 +1,6 @@ import React from "react"; -export const ArrowIcon: React.FC = ({ className, onClick }) => { +export const ArrowIcon: React.FC = ({ className }) => { return ( = ({ className, onClick }) => { interface ArrowIconProps { className?: string; - onClick?: Function; } diff --git a/src/components/Cmdk/components/Cmdk.tsx b/src/components/Cmdk/components/Cmdk.tsx index 744a162e..8897372d 100644 --- a/src/components/Cmdk/components/Cmdk.tsx +++ b/src/components/Cmdk/components/Cmdk.tsx @@ -296,7 +296,7 @@ function Home({ inputValue, setIsCmdkOpen, }: { - goToChat: Function; + goToChat: () => void; inputValue: string; setIsCmdkOpen: Dispatch>; }) { diff --git a/src/components/Cmdk/components/CmdkChat.tsx b/src/components/Cmdk/components/CmdkChat.tsx index 01235e43..0de9b166 100644 --- a/src/components/Cmdk/components/CmdkChat.tsx +++ b/src/components/Cmdk/components/CmdkChat.tsx @@ -40,8 +40,6 @@ export const CmdkChat: React.FC = ({ initialValue, setCmdkInputVa } }, [initialValue, input]); - console.log(error); - return (
e.stopPropagation()}>
@@ -88,9 +86,7 @@ export const CmdkChat: React.FC = ({ initialValue, setCmdkInputVa return (
- <> - - +
); @@ -127,6 +123,7 @@ export const CmdkChat: React.FC = ({ initialValue, setCmdkInputVa
= ({ initialValue, setCmdkInputVa onKeyDown={(e) => { switch (e.key) { case "Enter": - if (isLoading) { - return; - } + if (isLoading) return; handleSubmit(e); return; case "Backspace": e.stopPropagation(); + break; default: return; } @@ -180,5 +176,5 @@ export const CmdkChat: React.FC = ({ initialValue, setCmdkInputVa interface CmdkChatProps { initialValue: string; - setCmdkInputValue: Function; + setCmdkInputValue: React.Dispatch>; } diff --git a/src/components/Cmdk/components/MarkdownMesage.tsx b/src/components/Cmdk/components/MarkdownMesage.tsx index c3af7298..a68e81db 100644 --- a/src/components/Cmdk/components/MarkdownMesage.tsx +++ b/src/components/Cmdk/components/MarkdownMesage.tsx @@ -1,4 +1,3 @@ -import styled from "@emotion/styled"; import { Message } from "ai"; import clsx from "clsx"; import React from "react"; @@ -8,8 +7,6 @@ import remarkGfm from "remark-gfm"; import { MarkdownCodeBlock } from "./MarkdownCodeBlock"; -const StyledMarkdownMessage = styled.div``; - const remarkPlugins = [[remarkGfm, { singleTilde: false }]]; const rehypePlugins = [rehypeRaw]; @@ -20,13 +17,14 @@ export const MarkdownMessage: React.FC = ({ message }) => rehypePlugins={rehypePlugins} skipHtml={false} components={{ - code: (props: any) => ( + code: ({ children, ...props }: any) => ( + > + {children} + ), a: ({ children, ...args }) => { return ( diff --git a/src/components/Cmdk/components/ZetaAiIcon.tsx b/src/components/Cmdk/components/ZetaAiIcon.tsx index 3f8fc95f..2b239c3a 100644 --- a/src/components/Cmdk/components/ZetaAiIcon.tsx +++ b/src/components/Cmdk/components/ZetaAiIcon.tsx @@ -1,6 +1,6 @@ import React from "react"; -export const ZetaAiIcon: React.FC = ({ className, onClick }) => { +export const ZetaAiIcon: React.FC = ({ className }) => { return ( = ({ className, onClick }) => fill="none" xmlns="http://www.w3.org/2000/svg" className={className} - onClick={onClick} > @@ -29,5 +28,4 @@ export const ZetaAiIcon: React.FC = ({ className, onClick }) => interface ZetaAiIconProps { className?: string; - onClick?: Function; } diff --git a/src/lib/generate-embeddings.ts b/src/lib/generate-embeddings.ts index ffb71387..3616c224 100644 --- a/src/lib/generate-embeddings.ts +++ b/src/lib/generate-embeddings.ts @@ -1,7 +1,5 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck /* eslint-disable no-console */ -import "openai"; import { createClient } from "@supabase/supabase-js"; import { createHash } from "crypto"; @@ -137,6 +135,7 @@ function processMdxForSearch(content: string): ProcessedMdx { mdastExtensions: [], }); + // @ts-ignore const meta = extractMetaExport(mdxTree); // Remove all MDX elements from markdown @@ -156,6 +155,7 @@ function processMdxForSearch(content: string): ProcessedMdx { }; } + // @ts-ignore const sectionTrees = splitTreeBy(mdTree, (node) => node.type === "heading"); const slugger = new GithubSlugger(); @@ -319,9 +319,11 @@ async function generateEmbeddings() { // We use checksum to determine if this page & its sections need to be regenerated if (!shouldRefresh && existingPage?.checksum === checksum) { + // @ts-ignore const existingParentPage = existingPage?.parentPage as Singular; // If parent page changed, update it + // @ts-ignore if (existingParentPage?.path !== parentPath) { console.log(`[${path}] Parent page has changed. Updating to '${parentPath}'...`); const { error: fetchParentPageError, data: parentPage } = await supabaseClient