fix: remove html from AI prompt#598
Conversation
|
@Vicentesan is attempting to deploy a commit to the Zero Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedThe pull request is closed. WalkthroughThis pull request enhances email processing by making the Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/mail/actions/ai-reply.ts(3 hunks)apps/mail/actions/ai-search.ts(1 hunks)apps/mail/actions/ai.ts(2 hunks)apps/mail/lib/ai.ts(4 hunks)apps/mail/lib/groq.ts(0 hunks)
💤 Files with no reviewable changes (1)
- apps/mail/lib/groq.ts
🧰 Additional context used
🧬 Code Definitions (2)
apps/mail/actions/ai-reply.ts (1)
apps/mail/lib/ai.ts (1)
stripHtmlTags(149-187)
apps/mail/lib/ai.ts (1)
apps/mail/lib/groq.ts (2)
createEmbeddings(132-146)generateCompletions(168-278)
🔇 Additional comments (10)
apps/mail/actions/ai.ts (2)
42-42: Code style improvement.The added whitespace improves readability by properly separating the error handling section from the subsequent API call.
61-61: Code style improvement.The added whitespace improves readability by properly separating the email responses filtering from the content cleaning logic.
apps/mail/actions/ai-search.ts (1)
57-60: Removal of debug logging improves code quality.The PR cleaned up the code by removing console.log statements that were used for debugging purposes. This is good practice for production code as it prevents unnecessary logging and keeps the output clean.
apps/mail/actions/ai-reply.ts (3)
6-6: Added import for HTML tag stripping functionality.The new import brings in the
stripHtmlTagsutility function from the AI module, supporting the goal of removing HTML from AI prompts.
10-12: Key implementation: HTML tag removal from email threads.This change addresses the core issue in the PR by stripping HTML tags from thread content before processing, resulting in cleaner text input for the AI to work with. This is a critical improvement that should lead to better AI-generated content.
46-46: Code style improvement.Added whitespace improves readability by separating logical sections of the code.
apps/mail/lib/ai.ts (4)
1-1: Enhanced import to support embedding generation.Updated import to include
createEmbeddingsalongsidegenerateCompletions, which is used in the new embedding functionality to improve AI context awareness.
79-107: Added embedding generation for improved AI context awareness.This significant enhancement creates embeddings from relevant context sources (current email, user prompt, and recent conversation history), enabling the AI to better understand the conversational context when generating responses. The implementation includes proper error handling to continue without embeddings if generation fails.
115-117: Updated generateCompletions call to include embeddings.Improved the API call by passing the generated embeddings to the AI model, which enhances the contextual understanding for more relevant responses. Also fixed a max_tokens parameter that may have been modified as part of this change.
149-187: Added comprehensive stripHtmlTags utility function.This well-implemented utility function:
- Removes HTML style and script tags completely
- Replaces common HTML entities with their text equivalents
- Strips all remaining HTML tags
- Normalizes whitespace and fixes common formatting issues
- Adds appropriate line breaks for better readability
The implementation is thorough and handles various edge cases. This function is a key part of the PR's goal to remove HTML from AI prompts.
| prompt, | ||
| temperature: 0.7, | ||
| max_tokens: 500 | ||
| }) | ||
| }); |
There was a problem hiding this comment.
Fixed syntax error in generateCompletions call.
Added a missing comma after the prompt parameter, correcting what would have been a syntax error. This is an important fix for proper function operation.
apps/mail/lib/ai.ts
Outdated
| // Fixed bug: was using formatEmailContent.toString() instead of formattedContent | ||
| formattedContent = stripHtmlTags(formattedContent).trim(); | ||
|
|
There was a problem hiding this comment.
Fixed content cleaning bug in formatEmailContent.
This change fixes a significant bug where the function was incorrectly using formatEmailContent.toString() instead of the actual formattedContent variable, and applies the new stripHtmlTags function to ensure the email content is properly cleaned of HTML.
|
converted to draft cuz AI-search isn't working |
|
it isnt your fault. lets ship and worry about ai search after |
i actually think i might be... just saw a log and its returning a hole email instead of the filter |
|
trying to understand why now |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/mail/components/mail/search-bar.tsx (1)
885-932: Consider using optional chaining for regex match groups and add tests for edge cases.
- You can simplify the safety checks for
quotedQueryMatchand captures by applying optional chaining, e.g.if (quotedQueryMatch?.[1]) {...}, improving readability and reducing potential defensive checks.- Additionally, test the function against unusual inputs (e.g., partial quotes, misleading phrases, or no recognized patterns) to ensure robust coverage.
🧰 Tools
🪛 Biome (1.9.4)
[error] 889-890: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
apps/mail/actions/ai-reply.ts(3 hunks)apps/mail/actions/ai-search.ts(2 hunks)apps/mail/components/mail/search-bar.tsx(3 hunks)apps/mail/lib/ai.ts(5 hunks)apps/mail/lib/groq.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- apps/mail/actions/ai-search.ts
- apps/mail/actions/ai-reply.ts
- apps/mail/lib/groq.ts
🧰 Additional context used
🧬 Code Definitions (1)
apps/mail/lib/ai.ts (1)
apps/mail/lib/groq.ts (2)
createEmbeddings(132-146)generateCompletions(168-262)
🪛 Biome (1.9.4)
apps/mail/components/mail/search-bar.tsx
[error] 889-890: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
🔇 Additional comments (6)
apps/mail/components/mail/search-bar.tsx (2)
640-640: Minor style improvement.The updated class names enhance the visual styling of the input field, improving readability and consistency with the theme. No issues found here.
201-204: Validate the fallback behavior afterextractMetaText.You gracefully handle cases where
extractMetaTextreturns undefined by defaulting to an empty string. Ensure that dropping to an empty search query is desired behavior whenextractMetaTextreturns nothing. Otherwise, consider logging or informing the user that no actionable query could be extracted.apps/mail/lib/ai.ts (4)
1-2: Import statements look correct.Using
extractTextFromHTMLfrom@/actions/extractTextand bringingcreateEmbeddings, generateCompletionsinto this file is appropriate for local usage. No changes suggested here.
80-108: Embedding strategy is logical—verify large content performance.You're generating embeddings for current content, prompt, and recent messages, which should enrich AI context. For extremely large email drafts or prompts, confirm performance remains acceptable. Consider chunking or summarizing large texts if you encounter timeouts or memory issues.
116-117: Condensing or adjusting tokens for questions is sensible.Reducing
max_tokensto 150 for queries helps tailor responses. This logic is reasonable, but ensure shorter outputs don’t cut off essential context. Keep an eye on user feedback to see if 150 tokens suffice.
150-150: Async content extraction and cleaning fix look solid.
- Changing
formatEmailContentto async allows for proper HTML extraction before trimming, which resolves past mishaps where.toString()was mistakenly used.- The call to
extractTextFromHTML(formattedContent)ensures HTML tags are stripped, improving email response clarity.No issues found with this fix.
Also applies to: 163-164
|
@Vicentesan some issues with with drafting up an email. it tend to not space things out and wont perform some requests like writing an email about someone getting fired. let's fix plz. this only happens on the create-email page. search emails is great, same with reply-composer one. only one that needs fixing is create-email |
|
working on it |
it worked with me... can u share the used prompt? |
|
not ideal but we can improve on this over the coming days |
* fix: show primary emails * (review) add "All Mail" section to inbox switcher * ph provider * perf: switch from open ai to groq api * chore: remove openai package * chore: remove duplicated function * chore: remove duplicated function * feat: use system prompt from env * perf: use base js fetch instead of better-fetch * homepage open fix * context * cleanup * cleanup * feat: update categories logic * cleanup * cleanup * feat: use nuqs * action buttons * feat: added mark as read functionality for mails * added try and catch for better error handling * better error than codeRabbit lmao * hold to scroll down emails * fix spacing on reply composer ; * spacing * tooltip to thread display bar for ux * fix to reply composer * forward emails button * cleanup * cleanup * reply ring * overflow * cleanup * un animate x * New translations en.json (French) * New translations en.json (Spanish) * New translations en.json (Arabic) * New translations en.json (Catalan) * New translations en.json (Czech) * New translations en.json (German) * New translations en.json (Japanese) * New translations en.json (Korean) * New translations en.json (Polish) * New translations en.json (Portuguese) * New translations en.json (Russian) * New translations en.json (Turkish) * New translations en.json (Latvian) * New translations en.json (Hindi) * New translations en.json (Russian) * New translations en.json (Latvian) * cleanup * loading state and padding to mail list to not overflow when scrolling * onMouseDown * fix: remove html from AI prompt (#598) * fix: remove html from AI prompt * refact: use cheerio util to remove html from email * feat: add regex to ai-search * chore: remove debug logs * refactor: migrate from groq embeddings to openai for and improve email formatting * fix: join waitlist button contrast (#603) * fix: join waitlist button contrast The old contrast was terrible in light mode, so now I just made it black so it is always readable. * Revert "regenerating bun file" This reverts parts of commit cef74f3. * Add tooltips and i18n for editor MenuBar (#604) * feat: add tooltips and i18n to editor MenuBar * fix: incorrect translation key --------- Co-authored-by: Sergio Vazquez <sergiovazag@gmail.com> Co-authored-by: plyght <plyght@peril.lol> Co-authored-by: Sergio <60497216+sergio-jva@users.noreply.github.com> Co-authored-by: Nizzy <nizabizaher@gmail.com> Co-authored-by: Vicentesan <vikom.sanchez@gmail.com> Co-authored-by: user12224 <122770437+user12224@users.noreply.github.com> Co-authored-by: Rajmeet <rajmeetchandok@gmail.com> Co-authored-by: [bot] <zero@ibra.rip> Co-authored-by: needle <122770437+needleXO@users.noreply.github.com> Co-authored-by: Dominik Koch <dominik@koch-bautechnik.de> Co-authored-by: YK <70700647+yaraslau-klimuk@users.noreply.github.com>



What Changed
This PR introduces several improvements to the email processing system in the
apps/maildirectory:stripHtmlTagsutility function inai-reply.tsto clean HTML tags from email threads before AI processinglib/ai.tsto improve context awareness in AI responseslib/groq.tsto clean up the codebaseWhy This Change Matters
Areas Affected
Notes for Reviewers
This change focuses on improving the quality of AI-generated email responses while cleaning up the codebase. No breaking changes are introduced, and all existing functionality should continue to work as expected.
Related Issues
https://www.loom.com/share/32e08357c70545569016fc0c8e61740a?sid=2553d5d6-f5cf-4b65-b27c-2e21b66c9543

Summary by CodeRabbit
New Features
Bug Fixes