Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwabco committed Jan 8, 2024
1 parent 90b71dc commit 7cf73ee
Show file tree
Hide file tree
Showing 24 changed files with 28 additions and 108 deletions.
2 changes: 1 addition & 1 deletion src/app/api/chat/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Configuration, OpenAIApi } from 'openai-edge'
import { Message, OpenAIStream, StreamingTextResponse, experimental_StreamData } from 'ai'
import { Metadata, getContext } from '@/utils/context'
import { Metadata, getContext } from '@/services/context'
import { PineconeRecord, ScoredVector } from '@pinecone-database/pinecone'

// Create an OpenAI API client (that's edge friendly!)
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/crawl/seed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getEmbeddings } from "@/utils/embeddings";
import { getEmbeddings } from "@/services/embeddings";
import { truncateStringByBytes } from "@/utils/truncateString";
import { Document, MarkdownTextSplitter, RecursiveCharacterTextSplitter } from "@pinecone-database/doc-splitter";
import { Pinecone, PineconeRecord } from "@pinecone-database/pinecone";
import { chunkedUpsert } from '../../utils/chunkedUpsert'
import md5 from "md5";
import { chunkedUpsert } from '@/services/chunkedUpsert';
import { Crawler, Page } from "./crawler";
import { truncateStringByBytes } from "@/utils/truncateString"

