Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-janon committed Jul 31, 2024
1 parent 1f4b8a6 commit b90ea03
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 28 deletions.
14 changes: 13 additions & 1 deletion src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions src/components/Cmdk/components/ArrowIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

export const ArrowIcon: React.FC<ArrowIconProps> = ({ className, onClick }) => {
export const ArrowIcon: React.FC<ArrowIconProps> = ({ className }) => {
return (
<svg
width="24"
Expand All @@ -22,5 +22,4 @@ export const ArrowIcon: React.FC<ArrowIconProps> = ({ className, onClick }) => {

interface ArrowIconProps {
className?: string;
onClick?: Function;
}
2 changes: 1 addition & 1 deletion src/components/Cmdk/components/Cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function Home({
inputValue,
setIsCmdkOpen,
}: {
goToChat: Function;
goToChat: () => void;
inputValue: string;
setIsCmdkOpen: Dispatch<SetStateAction<boolean>>;
}) {
Expand Down
14 changes: 5 additions & 9 deletions src/components/Cmdk/components/CmdkChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ initialValue, setCmdkInputVa
}
}, [initialValue, input]);

console.log(error);

return (
<div className="w-full" onClick={(e) => e.stopPropagation()}>
<div className={clsx("relative py-4")}>
Expand Down Expand Up @@ -88,9 +86,7 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ initialValue, setCmdkInputVa
return (
<div key={index} className="px-4 [overflow-anchor:none] mb-[25px]">
<div className="flex gap-6 [overflow-anchor:none] mb-6">
<>
<MarkdownMessage message={message} />
</>
<MarkdownMessage message={message} />
</div>
</div>
);
Expand Down Expand Up @@ -127,6 +123,7 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ initialValue, setCmdkInputVa
<div className="absolute bottom-0 pb-4 w-[98%] bg-background py-3 pt-0 bg-white dark:bg-[#15191e] flex items-center justify-center">
<div className="flex items-center border rounded-full shadow-sm w-[95%] justify-center">
<input
aria-label="Chat input"
ref={inputRef}
type="text"
placeholder={isLoading ? "Waiting on an answer..." : "What can ZetaAI do for you?"}
Expand All @@ -147,13 +144,12 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ 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;
}
Expand All @@ -180,5 +176,5 @@ export const CmdkChat: React.FC<CmdkChatProps> = ({ initialValue, setCmdkInputVa

interface CmdkChatProps {
initialValue: string;
setCmdkInputValue: Function;
setCmdkInputValue: React.Dispatch<React.SetStateAction<string>>;
}
10 changes: 4 additions & 6 deletions src/components/Cmdk/components/MarkdownMesage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import styled from "@emotion/styled";
import { Message } from "ai";
import clsx from "clsx";
import React from "react";
Expand All @@ -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];

Expand All @@ -20,13 +17,14 @@ export const MarkdownMessage: React.FC<MarkdownMessageProps> = ({ message }) =>
rehypePlugins={rehypePlugins}
skipHtml={false}
components={{
code: (props: any) => (
code: ({ children, ...props }: any) => (
<MarkdownCodeBlock
children={props.children}
className={props.className}
// language={props.language}
// title={props.title}
/>
>
{children}
</MarkdownCodeBlock>
),
a: ({ children, ...args }) => {
return (
Expand Down
12 changes: 5 additions & 7 deletions src/components/Cmdk/components/ZetaAiIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

export const ZetaAiIcon: React.FC<ZetaAiIconProps> = ({ className, onClick }) => {
export const ZetaAiIcon: React.FC<ZetaAiIconProps> = ({ className }) => {
return (
<svg
width="91"
Expand All @@ -9,17 +9,16 @@ export const ZetaAiIcon: React.FC<ZetaAiIconProps> = ({ className, onClick }) =>
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
onClick={onClick}
>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M16.7903 17.2241V17.2227L16.789 17.2241H16.7903ZM16.7903 20.4134V17.2241H20.3708V24H0V22.208C0 18.7108 0.329918 15.7426 4.47952 12.0651L4.50318 12.0428L14.4047 3.58533H3.58441V6.83778H0.00394324V0H20.3721V13.7177H16.7903V6.2615L6.84021 14.7584C4.49924 16.8359 3.82231 18.3135 3.64093 20.4134H16.7903ZM59.7914 18.166C59.8019 18.1647 59.8098 18.1555 59.8098 18.145H59.8111V16.1346C59.8111 16.1201 59.798 16.1096 59.7848 16.1135C59.6098 16.1622 59.373 16.1859 59.0769 16.1859H58.2349C57.2731 16.1859 56.231 16.0977 56.231 13.5492V8.00474C56.231 7.99158 56.2416 7.98237 56.2534 7.98237H59.3624C59.3756 7.98237 59.3848 7.97185 59.3848 7.96001V6.05353C59.3848 6.04038 59.3743 6.03117 59.3624 6.03117H56.2534C56.2402 6.03117 56.231 6.02064 56.231 6.0088V1.96428C56.231 1.95113 56.2205 1.94192 56.2087 1.94192H53.9272C53.9141 1.94192 53.9049 1.95244 53.9049 1.96428V6.0088C53.9049 6.02196 53.8943 6.03117 53.8825 6.03117H51.6813C51.6681 6.03117 51.6589 6.04169 51.6589 6.05353V7.96001C51.6589 7.97316 51.6694 7.98237 51.6813 7.98237H53.8825C53.8956 7.98237 53.9049 7.9929 53.9049 8.00474V14.0755C53.9049 17.6095 55.735 18.3239 57.7257 18.3239C58.1165 18.3239 58.5046 18.3055 58.8875 18.27C59.2611 18.2358 59.5624 18.2002 59.7914 18.166ZM41.9464 12.7361C41.9464 12.7229 41.9569 12.7124 41.9687 12.7124V12.7111H51.1195C51.1301 12.7111 51.1393 12.7032 51.1406 12.6927C51.1919 12.3624 51.2222 12.0743 51.2314 11.8296C51.2406 11.5809 51.2445 11.3664 51.2445 11.1888C51.2445 8.13765 48.842 5.71147 45.633 5.71147C42.1911 5.71147 39.6478 8.05871 39.6478 12.098C39.6478 15.3991 41.6437 18.4568 45.7133 18.4568C49.7828 18.4568 50.9906 15.3925 51.1314 14.6097C51.134 14.5965 51.1248 14.5833 51.1103 14.5833H48.8012C48.792 14.5833 48.7855 14.5886 48.7815 14.5965C48.7698 14.6221 48.757 14.6517 48.7428 14.6847C48.5228 15.1933 47.9547 16.5069 45.7133 16.5069C42.62 16.5069 42.0187 14.1781 41.9464 12.7361ZM41.974 10.9257C41.974 9.66915 42.6726 7.50216 45.5804 7.50216C48.1434 7.50216 49.0828 9.53757 49.0012 10.927C48.9999 10.9388 48.9907 10.9493 48.9789 10.9493H41.9963C41.9832 10.9493 41.974 10.9375 41.974 10.9257ZM72.8566 6.05491V18.1424C72.8566 18.1542 72.8474 18.1648 72.8342 18.1648H70.5804C70.5685 18.1648 70.558 18.1556 70.558 18.1424V16.1373C70.558 16.1149 70.5278 16.107 70.5185 16.128C70.1107 16.9346 68.745 18.4582 66.3096 18.4582C63.0663 18.4582 60.0836 15.9123 60.0836 12.0993C60.0836 9.00343 62.2874 5.71282 66.3096 5.71282C68.5871 5.71282 70.0528 7.11538 70.5185 8.04296C70.5291 8.06269 70.558 8.05611 70.558 8.03375V6.05491C70.558 6.04307 70.5672 6.03254 70.5804 6.03254H72.8342C72.846 6.03254 72.8566 6.04175 72.8566 6.05491ZM66.4438 16.3741C69.3041 16.3741 70.5593 14.0637 70.5593 12.0993C70.5593 9.82312 68.9528 7.79692 66.4438 7.79692C63.6045 7.79692 62.3821 10.2192 62.3821 12.0993C62.3821 13.9795 63.5374 16.3741 66.4438 16.3741ZM29.3102 17.1279C29.3102 15.3662 29.4734 13.8702 31.5272 12.0137V12.0124L31.5535 11.9887L36.1941 8.0942H29.3023V6.02195H38.7255V8.63891L32.8719 13.5715C31.8456 14.5017 31.5048 15.1807 31.397 16.0911H38.7255V18.1634H29.3102V17.1279Z"
className="dark:fill-white fill-black"
/>
<path
fill-rule="evenodd"
clip-rule="evenodd"
fillRule="evenodd"
clipRule="evenodd"
d="M87.9528 5.76209V18.1394H90.335V5.76209H87.9528ZM87.8055 0.580322V3.57641H90.4578V0.580322H87.8055ZM74.7664 14.6036C74.7664 16.8139 76.4363 18.3365 78.9658 18.3365C80.8322 18.3365 82.404 17.4769 82.9934 16.1262V18.14H85.3755V10.1586C85.3755 7.40811 83.2635 5.56625 80.0709 5.56625C77.1485 5.56625 74.9383 7.38355 74.7418 9.81481H76.9521C77.0257 8.56234 78.2782 7.48179 79.9973 7.48179C81.9128 7.48179 82.9934 8.51323 82.9934 10.0113C82.9934 10.4533 82.7232 10.748 82.1584 10.748H79.5798C76.6574 10.748 74.7664 12.2215 74.7664 14.6036ZM79.4324 16.4455C78.0572 16.4455 77.124 15.6842 77.124 14.5545C77.124 13.2529 78.18 12.418 79.8008 12.418H82.9934V12.7127C82.9934 14.9966 81.6918 16.4455 79.4324 16.4455Z"
fill="#00BC8D"
/>
Expand All @@ -29,5 +28,4 @@ export const ZetaAiIcon: React.FC<ZetaAiIconProps> = ({ className, onClick }) =>

interface ZetaAiIconProps {
className?: string;
onClick?: Function;
}
6 changes: 4 additions & 2 deletions src/lib/generate-embeddings.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -137,6 +135,7 @@ function processMdxForSearch(content: string): ProcessedMdx {
mdastExtensions: [],
});

// @ts-ignore
const meta = extractMetaExport(mdxTree);

// Remove all MDX elements from markdown
Expand All @@ -156,6 +155,7 @@ function processMdxForSearch(content: string): ProcessedMdx {
};
}

// @ts-ignore
const sectionTrees = splitTreeBy(mdTree, (node) => node.type === "heading");

const slugger = new GithubSlugger();
Expand Down Expand Up @@ -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<typeof existingPage.parentPage>;

// 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
Expand Down

0 comments on commit b90ea03

Please sign in to comment.