Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/app/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ def _answer_direct_fact_question(question: str, context: dict[str, Any]) -> str
"in monthly dividend income to reach your target."
)

if "progress" in normalized and ("goal" in normalized or "target" in normalized):
asks_progress = "progress" in normalized or "tracking" in normalized
if asks_progress and ("goal" in normalized or "target" in normalized):
return (
f"You are {context['progress_percent']:.2f}% of the way to your "
f"{_format_currency(context['monthly_target'])}/month target."
Expand Down
21 changes: 21 additions & 0 deletions backend/tests/test_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ def test_answer_portfolio_question_answers_current_monthly_income_directly(
self.assertEqual(answer, "Your current monthly dividend income is $10.20.")
mock_post.assert_not_called()

@patch("app.ai._portfolio_context")
@patch("app.ai.requests.post")
def test_answer_portfolio_question_answers_goal_tracking_directly(
self,
mock_post,
mock_portfolio_context,
) -> None:
mock_portfolio_context.return_value = {
"monthly_income": 10.2,
"annual_income": 122.4,
"monthly_target": 5000,
"progress_percent": 0.2,
"remaining_monthly_income": 4989.8,
"holdings": [{"ticker": "SCHD"}],
}

answer = answer_portfolio_question("How am I tracking toward my goal?")

self.assertEqual(answer, "You are 0.20% of the way to your $5,000.00/month target.")
mock_post.assert_not_called()

@patch("app.ai._portfolio_context")
@patch("app.ai._get_openrouter_headers")
@patch("app.ai.requests.post")
Expand Down