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(chatMessages): add brain_id and prompt_id columns #912

Merged
merged 2 commits into from
Aug 10, 2023
Merged

Conversation

mamadoudicko
Copy link
Contributor

@mamadoudicko mamadoudicko commented Aug 9, 2023

Description

  • Update chat_history table
  • Update some entities and DTOs
  • Update chat controller

@mamadoudicko mamadoudicko temporarily deployed to preview August 9, 2023 15:47 — with GitHub Actions Inactive
@vercel
Copy link

vercel bot commented Aug 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2023 7:53am
quivrapp ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 10, 2023 7:53am

@github-actions
Copy link
Contributor

github-actions bot commented Aug 9, 2023

Risk Level 2 - /home/runner/work/quivr/quivr/backend/core/models/databases/supabase/chats.py

The code is generally well written, but there are a few areas that could be improved:

  1. The update_chat_history method uses string conversion for UUIDs. This could potentially lead to issues if the UUID is not valid. Consider adding error handling for this.

  2. The update_chat_history method also directly inserts the input dictionary into the database. This could potentially lead to SQL injection attacks if the input is not properly sanitized. Consider using parameterized queries or ensuring that the input is properly sanitized.


Risk Level 2 - /home/runner/work/quivr/quivr/backend/core/repository/chat/update_chat_history.py

The function update_chat_history does not handle the case where supabase_db.update_chat_history(chat_history) fails and does not return a response. This could lead to an AttributeError when trying to access the data attribute of None. Consider adding error handling for this case. For example:

response = supabase_db.update_chat_history(chat_history)
if response is None or len(response.data) == 0:
    raise HTTPException(
        status_code=500, detail=\"An exception occurred while updating chat history.\"
    )

This will ensure that an appropriate error is raised when the update operation fails.


Risk Level 3 - /home/runner/work/quivr/quivr/backend/core/routes/chat_routes.py

  1. The function create_question_handler has a high cyclomatic complexity due to multiple conditional checks and could be simplified for better readability and maintainability. Consider refactoring the code to reduce complexity.

  2. The function delete_chat_from_db suppresses all exceptions and just prints them. This could lead to silent failures that are hard to debug. Consider re-raising the exception or handling specific exceptions that you expect may occur.

  3. The function check_user_limit has a pass statement in the else clause which is unnecessary and can be removed for cleaner code.

  4. The function create_stream_question_handler has duplicate code for retrieving the user's OpenAI API key and chat model. Consider refactoring this into a separate function to adhere to the DRY (Don't Repeat Yourself) principle.


🔒🐛🔄


Powered by Code Review GPT



def get_brain_prompt_id(brain_id: UUID) -> UUID | None:
if not brain_id:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but brain_id is typed as UUID in the input props

user_message: str
assistant: str
message_time: str
prompt_title: Optional[str] = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not at the chatHistory level, its at the message level no ? a chat history could be generated using multiple brains in the future

supabase_db = get_supabase_db()
history: List[ChatHistory] = supabase_db.get_chat_history(chat_id).data
history: List[dict] = supabase_db.get_chat_history(chat_id).data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why dict instead of ChatHistory ?

@@ -23,7 +23,9 @@ CREATE TABLE IF NOT EXISTS chat_history (
user_message TEXT,
assistant TEXT,
message_time TIMESTAMP DEFAULT current_timestamp,
PRIMARY KEY (chat_id, message_id)
PRIMARY KEY (chat_id, message_id),
prompt_id UUID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prompt_id and brain_id should reference the prompts and brains table respectively, can be null

Copy link
Contributor

@gozineb gozineb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reference prompts and brains tables in chat_history

BEGIN
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'chat_history' AND column_name = 'brain_id') THEN
-- Add brain_id column
ALTER TABLE chat_history ADD COLUMN brain_id UUID;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference brains table

IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'chat_history' AND column_name = 'prompt_id') THEN
-- Add prompt_id column
ALTER TABLE chat_history ADD COLUMN prompt_id UUID;
END IF;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reference prompts table

Copy link
Contributor

@gozineb gozineb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing references to tables in migration script

Copy link
Contributor

@gozineb gozineb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bien vuuuu

@gozineb gozineb merged commit 6e77732 into main Aug 10, 2023
6 of 7 checks passed
StanGirard pushed a commit that referenced this pull request Sep 12, 2023
* feat: add prompt_id and brain_id to chat history)

* feat: add prompt_id and brain_id to chat routes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants