Skip to content

Commit

Permalink
remove merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mayooear committed Apr 10, 2023
2 parents 7a6d82f + 6db8ba8 commit a74abf2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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=
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down
46 changes: 14 additions & 32 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,6 +16,7 @@ import {
export default function Home() {
const [query, setQuery] = useState<string>('');
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string | null>(null);
const [messageState, setMessageState] = useState<{
messages: Message[];
pending?: string;
Expand All @@ -30,10 +30,9 @@ export default function Home() {
},
],
history: [],
sourceDocs: [],
});

const { messages, pending, history, sourceDocs } = messageState;
const { messages, history } = messageState;

const messageListRef = useRef<HTMLDivElement>(null);
const textAreaRef = useRef<HTMLTextAreaElement>(null);
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -99,7 +96,6 @@ export default function Home() {
},
],
history: [...state.history, [question, data.text]],
// sourceDocs: data.sourceDocs,
}));
}
console.log('messageState', messageState);
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -186,7 +183,7 @@ export default function Home() {
className="flex-col"
>
{message.sourceDocs.map((doc, index) => (
<div key={`sourceDoc-${index}`}>
<div key={`messageSourceDocs-${index}`}>
<AccordionItem value={`item-${index}`}>
<AccordionTrigger>
<h3>Source {index + 1}</h3>
Expand All @@ -208,26 +205,6 @@ export default function Home() {
</>
);
})}
{sourceDocs.length > 0 && (
<div className="p-5">
<Accordion type="single" collapsible className="flex-col">
{sourceDocs.map((doc, index) => (
<div key={`SourceDocs-${index}`}>
<AccordionItem value={`item-${index}`}>
<AccordionTrigger>
<h3>Source {index + 1}</h3>
</AccordionTrigger>
<AccordionContent>
<ReactMarkdown linkTarget="_blank">
{doc.pageContent}
</ReactMarkdown>
</AccordionContent>
</AccordionItem>
</div>
))}
</Accordion>
</div>
)}
</div>
</div>
<div className={styles.center}>
Expand Down Expand Up @@ -274,9 +251,14 @@ export default function Home() {
</form>
</div>
</div>
{error && (
<div className="border border-red-400 rounded-md p-4">
<p className="text-red-500">{error}</p>
</div>
)}
</main>
</div>
<footer className="m-auto">
<footer className="m-auto p-4">
<a href="https://twitter.com/mayowaoshin">
Powered by LangChainAI. Demo built by Mayo (Twitter: @mayowaoshin).
</a>
Expand Down
4 changes: 2 additions & 2 deletions styles/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
flex-direction: column;
justify-content: space-between;
align-items: center;
padding: 2rem;
padding: 1rem;
}

.header {
Expand Down Expand Up @@ -184,7 +184,7 @@
justify-content: center;
align-items: center;
position: relative;
padding: 2rem 0;
padding: 1rem 0;
flex-direction: column;
}

Expand Down
9 changes: 0 additions & 9 deletions utils/openai-client.ts

This file was deleted.

0 comments on commit a74abf2

Please sign in to comment.