Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chat and messaging with openai 4o llm implementation #27

Merged
merged 24 commits into from
Nov 9, 2024

Conversation

Nyumat
Copy link
Member

@Nyumat Nyumat commented Nov 7, 2024

new tables and extensions to the database, updating dependencies, and implementing new chat-related features in the backend and frontend. lfg. 🗣️

Database Schema Updates:

  • Added new tables chats, messages, document_chunks, and embeddings along with necessary foreign key constraints in prisma/migrations/20241106184235_chats_messages/migration.sql.
  • Updated prisma/schema.prisma to include new models and extensions for vector.

Dependencies Updates:

  • Updated package.json to add new dependencies like @ai-sdk/openai, @langchain/core, pgvector, and others.

Configuration Changes:

  • Updated docker-compose.yml to use ankane/pgvector:latest image and added a new volume for initialization scripts.
  • Updated next.config.ts to include api.dicebear.com in the images.domains list.

Backend Features:

  • Implemented a new API route src/app/api/chat/route.ts for handling chat messages, including user authentication, message processing, and interaction with OpenAI's 4o model.

Note

This is just the first step in implementation. We still need to integrate the pinecone vector db work done in (#19) into the system.

It will take some query, compare the embedding to all course material documents, and return the K=1 most relevant document to the LLM, which will stream the response to the Next.js client.

Frontend Features:

  • Added a new ChatArea component in src/app/chat/(render)/chat-area.tsx to handle chat UI, message input, and image attachments.

@Nyumat Nyumat self-assigned this Nov 7, 2024
@Nyumat Nyumat linked an issue Nov 7, 2024 that may be closed by this pull request
@Nyumat Nyumat force-pushed the nyumat/full-stack-chats branch from bdabd97 to 751634d Compare November 7, 2024 10:03
@Nyumat
Copy link
Member Author

Nyumat commented Nov 7, 2024

Going to secure the code real quick, we need protected routes to avoid exposing resources to non-OSU students

@cshafizadeh
Copy link
Contributor

@Nyumat out of curiosity, are we storing the document chunks and the embeddings in a SQL database as well as in pinecone?

@Nyumat
Copy link
Member Author

Nyumat commented Nov 8, 2024

@Nyumat out of curiosity, are we storing the document chunks and the embeddings in a SQL database as well as in pinecone?

Good question. I initially was thinking that if we store our chunks, and embeddings as vectors alongside our core data model, we'd have a tighter integration for more complex use cases, like those outlined in the planning doc from week 2:

Some of the stuff in the doc:

  • upvote downvote ai responses
  • ai generated quizzes based on course content
  • top notes from rubric, compare assignments to the rubric

But after thinking about the work you did, along with just how complex it'd be to hack prisma into supporting vectors — I think it's best centering our RAG approach around Pinecone.

I'll update the data model to go back to what is was before. Thanks for asking that question and providing me some retrospective.

@cshafizadeh
Copy link
Contributor

@Nyumat out of curiosity, are we storing the document chunks and the embeddings in a SQL database as well as in pinecone?

Good question. I initially was thinking that if we store our chunks, and embeddings as vectors alongside our core data model, we'd have a tighter integration for more complex use cases, like those outlined in the planning doc from week 2:

Some of the stuff in the doc:

  • upvote downvote ai responses
  • ai generated quizzes based on course content
  • top notes from rubric, compare assignments to the rubric

But after thinking about the work you did, along with just how complex it'd be to hack prisma into supporting vectors — I think it's best centering our RAG approach around Pinecone.

I'll update the data model to go back to what is was before. Thanks for asking that question and providing me some retrospective.

Yeah no problem, Im not against storing the documents in a second db. it would allow us to easily upload the document to pinecone if they are already broken into chunks, and it would be a backup incase something happened to the vector db or we wanted to switch platforms. Ill try to take a look over the weekend at the updated UI you built and look into integrating the embeddings into sending messages. I looked at the UI from the last push and it looks great!

@Nyumat Nyumat merged commit d6badff into main Nov 9, 2024
1 check passed
@Nyumat Nyumat deleted the nyumat/full-stack-chats branch November 9, 2024 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Design the Application Data Model
2 participants