Giter Club home page Giter Club logo

chatpdf-yt's Introduction

Build and Deploy Full Stack ChatPDF Clone

Link to YouTube Tutorial

Overview

Welcome to the "chatpdf-yt" project, a comprehensive chat application with PDF integration. This project is designed to provide a seamless chat experience where users can upload PDF files, create chats around them, and interact with an AI assistant. The AI assistant uses the OpenAI API to generate responses based on the chat context. The application also includes a subscription feature, where users can subscribe to access premium features. The subscription process is handled using Stripe for payments and webhooks for event processing.

hi this is a test change!

Technologies and Frameworks

  • Next.js
  • React
  • TypeScript
  • Tailwind CSS
  • Clerk
  • Drizzle ORM
  • PostgreSQL
  • AWS SDK
  • OpenAI API
  • Stripe
  • Axios
  • Pinecone
  • Drizzle-kit
  • OpenAI Edge
  • Neon Database Serverless
  • Drizzle-orm/neon-http
  • @tanstack/react-query
  • @clerk/nextjs
  • clsx
  • tailwind-merge

Installation

Follow the steps below to install and setup the project:

  1. Clone the repository

    Open your terminal and run the following command:

    git clone https://github.com/Elliott-Chong/chatpdf-yt.git
  2. Navigate to the project directory

    cd chatpdf-yt
  3. Install Node.js

    The project requires Node.js version 13.4.19 or later. You can download it from here.

  4. Install the required dependencies

    Run the following command to install all the required dependencies:

    npm install

    This will install all the dependencies listed in the package.json file, including Next.js, React, React DOM, Axios, Stripe, Tailwind CSS, and other specific dependencies such as "@aws-sdk/client-s3" and "@clerk/nextjs".

  5. Setup environment variables

    Create a .env file in the root directory of your project and add the required environment variables.

  6. Run the project

    Now, you can run the project using the following command:

    npm run dev

    Open http://localhost:3000 with your browser to see the result.

chatpdf-yt's People

Contributors

elliott-chong avatar goudete avatar nicolello-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatpdf-yt's Issues

failed to load source : axios error

○ Compiling /sign-in/[[...sign-in]] ...
✓ Compiled /sign-in/[[...sign-in]] in 1214ms (1764 modules)
○ Compiling /api/create-chat ...
✓ Compiled /api/create-chat in 4.2s (1011 modules)
uploads/1709102023870Educational-E-book Doc.pdf Educational E-book Doc.pdf
downloading s3 into file system
Error: Resolved credential object is not valid is the terminal error i get, after i upgraded to standard pinecone db and all credentials are correct with no typos, and i also have these errors in the console looking like its having a hard time posting the vectors into pinecone and im not sure why. followed along with the video and been doing research and found nothing. anything helps
Screenshot 2024-02-28 013911

Rate limit reached for text-embedding-ada-002

After facing so many issues and errors finally the project is finished. and when I run the project once again it's not creating the chat and an error is displayed....

Rate limit reached for text-embedding-ada-002 in organization org-xjhxbxTHUyTzN4yftLmU3EDd on requests per min (RPM): Limit 3, Used 3, Requested 1. Please try again in 20s. Visit https://platform.openai.com/account/rate-limits to learn more. You can increase your rate limit by adding a payment method to your account at https://platform.openai.com/account/billing.

@Elliott-Chong

Screenshot 2023-12-19 182826

What is the reason of this error and how can I resolve this error.

Error query

When I run the application asked me directly the access with clerk and after I receive this error
IMG_6873

TypeError: Cannot read properties of undefined (reading 'text')

I keep encountering with the error

TypeError: Cannot read properties of undefined (reading 'text')
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:136:40)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:8:12)
    at extractMessage (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/utils.js:129:12)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:178:76)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:8:12)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:171:36)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:151:25)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:8:12)
    at handleFetchError (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:136:12)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:170:54)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
    at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:26:71)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:8:12)
    at handleApiError (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:164:12)
    at UpsertCommand.eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/data/upsert.js:178:57)
    at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/data/upsert.js:107:23)
    at Object.eval [as throw] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/data/upsert.js:48:20)
    at rejected (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/data/upsert.js:18:40)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

When trying to upsert vectors to Pinecone.
I think the 'text' does not refer to the text varibale I am trying to upsert. And not only the upsert, any operation would return this error.

I search on internet and there is a similar situation, don't know if they are relative.
https://github.com/pinecone-io/pinecone-ts-client/issues/124
Here is my code and welcome to judge.
https://github.com/Scott-Zeta/chatpdf/blob/main/src/lib/pinecone.ts
Thanks!

Pinecone Starter plan does not work

why

Pinecone has decided not to support the namespace feature for their free plan.

In my code, I was using the namespace feature like this:

const namespace = pineconeIndex.namespace(convertToAscii(fileKey));

Due to this limitation, I can't use the namespace feature in two places in my code. Although it's possible to proceed without using namespaces, this would result in answers being pulled from multiple files, which is not the desired behavior.

Error inserting vectors into pinecone

Hi, i got some error when inserting vector to pinecone. This is the error that i got, if someone have the same problem and fix it can you help me to give some solution. Thank you

inserting vectors into pinecone
PineconeBadRequestError: The requested feature 'Namespaces' is not supported by the current index type 'Starter'.
at mapHttpStatusError (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/http.js:179:20)
at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:170:55)
at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
at fulfilled (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:11:32)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: undefined
}
⨯ node_modules@pinecone-database\pinecone\dist\errors\http.js (179:19) @ mapHttpStatusError
⨯ unhandledRejection: PineconeBadRequestError: The requested feature 'Namespaces' is not supported by the current index type 'Starter'.
at mapHttpStatusError (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/http.js:179:20)
at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:170:55)
at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
at fulfilled (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:11:32)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: undefined
}
null
⨯ node_modules@pinecone-database\pinecone\dist\errors\http.js (179:19) @ mapHttpStatusError
⨯ unhandledRejection: PineconeBadRequestError: The requested feature 'Namespaces' is not supported by the current index type 'Starter'.
at mapHttpStatusError (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/http.js:179:20)
at eval (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:170:55)
at step (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:107:23)
at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:48:20)
at fulfilled (webpack-internal:///(rsc)/./node_modules/@pinecone-database/pinecone/dist/errors/handling.js:11:32)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
cause: undefined
}
null

Error in querying embeddings

Having some error when getting context from query.

On function getMatchesFromEmbeddings() , any idea?

Thanks!

error querying embeddings [TypeError: Cannot read properties of undefined (reading 'text')]

Cannot read properties of undefined (reading '0')

Around 3:24:00, we test the app to make sure it is working. At this point, we've integrated embedding the document we upload so it can be used in chatGPT.

One the initial pdf upload, I am getting the following error from embeddings.ts:

TypeError: Cannot read properties of undefined (reading '0')
import { OpenAIApi, Configuration } from "openai-edge";

const config = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});

const openai = new OpenAIApi(config);

export async function getEmbeddings(text: string) {
  try {
    const response = await openai.createEmbedding({
      model: "text-embedding-ada-002",
      input: text.replace("/\n/g", " "),
    });

    const result = await response.json();
    return result.data[0].embedding as number[];
  } catch (error) {
    console.log("Error calling OpenAI embeddings api", error);
    throw error;
  }
}

As far as I can tell, my file is the same was what is on the repo. After the initial load, result.data is no longer undefined:

{
  object: 'list',
  data: [ { object: 'embedding', index: 0, embedding: [Array] } ],
  model: 'text-embedding-ada-002-v2',
  usage: { prompt_tokens: 187, total_tokens: 187 }
}

How can I fix this issue?

error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')

Im using Windows and im getting this error.

this is my repo: https://github.com/MatthewAraujo/chatpdf

I can upload in S3 buckets, and save the pdf in my /tmp folder but when get in the part of vectorizing and embedding individual documents (step 3) I get this type of error. I already saw the video again and copied some code of your repo but didn't work.

`error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 1)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:45:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37)

TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 1)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:45:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37)

error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 1)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:45:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37)

error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 3)

error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 3)

error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
gs.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pinecone.ts:56:28)
at async Promise.all (index 0)`

I appreciated already

Langchain Issue?

I occationally found a file would be read incorrectly in the langchain readding step. But other pdf files in my hand works well. So I am not sure it is my configuration problem or the file is too special for langchain to read. I tried some online tools to extract the text, and they are all fine.

It looks like

Bupa A\nustralia\nNothing is mor\ne important t\no us than pr\noviding our\nmembers with quality c\norpor\nate health insur\nanc\ne.\n
Bupa A
ustralia
Nothing is mor
e important t
o us than pr
oviding our
members with quality c
orpor
ate health insur
anc
e.

Many words have been divied by newline without obvious pattern or reason. Then the new line char would be convert to space in the next step, make it would have potential bias when embedding.
If you are intereted in. Here is the link for the original file:
https://github.com/Scott-Zeta/chatpdf/tree/API-call-method/attachment

PDF does not upload to the bucket.

HI Elliot. I have issues uploading the PDF file to the bucket. I am in the part of the video https://youtu.be/r895rFUbGtE?t=4635.

I noticed you updated the S3.ts file to the AWS sdk-v3 in the repo. I updated mine accordingly but when I try to upload the file I get this and not get any error.
image

But when I try to check the bucket file is not uploaded for some reason. I am using WSL on Windows. Appreciate the help.

Clerk blocking /api/stripe

