mlim-usfca / PersonalKnowledge

https://personal-knowledge.vercel.app
0 stars 0 forks source link

Chatbot with RAG+LLM with auth and file upload functionality #14

Closed hazalsenturk closed 5 months ago

hazalsenturk commented 6 months ago

P.S: Please remember to start your supabase container from the project dir locally.!!

Description: The functionality of RAG based chat bot using gpt3.5 through OPENAI API. The program is ready to be run in the /rag directory. It has the authentication with mock email verification, uploading file feature through a simple UI, and chat feature to ask questions to the files uploaded. Currently the models's temperature is set to 0 and the agent is configured to answer solely questions based on the documents uploaded. It uses no creativity considering this being personalized and answering solely from user's knowledge-base.

Changes:

Dependencies and pre-req: In order to run this on your local device please follow the below instructions and let me know if you encounter an issue. Probably I already went through that:)

  1. Make sure the following is installed:

    • Docker
    • Node.js 18+
  2. Dependencies: Installations through npm and brew. If not using these please find related package manager commands. Run them in order specifically the ones related to supabase.

    • Pull the changes from the repo and cd into '/rag' directory
      
      npm install next react react-dom
      npm install
      npx supabase start
      npx supabase status -o env \
      --override-name api.url=NEXT_PUBLIC_SUPABASE_URL \
      --override-name auth.anon_key=NEXT_PUBLIC_SUPABASE_ANON_KEY |
      grep NEXT_PUBLIC > .env.local

brew install deno npm i @xenova/transformers ai

cat > supabase/functions/.env <<- EOF OPENAI_API_KEY= EOF


How to run:
It is configured to be run on localhost:3000
`npm run dev`

Useful commands: 
In case you make **local** changes on supabase db some useful commands: 
!! For cloud deployment the commands are different.
- To push the migrations: `npx supabase migration up`
- To serve functions: `npx supabase functions serve`
- To reset the supabase db: `supabase db reset`
- To get the supabase status(including studio link): `supabase status` 

Future work and notes:
1- Version does not have the functionality for LLM model plugin. This should be provided by taking the model form a config. Caution to see if for generate_message for the chat can be done in the same manner for all models. 
2- This contains UI component and Auth on supabase. The team members responsible for these functionality needs to revise and adopt the features based on their design. Can remove as well if this does not serve your purpose.  @GuoFan1996 @Huimin22 
3- Chat UI needs to be redesigned/integrated/removed based on the DragonAI design. @TanyaaCJain @cemtu 
4- This runs on local so if it is going to be moved to the cloud changes will be made.
5- All these dependency installations and run commands can be scripted at the end.

Please revise the code, run for yourself and provide feedback. You can use sample files in sample_files directory or can experiment with your own files. Cheers!
Huimin22 commented 6 months ago

In the rag/app directory, the auth folder can be removed as we can directly utilize Supabase's authentication service. We need to integrate third-party login authentication services on the login page. Currently, we do not require user registration functionality.

hazalsenturk commented 6 months ago

In the rag/app directory, the auth folder can be removed as we can directly utilize Supabase's authentication service. We need to integrate third-party login authentication services on the login page. Currently, we do not require user registration functionality.

Thanks for the comments Huimin! :) If I understoody your concerns right, the auth in here is done through Supabase. I would highly recommend reading the code. Once this code is reviewed, the following changes, like deletions/insertions and new features are supposed to not to break the current build. Regarding user functionality, we have a sign up functionality- it is supposed to be there since we are providing user based service. Please let me know if you have further questions.. Or please feel free to leave further feedback.

hazalsenturk commented 6 months ago

Dragons please make sure you pull the code and play around on your local. To both experiment around the feature and to get used to running the app :)

inhwaS commented 5 months ago

Hazal, can you please remove /firebase and /hausra directory in this pull request? I just made PR to remove them so it would be better to remove in this PR too

inhwaS commented 5 months ago

Quick question, so this version is using supabase local, not Cem's supabase containers, right?

hazalsenturk commented 5 months ago

Hazal, can you please remove /firebase and /hausra directory in this pull request? I just made PR to remove them so it would be better to remove in this PR too

I suggest keeping the tasks separate. While creating my issue I created this one to clean up this irrelevant content https://github.com/mlim-usfca/PersonalKnowledge/issues/13

@inhwaS @cemtu please follow up with: https://github.com/mlim-usfca/PersonalKnowledge/issues/13

inhwaS commented 5 months ago

Hazal, can you please remove /firebase and /hausra directory in this pull request? I just made PR to remove them so it would be better to remove in this PR too

I suggest keeping the tasks separate. While creating my issue I created this one to clean up this irrelevant content https://github.com/mlim-usfca/PersonalKnowledge/issues/13

@inhwaS @cemtu please follow up with: https://github.com/mlim-usfca/PersonalKnowledge/issues/13

this link does

Hazal, can you please remove /firebase and /hausra directory in this pull request? I just made PR to remove them so it would be better to remove in this PR too

I suggest keeping the tasks separate. While creating my issue I created this one to clean up this irrelevant content https://github.com/mlim-usfca/PersonalKnowledge/issues/13

@inhwaS @cemtu please follow up with: https://github.com/mlim-usfca/PersonalKnowledge/issues/13

I see! I will follow up that issue

hazalsenturk commented 5 months ago

Quick question, so this version is using supabase local, not Cem's supabase containers, right?

Great question! The thing is Supabase is even in local running on Docker. So in our local we are running on container. Only difference is we will be running our individual set during dev. But once we deploy- which Cem was talking about- we will be running somehow somewhere:) a Supabase container and all the changes we make upon deployment will be available on that hosted components such as tables, migrations etc.

inhwaS commented 5 months ago

Also, when I run your version, I think I issued OpenAI API key but having trouble with Authentication. Do we need another API key for authentication?

There is a step in the PR that you are supposed to copy and save supabase params as url and anon key to a .env.local file (see the command in the PR).

If you can share the error it would be useful. :)

inhwaS commented 5 months ago

Quick question, so this version is using supabase local, not Cem's supabase containers, right?

Great question! The thing is Supabase is even in local running on Docker. So in our local we are running on container. Only difference is we will be running our individual set during dev. But once we deploy- which Cem was talking about- we will be running somehow somewhere:) a Supabase container and all the changes we make upon deployment will be available on that hosted components such as tables, migrations etc.

Yes, this version of supabase runs on docker containers but still need to download Supabase through npx. Based on this request-response communication, @TanyaaCJain and @Huimin22 can refer how web can communicate with Supabase then :)

Yeap yeap they will still be developing on their local. Will test their website on localhost. Which if you realize to run this chabot you do npm run dev and go to your localhost:3000(I configured can change the port). They will do the same to see the changes. Then we will host this, we will deploy , link a domain etc.

inhwaS commented 5 months ago

Also, when I run your version, I think I issued OpenAI API key but having trouble with Authentication. Do we need another API key for authentication?

There is a step in the PR that you are supposed to copy and save supabase params as url and anon key to a .env.local file (see the command in the PR).

If you can share the error it would be useful. :)

Access to fetch at 'http://127.0.0.1:54321/functions/v1/chat' from origin 'http://localhost:3000/' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. 127.0.0.1:54321/functions/v1/chat:1

   Failed to load resource: net::ERR_FAILED