-
Notifications
You must be signed in to change notification settings - Fork 0
Cut Gemini cost: default to flash-lite + optional reply drafting #39
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Unit tests for analyze_email system-prompt assembly. | ||
|
|
||
| These are deterministic (no Gemini API needed) and verify that the | ||
| cost-saving feature flags actually drop their prompt sections. | ||
| """ | ||
| from assistant.event_extractor import build_system_prompt | ||
|
|
||
|
|
||
| def test_full_prompt_includes_all_sections(): | ||
| prompt = build_system_prompt(extract_action_items=True, draft_replies=True) | ||
| assert "CALENDAR:" in prompt | ||
| assert "REPLY:" in prompt | ||
| assert "ACTION ITEMS:" in prompt | ||
| assert "CONTEXT:" in prompt | ||
|
|
||
|
|
||
| def test_draft_replies_off_drops_reply_section(): | ||
| prompt = build_system_prompt(extract_action_items=True, draft_replies=False) | ||
| assert "REPLY:" not in prompt | ||
| # Everything else is retained. | ||
| assert "CALENDAR:" in prompt | ||
| assert "ACTION ITEMS:" in prompt | ||
| assert "CONTEXT:" in prompt | ||
|
|
||
|
|
||
| def test_action_items_off_drops_action_section(): | ||
| prompt = build_system_prompt(extract_action_items=False, draft_replies=True) | ||
| assert "ACTION ITEMS:" not in prompt | ||
| assert "REPLY:" in prompt | ||
|
|
||
|
|
||
| def test_both_off_leaves_calendar_and_context_only(): | ||
| prompt = build_system_prompt(extract_action_items=False, draft_replies=False) | ||
| assert "REPLY:" not in prompt | ||
| assert "ACTION ITEMS:" not in prompt | ||
| assert "CALENDAR:" in prompt | ||
| assert "CONTEXT:" in prompt | ||
|
|
||
|
|
||
| def test_sections_are_renumbered_contiguously(): | ||
| # With both optional sections off, the two remaining sections must be | ||
| # numbered "1." and "2." — no gaps that would confuse the model. | ||
| prompt = build_system_prompt(extract_action_items=False, draft_replies=False) | ||
| assert "1. CALENDAR:" in prompt | ||
| assert "2. CONTEXT:" in prompt |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
draft_repliesis set toFalse, theREPLYsection is omitted from the system prompt. However, theEmailAnalysisPydantic model (used as theresponse_schemafor Gemini) definesneeds_replyas a required boolean field:Because it is required, the Gemini model is forced to output
needs_replyin the JSON response, even though the system prompt contains no instructions or context on how to evaluate it. This can lead to unpredictable model behavior, validation errors, or arbitrary/hallucinated values.To resolve this, please update the
EmailAnalysisclass (around line 122) to provide a default value forneeds_reply: