Feature/sentiment analysis#62
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughThis PR adds automatic sentiment classification to user ratings. A new sentiment analysis library computes sentiment labels from review text and optional ratings, the database schema adds a ChangesSentiment Analysis Feature
Sequence DiagramsequenceDiagram
participant Client
participant POST_api_ratings as "POST /api/ratings"
participant analyzeSentiment
participant Supabase
Client->>POST_api_ratings: POST {comment, rating}
POST_api_ratings->>analyzeSentiment: analyzeSentiment(text, overallRating)
analyzeSentiment-->>POST_api_ratings: SentimentResult {label, score}
POST_api_ratings->>Supabase: INSERT ratings {sentiment_label, ...}
Supabase-->>POST_api_ratings: Created rating row
POST_api_ratings-->>Client: {id, sentimentLabel, displayDate}
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/lib/sentiment.tsParsing error: The keyword 'import' is reserved Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/lib/sentiment.ts (1)
13-13: 💤 Low valueHandle missing text more explicitly.
Using
text || ''as a fallback silently treatsnull,undefined, or empty strings the same way. When text is missing, the sentiment will be based solely on the rating (if provided), which may be intentional. However, making this explicit would improve clarity.💡 Consider making the fallback more explicit
- const { comparative } = analyzer.analyze(text || ''); + // When no text is provided, sentiment is based on rating only + const { comparative } = analyzer.analyze(text ?? '');🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/lib/sentiment.ts` at line 13, The line using analyzer.analyze(text || '') should be made explicit about missing text: check whether text is null/undefined/empty before calling analyzer.analyze and only call analyzer.analyze when there is actual text; otherwise set comparative (or sentiment score) to a clear default (e.g., 0) or derive it solely from rating. Update the code around analyzer.analyze and the variable comparative to branch on a hasText check so the behavior is explicit (use analyzer.analyze(text) when hasText, else assign the chosen default comparative and document the branch).scripts/add_sentiment.sql (1)
13-15: ⚖️ Poor tradeoffConsider leaving historical ratings as NULL instead of 'neutral'.
The backfill sets all existing ratings to
'neutral'without analyzing their actual sentiment. Since the constraint permits NULL values, consider leaving historical ratings as NULL to distinguish between "analyzed as neutral" vs "not yet analyzed."Alternatively, if you want to backfill with analyzed values, you could write a script to recompute sentiment for existing ratings based on their comment and rating_metrics.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/add_sentiment.sql` around lines 13 - 15, The current backfill unconditionally sets existing rows to 'neutral' (UPDATE ratings SET sentiment_label = 'neutral' WHERE sentiment_label IS NULL;), which hides whether a rating was actually analyzed; either remove this UPDATE so historical sentiment_label values remain NULL, or replace it with a proper recomputation step that derives labels from the rating content (e.g., call your sentiment computation routine against comment and rating_metrics and UPDATE ratings SET sentiment_label = <computed_label> WHERE sentiment_label IS NULL); locate the UPDATE in scripts/add_sentiment.sql and implement the chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@scripts/add_sentiment.sql`:
- Around line 13-15: The current backfill unconditionally sets existing rows to
'neutral' (UPDATE ratings SET sentiment_label = 'neutral' WHERE sentiment_label
IS NULL;), which hides whether a rating was actually analyzed; either remove
this UPDATE so historical sentiment_label values remain NULL, or replace it with
a proper recomputation step that derives labels from the rating content (e.g.,
call your sentiment computation routine against comment and rating_metrics and
UPDATE ratings SET sentiment_label = <computed_label> WHERE sentiment_label IS
NULL); locate the UPDATE in scripts/add_sentiment.sql and implement the chosen
approach.
In `@src/lib/sentiment.ts`:
- Line 13: The line using analyzer.analyze(text || '') should be made explicit
about missing text: check whether text is null/undefined/empty before calling
analyzer.analyze and only call analyzer.analyze when there is actual text;
otherwise set comparative (or sentiment score) to a clear default (e.g., 0) or
derive it solely from rating. Update the code around analyzer.analyze and the
variable comparative to branch on a hasText check so the behavior is explicit
(use analyzer.analyze(text) when hasText, else assign the chosen default
comparative and document the branch).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8fda3d0b-beeb-4839-a2e3-80e2d5b028ec
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (5)
package.jsonscripts/add_sentiment.sqlsrc/lib/sentiment.tssrc/pages/api/ratings/route.tssrc/types/supabase.ts
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
Summary
Closes #42
Added sentiment analysis for course/professor reviews.
Changes
Added
src/lib/sentiment.tswith sentiment utility using thesentimentnpm package, andscripts/add_sentiment.sqlwith migration to addsentiment_labelcolumn to theratingstable.How it works
Combines text analysis with optional numeric rating (60/40 weight). Returns
positive,negative, orneutrallabel.Integration
Call
analyzeSentiment(comment, ratingMetrics.overall)inPOST /api/ratingsbefore insert, store result insentiment_label.Notes
Thresholds and weights are heuristic. As a higher-accuracy alternative,
@huggingface/inferencewithdistilbert-base-uncased-finetuned-sst-2-englishcould be used (requires addingHF_API_TOKENto env).Summary by CodeRabbit
New Features
Chores