To reproduce:

  1. click upgrade to pro

  2. enter details into stripe

  3. all succeeds on the stripe side and returns to "/"

  4. However Clerk seems to be blocking access to /api/stripe with the following error:
    [401] POST http://localhost:3000/api/stripe
    Also, the following logs are sent from Clerk:
    INFO: Clerk: The request to /api/stripe is being protected (401) because there is no signed-in user, and the path is included in apiRoutes. To prevent this behavior, choose one of:

  5. To prevent Clerk authentication from protecting (401) the api route, remove the rule matching "/api/stripe" from the apiRoutes array passed to authMiddleware

  6. To make the route accessible to both signed in and signed out users, add "/api/stripe" to the publicRoutes array passed to authMiddleware

  7. To prevent Clerk authentication from running at all, pass ignoredRoutes: ["/((?!api|trpc))(_next.*|.+\.[\w]+$)", "/api/stripe"] to authMiddleware

  8. Pass a custom afterAuth to authMiddleware, and replace Clerk's default behavior of redirecting unless a route is included in publicRoutes

I am logged in.

Also, I've tried adding /api/stripe to the public_routes in middleware but it then returns 405 Method Not Allowed

I've tried updating the library for clerk again as well.

I'm stuck with what to debug next.

Thanks!

For additional information about middleware, please visit https://clerk.com/docs/nextjs/middleware

Error to create chat

I have this problem, dont know actually how to solved, learning by your video.
if somebody can help me please?

Screenshot 2023-09-21 at 01 17 14

this is my terminal:

⚠ ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/goga/Documents/myProjects/chatpdf/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx
⚠ ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/goga/Documents/myProjects/chatpdf/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx
⚠ ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/goga/Documents/myProjects/chatpdf/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx
⚠ ./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/load-crt.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/SignatureV4MultiRegion.js
./node_modules/@aws-sdk/signature-v4-multi-region/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.shared.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx

./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
Module not found: Can't resolve 'aws-crt' in '/Users/goga/Documents/myProjects/chatpdf/node_modules/@aws-sdk/util-user-agent-node/dist-cjs'

Import trace for requested module:
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/is-crt-available.js
./node_modules/@aws-sdk/util-user-agent-node/dist-cjs/index.js
./node_modules/@aws-sdk/client-s3/dist-cjs/runtimeConfig.js
./node_modules/@aws-sdk/client-s3/dist-cjs/S3Client.js
./node_modules/@aws-sdk/client-s3/dist-cjs/index.js
./src/lib/s3.ts
./src/components/FileUpload.tsx

./node_modules/node-fetch/lib/index.js
Module not found: Can't resolve 'encoding' in '/Users/goga/Documents/myProjects/chatpdf/node_modules/node-fetch/lib'

Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/@pinecone-database/pinecone/dist/pinecone.js
./node_modules/@pinecone-database/pinecone/dist/index.js
./src/lib/pincecone.ts
./src/app/api/create-chat/route.ts
uploads/1695248226308the-weekend.pdf the weekend.pdf
downloading s3 into file system
loading pdf into memory/tmp/elliott1695248229781.pdf
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 2)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pincecone.ts:41:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async /Users/goga/Documents/myProjects/chatpdf/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:1:66877
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 2)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pincecone.ts:41:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async /Users/goga/Documents/myProjects/chatpdf/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:1:66877
TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 2)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pincecone.ts:41:21)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async /Users/goga/Documents/myProjects/chatpdf/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:1:66877
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 3)
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 3)
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 4)
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 4)
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 1)
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 1)
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 0)
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 0)
error calling openai embeddings api TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 5)
error embedding document TypeError: Cannot read properties of undefined (reading '0')
at getEmbeddings (webpack-internal:///(rsc)/./src/lib/embeddings.ts:18:27)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async embedDocument (webpack-internal:///(rsc)/./src/lib/pincecone.ts:52:28)
at async Promise.all (index 5)

Unhandled Runtime error

Unhandled Runtime Error
Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server".
{listeners: Set, subscribe: function, config: ..., queries: ..., queriesMap: ...}
^^^^^^^^

Call Stack

file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:455033)
QueryCache.toJSON
file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:455797)
stringify

st
file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:460079)
lt
file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:460478)
ct
file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:460897)
Timeout._onTimeout
file:///C:/Users/SUDIPTA%20PAUL/OneDrive/Desktop/Projects/chatpdf-yt/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js (1:458100)
listOnTimeout
node:internal/timers (573:17)
process.processTimers
node:internal/timers (514:7)

Error when interacting with chat .