interface SeedOptions {
splittingMethod: string
Expand Down
1 change: 0 additions & 1 deletion src/app/appContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';


interface RefreshIndexContextType {
totalRecords: number;
refreshIndex: () => Promise<void>;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/app/components/Chat/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UpArrowSvg } from '@/utils/svg/upArrow';
import { UpArrowSvg } from '@/assets/svg/upArrow';
import React, { FormEvent } from 'react';

interface ChatInputProps {
Expand All @@ -25,7 +25,6 @@ const ChatInput: React.FC<ChatInputProps> = ({ input, handleInputChange, handleM
className="bg-white rounded-lg relative"
>
<div style={styles.form}>

<input
type="text"
className="input-glow appearance-none w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline pl-3 pr-10 transition-shadow duration-200"
Expand Down
6 changes: 3 additions & 3 deletions src/app/components/Chat/ChatWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { FormEvent, ChangeEvent, forwardRef, useImperativeHandle, useRef, Ref, useEffect, useState } from "react";
import Messages from "./Messages";
import type { PineconeRecord } from "@pinecone-database/pinecone";
import { useChat } from "ai/react";
import type { PineconeRecord, RecordMetadata, ScoredPineconeRecord } from "@pinecone-database/pinecone";
import React, { ChangeEvent, FormEvent, Ref, forwardRef, useEffect, useImperativeHandle, useRef } from "react";
import { v4 as uuidv4 } from 'uuid';
import Messages from "./Messages";

export interface ChatInterface {
handleMessageSubmit: (e: FormEvent<HTMLFormElement>) => void;
Expand Down
17 changes: 8 additions & 9 deletions src/app/components/Chat/Messages.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { EllipseIcon } from "@/assets/icons/ellipse";
import { PineconeIcon } from "@/assets/icons/pinecone";
import { UserIcon } from "@/assets/icons/user";
import { BlueEllipseSvg } from "@/assets/svg/blueEllipse";
import { PineconeLogoSvg } from "@/assets/svg/pineconeLogo";
import { Typography } from "@mui/material";
import Popover from '@mui/material/Popover';
import type { PineconeRecord } from "@pinecone-database/pinecone";
import { Message } from "ai";
import { useRef, useState } from "react";
import { UserIcon } from "@/utils/icons/user";
import { PineconeIcon } from "@/utils/icons/pinecone";
import { EllipseIcon } from "@/utils/icons/ellipse";
import { BlueEllipseSvg } from "@/utils/svg/blueEllipse";
import { PineconeRecord } from "@pinecone-database/pinecone";
import Popover from '@mui/material/Popover';
import { Typography } from "@mui/material";
import { PineconeSvg } from "@/utils/svg/pinecone";
import { PineconeLogoSvg } from "@/utils/svg/pineconeLogo";

export default function Messages({ messages, withContext, context }: { messages: Message[], withContext: boolean, context?: { context: PineconeRecord[] }[] }) {
const messagesEndRef = useRef<HTMLDivElement | null>(null);
Expand Down
15 changes: 4 additions & 11 deletions src/app/components/Chat/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { FormEvent, ChangeEvent, useRef, useEffect, useContext } from "react";
import ChatWrapper, { ChatInterface } from "./ChatWrapper";
import ChatInput from "./ChatInput";
import { Message } from "ai";
import type { PineconeRecord, RecordMetadata, ScoredPineconeRecord } from "@pinecone-database/pinecone";
import useRefreshIndex from "@/hooks/useRefreshIndex";
import AppContext from "@/appContext";
import type { PineconeRecord } from "@pinecone-database/pinecone";
import React, { ChangeEvent, FormEvent, useContext, useRef } from "react";
import ChatInput from "./ChatInput";
import ChatWrapper, { ChatInterface } from "./ChatWrapper";

interface ChatProps {
setContext: (data: { context: PineconeRecord[] }[]) => void;
Expand All @@ -18,11 +16,6 @@ const Chat: React.FC<ChatProps> = ({ setContext, context }) => {

const { totalRecords } = useContext(AppContext);

useEffect(() => {
console.log("totalRecords", totalRecords)
}, [totalRecords])


const [input, setInput] = React.useState<string>("")
const onMessageSubmit = (e: FormEvent<HTMLFormElement>) => {
setInput("")
Expand Down
55 changes: 0 additions & 55 deletions src/app/components/InstructionModal.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/components/Sidebar/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BlueEllipseSvg } from "@/utils/svg/blueEllipse";
import { BlueEllipseSvg } from "@/assets/svg/blueEllipse";
import { PineconeRecord } from "@pinecone-database/pinecone";
import React, { FC } from "react";
import ReactMarkdown from "react-markdown";
Expand Down
13 changes: 0 additions & 13 deletions src/app/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ export const Sidebar: React.FC = () => {
setSplittingMethod(value)
}


const chunkSizePopoverTriggers = {
onMouseEnter: () => setOpenChunkSizePopover(true),
onMouseLeave: () => setOpenChunkSizePopover(false),
};



const overLapPopoverTriggers = {
onMouseEnter: () => setOpenOverLapPopover(true),
onMouseLeave: () => setOpenOverLapPopover(false),
};

const handleEmbedAndUpsertClick = async () => {
setCrawling(true)
await crawlDocument(
Expand Down
10 changes: 4 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// page.tsx

"use client";

import React, { useEffect, useState } from "react";
import { Sidebar } from "@/components/Sidebar";
import Chat from "@/components/Chat";
import AppContext from "./appContext";
import useRefreshIndex from '@/hooks/useRefreshIndex'
import { Sidebar } from "@/components/Sidebar";
import useRefreshIndex from '@/hooks/useRefreshIndex';
import type { PineconeRecord } from "@pinecone-database/pinecone";
import React, { useEffect, useState } from "react";
import AppContext from "./appContext";

const Page: React.FC = () => {
const [context, setContext] = useState<{ context: PineconeRecord[] }[] | null>(null);
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/app/utils/context.ts → src/app/services/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ScoredVector } from "@pinecone-database/pinecone";
import type { PineconeRecord } from "@pinecone-database/pinecone";
import { getEmbeddings } from './embeddings';
import { getMatchesFromEmbeddings } from "./pinecone";
import { getEmbeddings } from './embeddings'

export type Metadata = {
url: string,
Expand All @@ -9,7 +9,7 @@ export type Metadata = {
}

// The function `getContext` is used to retrieve the context of a given message
export const getContext = async (message: string, namespace: string, maxTokens = 3000, minScore = 0.7, getOnlyText = true): Promise<ScoredVector[]> => {
export const getContext = async (message: string, namespace: string, maxTokens = 3000, minScore = 0.7, getOnlyText = true): Promise<PineconeRecord[]> => {

// Get the embeddings of the input message
const embedding = await getEmbeddings(message);
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 7cf73ee

Please sign in to comment.