diff --git a/.env.example b/.env.example index 77bb5630e..778ad5519 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,6 @@ OPENAI_API_KEY= -# Update these with your Supabase details from your project settings > API +# Update these with your Supabase details from your project settings > API and dashboard settings PINECONE_API_KEY= PINECONE_ENVIRONMENT= - +PINECONE_INDEX_NAME= diff --git a/README.md b/README.md index 93442d511..e014c6657 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Tech stack used includes LangChain, Pinecone, Typescript, Openai, and Next.js. L [Tutorial video](https://www.youtube.com/watch?v=ih9PBGVVOO4) -[Get in touch via twitter if you have questions](https://twitter.com/mayowaoshin) +[Join the discord if you have questions](https://discord.gg/E4Mc77qwjm) The visual guide of this repo and tutorial is in the `visual guide` folder. @@ -69,19 +69,23 @@ In general, keep an eye out in the `issues` and `discussions` section of this re **General errors** - Make sure you're running the latest Node version. Run `node -v` +- Try a different PDF or convert your PDF to text first. It's possible your PDF is corrupted, scanned, or requires OCR to convert to text. +- `Console.log` the `env` variables and make sure they are exposed. - Make sure you're using the same versions of LangChain and Pinecone as this repo. - Check that you've created an `.env` file that contains your valid (and working) API keys, environment and index name. - If you change `modelName` in `OpenAIChat` note that the correct name of the alternative model is `gpt-3.5-turbo` - Make sure you have access to `gpt-4` if you decide to use. Test your openAI keys outside the repo and make sure it works and that you have enough API credits. -- Your pdf file is corrupted and cannot be parsed. +- Check that you don't have multiple OPENAPI keys in your global environment. If you do, the local `env` file from the project will be overwritten by systems `env` variable. +- Try to hard code your API keys into the `process.env` variables. + **Pinecone errors** - Make sure your pinecone dashboard `environment` and `index` matches the one in the `pinecone.ts` and `.env` files. - Check that you've set the vector dimensions to `1536`. - Make sure your pinecone namespace is in lowercase. -- Pinecone indexes of users on the Starter(free) plan are deleted after 7 days of inactivity. To prevent this, send an API request to Pinecone to reset the counter. -- Retry from scratch with a new Pinecone index and cloned repo. +- Pinecone indexes of users on the Starter(free) plan are deleted after 7 days of inactivity. To prevent this, send an API request to Pinecone to reset the counter before 7 days. +- Retry from scratch with a new Pinecone project, index, and cloned repo. ## Credit diff --git a/pages/index.tsx b/pages/index.tsx index 76f2c022a..7fd1bbbcd 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,8 +1,7 @@ -import { useRef, useState, useEffect, useMemo } from 'react'; +import { useRef, useState, useEffect } from 'react'; import Layout from '@/components/layout'; import styles from '@/styles/Home.module.css'; import { Message } from '@/types/chat'; -import { fetchEventSource } from '@microsoft/fetch-event-source'; import Image from 'next/image'; import ReactMarkdown from 'react-markdown'; import LoadingDots from '@/components/ui/LoadingDots'; @@ -17,6 +16,7 @@ import { export default function Home() { const [query, setQuery] = useState(''); const [loading, setLoading] = useState(false); + const [error, setError] = useState(null); const [messageState, setMessageState] = useState<{ messages: Message[]; pending?: string; @@ -30,10 +30,9 @@ export default function Home() { }, ], history: [], - sourceDocs: [], }); - const { messages, pending, history, sourceDocs } = messageState; + const { messages, history } = messageState; const messageListRef = useRef(null); const textAreaRef = useRef(null); @@ -46,6 +45,8 @@ export default function Home() { async function handleSubmit(e: any) { e.preventDefault(); + setError(null); + if (!query) { alert('Please input a question'); return; @@ -82,11 +83,7 @@ export default function Home() { console.log('data', data); if (data.error) { - toast({ - title: 'Something went wrong', - description: data.error, - variant: 'destructive', - }); + setError(data.error); } else { setMessageState((state) => ({ ...state, @@ -99,7 +96,6 @@ export default function Home() { }, ], history: [...state.history, [question, data.text]], - // sourceDocs: data.sourceDocs, })); } console.log('messageState', messageState); @@ -110,6 +106,7 @@ export default function Home() { messageListRef.current?.scrollTo(0, messageListRef.current.scrollHeight); } catch (error) { setLoading(false); + setError('An error occurred while fetching the data. Please try again.'); console.log('error', error); } } @@ -186,7 +183,7 @@ export default function Home() { className="flex-col" > {message.sourceDocs.map((doc, index) => ( -
+

Source {index + 1}

@@ -208,26 +205,6 @@ export default function Home() { ); })} - {sourceDocs.length > 0 && ( -
- - {sourceDocs.map((doc, index) => ( -
- - -

Source {index + 1}

-
- - - {doc.pageContent} - - -
-
- ))} -
-
- )}
@@ -274,9 +251,14 @@ export default function Home() {
+ {error && ( +
+

{error}

+
+ )} -