error ./node_modules/@pinecone-database/pinecone/dist/utils/user-agent.js:27:22

Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@pinecone-database/pinecone/dist/utils/index.js
./node_modules/@pinecone-database/pinecone/dist/pinecone.js
./node_modules/@pinecone-database/pinecone/dist/index.js
./src/lib/context.ts
./src/app/api/chat/route.ts
./node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?absolutePagePath=C%3A%5CUsers%5CShubh%5CDesktop%5CMini%20Project%5Cchatpdf%5Csrc%5Capp%5Capi%5Cchat%5Croute.ts&page=%2Fapi%2Fchat%2Froute&appDirLoader=bmV4dC1hcHAtbG9hZGVyP25hbWU9YXBwJTJGYXBpJTJGY2hhdCUyRnJvdXRlJnBhZ2U9JTJGYXBpJTJGY2hhdCUyRnJvdXRlJmFwcFBhdGhzPSZwYWdlUGF0aD1wcml2YXRlLW5leHQtYXBwLWRpciUyRmFwaSUyRmNoYXQlMkZyb3V0ZS50cyZhcHBEaXI9QyUzQSU1Q1VzZXJzJTVDU2h1YmglNUNEZXNrdG9wJTVDTWluaSUyMFByb2plY3QlNUNjaGF0cGRmJTVDc3JjJTVDYXBwJnBhZ2VFeHRlbnNpb25zPXRzeCZwYWdlRXh0ZW5zaW9ucz10cyZwYWdlRXh0ZW5zaW9ucz1qc3gmcGFnZUV4dGVuc2lvbnM9anMmcm9vdERpcj1DJTNBJTVDVXNlcnMlNUNTaHViaCU1Q0Rlc2t0b3AlNUNNaW5pJTIwUHJvamVjdCU1Q2NoYXRwZGYmaXNEZXY9dHJ1ZSZ0c2NvbmZpZ1BhdGg9dHNjb25maWcuanNvbiZiYXNlUGF0aD0mYXNzZXRQcmVmaXg9Jm5leHRDb25maWdPdXRwdXQ9JnByZWZlcnJlZFJlZ2lvbj0mbWlkZGxld2FyZUNvbmZpZz1lMzAlM0Qh&nextConfigOutput=&preferredRegion=&middlewareConfig=e30%3D!

414: URI_TOO_LONG Code: URL_TOO_LONG ID: ...

Hi! I got this error message after deploying to vercel "414: URI_TOO_LONG Code: URL_TOO_LONG ID", everything seemed to be working until this point. Any ideas? I would appreciate your help.

Additionally I go this log from the vercel timeline "[GET] [middleware: "src/middleware"] /sign-in reason=URL_TOO_LONG, status=414, user_error=true"

This is how my "middleware.ts" implementation looks like
...
import {
clerkMiddleware,
createRouteMatcher
} from "@clerk/nextjs/server";

const isPublicRoute = createRouteMatcher(["/", "/api/webhook"]);

export default clerkMiddleware((auth, request) => {
if(!isPublicRoute(request)) {
auth().protect();
}
});

export const config = {
matcher: ["/((?!.+.[w]+$|_next).)", "/", "/(api|trpc)(.)"],
};

I am using according to my "package.json" this version for clerk

"@clerk/nextjs": "^5.0.12",

Wrong answers.

Hi there,

I'm trying to interact with the documents, but I'm getting random responses. I'm just wondering if anyone else has experienced issues related to the quality of the responses.

This seems completely random, and I don't know where it's getting that information since I haven't uploaded anything related to it.

I'm using the same context provided in the code.

Thanks.

Screenshot 2023-11-02 at 8 57 16 PM

npx drizzle-kit push:pg issue

Besides "No config path provided..." it says: "Invalid input" Either "connection String" or "host", "database" are required for database connection. I need help. Help. Thanks.

drizzle.config.ts issue

export default { driver: "pg", schema: "./src/lib/db/schema.ts", dbCredentials: { connectionString: process.env.DATABASE_URL!, }, } satisfies Config;

error in driver and connectionString
Error: Type '"pg"' is not assignable to type '"d1"'.
Object literal may only specify known properties, and 'connectionString' does not exist in type '{ wranglerConfigPath: string; dbName: string; }'.

Webpage truncated

Anybody has the issue that the chat page is truncated to be only left with the upper part of the screen?

I had this issue while coding along this tutorial and it still exists when I cloned this repo and ran it locally.

WechatIMG172

No overload matches this call.

Error:

No overload matches this call.
  Overload 1 of 2, '(value: { userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }): PgInsert<...>', gave the following error.
    Type 'void' is not assignable to type 'string | SQL<unknown> | Placeholder<string, any>'.
  Overload 2 of 2, '(values: { userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]): PgInsert<...>', gave the following error.
    Argument of type '{ fileKey: any; pdfName: any; pdfUrl: void; userId: string; }' is not assignable to parameter of type '{ userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]'.
      Object literal may only specify known properties, and 'fileKey' does not exist in type '{ userId: string | SQL<unknown> | Placeholder<string, any>; pdfName: string | SQL<unknown> | Placeholder<string, any>; pdfUrl: string | SQL<unknown> | Placeholder<...>; fileKey: string | ... 1 more ... | Placeholder<...>; id?: number | ... 2 more ... | undefined; createdAt?: Date | ... 2 more ... | undefined; }[]'.
import { db } from "@/lib/db";
import { chats } from "@/lib/db/schema";
import { loadS3IntoPinecone } from "@/lib/pinecone";
import { getS3Url } from "@/lib/s3";
import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";

// /api/create-chat
export async function POST(req: Request, res: Response) {
  const { userId } = await auth();
  if (!userId) {
    return NextResponse.json({ error: "unauthorized" }, { status: 401 });
  }
  try {
    const body = await req.json();
    const { file_key, file_name } = body;
    console.log(file_key, file_name);
    await loadS3IntoPinecone(file_key);
    const chat_id = await db
      .insert(chats)
      .values({
        fileKey: file_key,
        pdfName: file_name,
        pdfUrl: getS3Url(file_key),
        userId,
      })
      .returning({
        insertedId: chats.id,
      });

    return NextResponse.json(
      {
        chat_id: chat_id[0].insertedId,
      },
      { status: 200 }
    );
  } catch (error) {
    console.error(error);
    return NextResponse.json(
      { error: "internal server error" },
      { status: 500 }
    );
  }
}

Error upserting chunk [PineconeError]

I am getting this error

Error upserting chunk [PineconeError: PineconeClient: Error calling upsert: PineconeError: The requested feature 'Namespaces' is not supported by the current
index type 'Starter'.]

Here is my code for the namespace:
const namespace = convertToAscii(fileKey);
PineconeUtils.chunkedUpsert(pineconeIndex, vectors, namespace, 10)

And here is the code for the convert to Ascii

export function convertToAscii(inputString: string) {
// remove non-ASCII characters
const asciiString = inputString.replace(/[^\x00-\x7F]+/g, "");
return asciiString;
}

What do you think might be wrong?

pinecone database redirect url [object object] error

After the vectors inserted into pinecone the page is being redirected but i can't understand that the chat is pushed into database or not.
The URL is like http://localhost:3000/chat/[object%20Object] instead of http://localhost:3000/chat/1 like in video tutorial of Elliott-Chong.

I want to clear my self that the chat is being pushed into database or not and why the URL is different for me ?

Subscription.ts error

I was following your video step by step and i made it until the end but .. i got this error

src\lib\subscription.ts (13:29) @ async checkSubscription

11 | }
12 |

13 | const _userSubscriptions = await db
| ^
14 | .select()
15 | .from(userSubscriptions)
16 | .where(eq(userSubscriptions.userId, userId));

Issues uploading pdf

Hi Elliott

there are some issues i came across and i cant solve it by my self. I'm learning from u

image

and this is the console error that i get :
Error: could not download from s3
at loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:38:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37)
uploads/1694257515896Converted_Amazon.pdf Converted_Amazon.pdfdownloading s3 into file system
Error: ENOENT: no such file or directory, open '/tmp/pdf-1694257516460.pdf'
at Object.openSync (node:fs:601:3)
at Object.writeFileSync (node:fs:2249:35)
at downloadFromS3 (webpack-internal:///(rsc)/./src/lib/s3-server.ts:29:51)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:36:23)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: '/tmp/pdf-1694257516460.pdf'
}
Error: could not download from s3
at loadS3IntoPinecone (webpack-internal:///(rsc)/./src/lib/pinecone.ts:38:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async POST (webpack-internal:///(rsc)/./src/app/api/create-chat/route.ts:31:9)
at async eval (webpack-internal:///(rsc)/./node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37)
(node:8964) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

Please migrate your code to use AWS SDK for JavaScript (v3).
For more information, check the migration guide at https://a.co/7PzMCcy
(Use node --trace-warnings ... to show where the warning was created)

on the site i also get this following errors :

image
image

Thanks for your support

How to add deletion based on the chatID

Hi,

I want to add the deletion button beside the chat message, but it seems like the deletion doesn't work for the server. Anyone know how to write the correct function for the deletion in chatsideBar.tsx

This is the function I created for deletion, it actually show Chat deleted successfully, however the server side and database remain the same value.
image
Any suggestions?

Memory leak

while running this project i found there is a memory leak

Error 301 Redirect in AWS S3

Error 1:

  • event compiled client and server successfully in 2.2s (2594 modules)
    uploads/1699211543893CCMEI-49690000000150.pdf CCMEI-49690000000150.pdf
    downloading s3 into file system
    PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    at throwDefaultError (C:\Users\kalil\chatpdf-yt\node_modules@smithy\smithy-client\dist-cjs\default-error-handler.js:8:22)
    at C:\Users\kalil\chatpdf-yt\node_modules@smithy\smithy-client\dist-cjs\default-error-handler.js:18:39
    at de_GetObjectCommandError (C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\client-s3\dist-cjs\protocols\Aws_restXml.js:4330:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async C:\Users\kalil\chatpdf-yt\node_modules@smithy\middleware-serde\dist-cjs\deserializerMiddleware.js:7:24
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-signing\dist-cjs\awsAuthMiddleware.js:14:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@smithy\middleware-retry\dist-cjs\retryMiddleware.js:27:46
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-flexible-checksums\dist-cjs\flexibleChecksumsMiddleware.js:63:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-sdk-s3\dist-cjs\region-redirect-endpoint-middleware.js:14:24
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-sdk-s3\dist-cjs\region-redirect-middleware.js:9:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-logger\dist-cjs\loggerMiddleware.js:7:26
    at async eval (webpack-internal:///(rsc)/./src/lib/s3-server.ts:25:25) {
    '$fault': 'client',
    '$metadata': {
    httpStatusCode: 301,
    requestId: 'BN7JTW2P1NK235RP',
    extendedRequestId: 'P5G9UMk7/CcxGZeT+S8XL2Pd8/xhmBjpnEGXUkSF8P+wyRVqXkT74rcmUCnV6V477NSstvx8MXc=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
    },
    Code: 'PermanentRedirect',
    Endpoint: 'pdfconversa-yt.s3-us-west-2.amazonaws.com',
    Bucket: 'pdfconversa-yt',
    RequestId: 'BN7JTW2P1NK235RP',
    HostId: 'P5G9UMk7/CcxGZeT+S8XL2Pd8/xhmBjpnEGXUkSF8P+wyRVqXkT74rcmUCnV6V477NSstvx8MXc='
    }
    PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.
    at throwDefaultError (C:\Users\kalil\chatpdf-yt\node_modules@smithy\smithy-client\dist-cjs\default-error-handler.js:8:22)
    at C:\Users\kalil\chatpdf-yt\node_modules@smithy\smithy-client\dist-cjs\default-error-handler.js:18:39
    at de_GetObjectCommandError (C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\client-s3\dist-cjs\protocols\Aws_restXml.js:4330:20)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async C:\Users\kalil\chatpdf-yt\node_modules@smithy\middleware-serde\dist-cjs\deserializerMiddleware.js:7:24
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-signing\dist-cjs\awsAuthMiddleware.js:14:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@smithy\middleware-retry\dist-cjs\retryMiddleware.js:27:46
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-flexible-checksums\dist-cjs\flexibleChecksumsMiddleware.js:63:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-sdk-s3\dist-cjs\region-redirect-endpoint-middleware.js:14:24
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-sdk-s3\dist-cjs\region-redirect-middleware.js:9:20
    at async C:\Users\kalil\chatpdf-yt\node_modules@aws-sdk\middleware-logger\dist-cjs\loggerMiddleware.js:7:26
    at async eval (webpack-internal:///(rsc)/./src/lib/s3-server.ts:25:25) {
    '$fault': 'client',
    '$metadata': {
    httpStatusCode: 301,
    requestId: 'BN7JTW2P1NK235RP',
    extendedRequestId: 'P5G9UMk7/CcxGZeT+S8XL2Pd8/xhmBjpnEGXUkSF8P+wyRVqXkT74rcmUCnV6V477NSstvx8MXc=',
    cfId: undefined,
    attempts: 1,
    totalRetryDelay: 0
    },
    Code: 'PermanentRedirect',
    Endpoint: 'pdfconversa-yt.s3-us-west-2.amazonaws.com',
    Bucket: 'pdfconversa-yt',
    RequestId: 'BN7JTW2P1NK235RP',
    HostId: 'P5G9UMk7/CcxGZeT+S8XL2Pd8/xhmBjpnEGXUkSF8P+wyRVqXkT74rcmUCnV6V477NSstvx8MXc='
    }
  • wait compiling...
  • event compiled client and server successfully in 968 ms (2267 modules)

In console:
image

I get the error and then I go to upload page again.

Error 2:
Also getting some Hydratation errors, but it does not seem critical.

Unhandled Runtime Error
Error: Hydration failed because the initial UI does not match what was rendered on the server.

Warning: Expected server HTML to contain a matching

in .

See more info here: https://nextjs.org/docs/messages/react-hydration-error

Has anyone faced similar issues?

[Error: ENOENT: no such file or directory, open 'C:\tmp\elliott1695549520613.pdf'] {

Screenshot (7)
facing issue with this..
[Error: ENOENT: no such file or directory, open 'C:\tmp\elliott1695549520613.pdf'] {
errno: -4058,
code: 'ENOENT',
syscall: 'open',
path: 'C:\tmp\elliott1695549520613.pdf'
}

  • error uncaughtException: [Error: ENOENT: no such file or directory, open 'C:\tmp\elliott1695549520613.pdf'] {
    digest: undefined
    }
    TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11576:11)
    at async invokeRequest (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\server\lib\server-ipc\invoke-request.js:17:12)
    at async invokeRender (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\server\lib\router-server.js:254:29)
    at async handleRequest (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\server\lib\router-server.js:447:24)
    at async requestHandler (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\server\lib\router-server.js:464:13)
    at async Server. (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\server\lib\start-server.js:117:13) {
    cause: HeadersTimeoutError: Headers Timeout Error
    at Timeout.onParserTimeout [as callback] (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\compiled\undici\index.js:1:62578)
    at Timeout.onTimeout [as _onTimeout] (C:\Users\sauna\Downloads\chatpdf-yt-main (1)\chatpdf-yt-main\node_modules\next\dist\compiled\undici\index.js:2:269659)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7) {
    code: 'UND_ERR_HEADERS_TIMEOUT'
    }
    }
    pls tell what to do

Inserting vectors into Pinecone

console.log('inserting vectors into Pinecone');

    const namespace = pineconeIndex.namespace(convertToAscii(filekey));

    console.log("inserting vectors into pinecone");
    await namespace.upsert(vectors);

    return documents[0];  

i have tried using this but its throwing error i pass vectors in upsert():

'PineconeRecord<RecordMetadata>'.
    Types of property 'metadata' are incompatible.
      Type 'object | undefined' is not assignable to type 'RecordMetadata | undefined'.
        Type 'object' is not assignable to type 'RecordMetadata'.
          Index signature for type 'string' is missing in type '{}'.

Error creating chat

Screenshot (14)
Failed to load resource: the server responded with a status of 401 (Unauthorized)

Delete messages features

We would like to have a delete button when we are done chatting with the PDF we want to delete it

Content of .env ?

The Readme says:
Create a .env file in the root directory of your project and add the required environment variables.

Unfortunately there is no information which variables should be set . Error messages indicate that NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
CLERK_SECRET_KEY should be set. A DATABASE_URL seems also to be required, but I have no idea which value should be set there. Are this all required variables or are there others still missing?

Error: failed to pipe response

When i ask any question to my pdf doc i got this error :

Error: aborted
at connResetException (node:internal/errors:720:14)
at abortIncoming (node:_http_server:793:17)
at socketOnClose (node:_http_server:787:3)
at Socket.emit (node:events:526:35)
at TCP. (node:net:337:12)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNRESET'
}
⨯ uncaughtException: Error: aborted
at connResetException (node:internal/errors:720:14)
at abortIncoming (node:_http_server:793:17)
at socketOnClose (node:_http_server:787:3)
at Socket.emit (node:events:526:35)
at TCP. (node:net:337:12)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNRESET'
}
⨯ uncaughtException: Error: aborted
at connResetException (node:internal/errors:720:14)
at abortIncoming (node:_http_server:793:17)
at socketOnClose (node:_http_server:787:3)
at Socket.emit (node:events:526:35)
at TCP. (node:net:337:12)
at TCP.callbackTrampoline (node:internal/async_hooks:130:17) {
code: 'ECONNRESET'
}
⨯ Error: failed to pipe response
at pipeToNodeResponse (/Users/jordy/Desktop/chat-pdf/node_modules/next/dist/server/pipe-readable.js:106:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async DevServer.runEdgeFunction (/Users/jordy/Desktop/chat-pdf/node_modules/next/dist/server/next-server.js:1214:13)
at async NextNodeServer.handleCatchallRenderRequest (/Users/jordy/Desktop/chat-pdf/node_modules/next/dist/server/next-server.js:242:37)
at async DevServer.handleRequestImpl (/Users/jordy/Desktop/chat-pdf/node_modules/next/dist/server/base-server.js:751:17) {
[cause]: Error: Response error: {
"error": {
"message": "{'0': {'role': 'user', 'content': 'De quoi parle le document ?'}, 'prompt': {'role': 'system', 'content': 'AI assistant is a brand new, powerful, human-like artificial intelligence.\n The traits of AI include expert knowledge, helpfulness, cleverness, and articulateness.\n AI is a wel
at Object.start (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:100:42)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
}

Can you help me please?

TypeError: messagesRef.current.concat is not a function

Im getting this issue but I dont see where messagesRef is being used. I have tried changing initialMessages to initialMessages: !Array.isArray(data) || [], , but the ai messages and the user messages dont get saved to the database.

`"use client";
import React from "react";
import { Input } from "./ui/input";
import { useChat } from "ai/react";
import { Button } from "./ui/button";
import { Send } from "lucide-react";
import MessageList from "./MessageList";
import { useQuery } from "@tanstack/react-query";
import axios from "axios";
import { Message } from "ai";

type Props = { chatId: number };

const ChatComponent = ({ chatId }: Props) => {
const { data, isLoading } = useQuery({
queryKey: ["chat", chatId],
queryFn: async () => {
const response = await axios.post<Message[]>("/api/get-messages", {
chatId,
});
return response.data;
},
});

const { input, handleInputChange, handleSubmit, messages } = useChat({
api: "/api/chat",
body: {
chatId,
},
initialMessages: data || [],
});
React.useEffect(() => {
const messageContainer = document.getElementById("message-container");
if (messageContainer) {
messageContainer.scrollTo({
top: messageContainer.scrollHeight,
behavior: "smooth",
});
}
}, [messages]);
return (


{/* header */}

Chat


  {/* message list */}
  <MessageList messages={messages} isLoading={isLoading} />

  <form
    onSubmit={handleSubmit}
    className="sticky bottom-0 inset-x-0 px-2 py-4 bg-white"
  >
    <div className="flex">
      <Input
        value={input}
        onChange={handleInputChange}
        placeholder="Ask any question..."
        className="w-full"
      />
      <Button className="bg-blue-600 ml-2">
        <Send className="h-4 w-4" />
      </Button>
    </div>
  </form>
</div>

);
};

export default ChatComponent;`

`import { Configuration, OpenAIApi } from "openai-edge";
import { Message, OpenAIStream, StreamingTextResponse } from "ai";
import { getContext } from "@/lib/context";
import { db } from "@/lib/db";
import { chats, messages as _messages } from "@/lib/db/schema";
import { eq } from "drizzle-orm";
import { NextResponse } from "next/server";

export const runtime = "edge";

const config = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(config);

export async function POST(req: Request) {
try {
const { messages, chatId } = await req.json();
const _chats = await db.select().from(chats).where(eq(chats.id, chatId));
if (_chats.length != 1) {
return NextResponse.json({ error: "chat not found" }, { status: 404 });
}
const fileKey = _chats[0].fileKey;
const lastMessage = messages[messages.length - 1];
const context = await getContext(lastMessage.content, fileKey);

const prompt = {
  role: "system",
  content: `AI assistant is a brand new, powerful, human-like artificial intelligence.
  The traits of AI include expert knowledge, helpfulness, cleverness, and articulateness.
  AI is a well-behaved and well-mannered individual.
  AI is always friendly, kind, and inspiring, and he is eager to provide vivid and thoughtful responses to the user.
  AI has the sum of all knowledge in their brain, and is able to accurately answer nearly any question about any topic in conversation.
  AI assistant is a big fan of Pinecone and Vercel.
  START CONTEXT BLOCK
  ${context}
  END OF CONTEXT BLOCK
  AI assistant will take into account any CONTEXT BLOCK that is provided in a conversation.
  If the context does not provide the answer to question, the AI assistant will say, "I'm sorry, but I don't know the answer to that question".
  AI assistant will not apologize for previous responses, but instead will indicated new information was gained.
  AI assistant will not invent anything that is not drawn directly from the context.
  `,
};

const response = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [
    prompt,
    ...messages.filter((message: Message) => message.role === "user"),
  ],
  stream: true,
});
const stream = OpenAIStream(response, {
  onStart: async () => {
    // save user message into db
    await db.insert(_messages).values({
      chatId,
      content: lastMessage.content,
      role: "user",
    });
  },
  onCompletion: async (completion) => {
    // save ai message into db
    await db.insert(_messages).values({
      chatId,
      content: completion,
      role: "system",
    });
  },
});
return new StreamingTextResponse(stream);

} catch (error) {}
}`

`import {
integer,
pgEnum,
pgTable,
serial,
text,
timestamp,
varchar,
} from "drizzle-orm/pg-core";

export const userSystemEnum = pgEnum("user_system_enum", ["system", "user"]);

export const chats = pgTable("chats", {
id: serial("id").primaryKey(),
pdfName: text("pdf_name").notNull(),
pdfUrl: text("pdf_url").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
userId: varchar("user_id", { length: 256 }).notNull(),
fileKey: text("file_key").notNull(),
});

export type DrizzleChat = typeof chats.$inferSelect;

export const messages = pgTable("messages", {
id: serial("id").primaryKey(),
chatId: integer("chat_id")
.references(() => chats.id)
.notNull(),
content: text("content").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
role: userSystemEnum("role").notNull(),
});

export const userSubscriptions = pgTable("user_subscriptions", {
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 256 }).notNull().unique(),
stripeCustomerId: varchar("stripe_customer_id", { length: 256 })
.notNull()
.unique(),
stripeSubscriptionId: varchar("stripe_subscription_id", { length: 256 })
.notNull()
.unique(),
stripePriceId: varchar("stripe_price_id", { length: 256 }),
stripeCurrentPeriodEnd: timestamp("stripe_current_period_end"),
});
`

`import { Pinecone } from "@pinecone-database/pinecone";
import { convertToAscii } from "./utils";
import { getEmbeddings } from "./embeddings";

export async function getMatchesFromEmbeddings(
embeddings: number[],
fileKey: string
) {
const apiKey = process.env.PINECONE_API_KEY;

const pinecone = new Pinecone({
apiKey: apiKey!,
});

const index = await pinecone.Index("papertalk");

try {
const namespace = convertToAscii(fileKey);
const queryResponse = await index.namespace(namespace).query({
vector: embeddings,
topK: 5,
includeMetadata: true,
});

return queryResponse.matches || [];

} catch (error) {
console.log("error querying embeddings", error);
throw error;
}
}

export async function getContext(query: string, fileKey: string) {
const queryEmbeddings = await getEmbeddings(query);
const matches = await getMatchesFromEmbeddings(queryEmbeddings, fileKey);

const qualifyingDocs = matches.filter(
(match) => match.score && match.score > 0.7
);

type Metadata = {
text: string,
pageNumbe: number
}

let docs = qualifyingDocs.map(match => (match.metadata as Metadata).text)

return docs.join("\n").substring(0,3000)
}
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.