Skip to content

Fix/better ai - #294

Merged
driedpampas merged 9 commits into
mainfrom
fix/better-ai
May 26, 2026
Merged

Fix/better ai#294
driedpampas merged 9 commits into
mainfrom
fix/better-ai

Conversation

@iuliaaa20

@iuliaaa20 iuliaaa20 commented May 26, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores

    • More frequent global catalog population and lowered minimum distinct-user threshold so popular products appear sooner.
  • New Features / Improvements

    • AI now enforces a recipe quantity rule and applies catalog-based quantity/unit normalization for recipe items.
    • Product resolution captures catalog default quantities for better normalization.
  • Tests

    • Added/expanded tests for quantity/unit conversion and recipe vs non-recipe normalization.

Review Change Stack

@iuliaaa20
iuliaaa20 requested a review from a team as a code owner May 26, 2026 14:32
@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e9619f01-ef7a-45df-8a44-d3539d9c0844

📥 Commits

Reviewing files that changed from the base of the PR and between 825f88a and a99b0cb.

📒 Files selected for processing (1)
  • src/main/java/com/p2ps/ai/service/AiOrchestrationService.java

📝 Walkthrough

Walkthrough

Adds RECIPE-aware quantity/unit normalization across AI orchestration and product resolution (with QuantityParser.convertToUnit and Unit.symbol), updates AiService prompt, extends tests, and lowers the global catalog population threshold while changing its scheduled fixedRate.

Changes

AI Recipe Quantity Normalization

Layer / File(s) Summary
Orchestration and normalization changes
src/main/java/com/p2ps/ai/service/AiOrchestrationService.java
Propagates a recipeList flag and applies recipe-aware quantity/unit normalization when a ProductCatalog is available.
QuantityParser API changes
src/main/java/com/p2ps/util/QuantityParser.java
Adds Unit.symbol() and convertToUnit(sourceQuantity, targetQuantityTemplate) to parse and convert quantities between same unit families and return formatted target-unit strings.
Prompt update and ProductCatalog defaultQuantity
src/main/java/com/p2ps/ai/service/AiService.java, src/main/java/com/p2ps/catalog/service/ProductResolutionService.java
Adds a RECIPE quantity rule to the system prompt and populates ProductCatalog.defaultQuantity from user-history matches.
Unit tests for normalization and conversion
src/test/java/com/p2ps/ai/service/AiOrchestrationServiceTest.java, src/test/java/com/p2ps/util/QuantityParserTest.java
Adds tests verifying RECIPE conversion to catalog default quantity/unit, no rounding up behavior, preservation for non-RECIPE lists, and cross-family conversion errors.

Catalog Population Threshold Update

Layer / File(s) Summary
Configuration threshold & schedule
src/main/resources/application.properties, src/main/java/com/p2ps/catalog/service/GlobalCatalogPopulationJob.java
Default catalog.population.min-distinct-users lowered from 3 to 1 and @Scheduled(fixedRate=...) expression updated to 60*3*60000.

Sequence Diagram

sequenceDiagram
  participant AiService
  participant AiOrchestrationService
  participant ProductResolutionService
  participant QuantityParser
  AiService->>AiOrchestrationService: send structured list (listType, items)
  AiOrchestrationService->>ProductResolutionService: applyResolvedProduct(item, recipeList)
  ProductResolutionService->>QuantityParser: convertToUnit(sourceQty, catalogDefaultQty)
  QuantityParser-->>ProductResolutionService: converted quantity string
  ProductResolutionService-->>AiOrchestrationService: resolved item with normalized qty/unit
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • P2P-Shopping/server#291: Related work introducing and using ProductCatalog.defaultQuantity, which this PR reads and applies during recipe normalization.
  • P2P-Shopping/server#258: Also modifies AiService.SYSTEM_PROMPT; overlaps in prompt instruction edits.
  • P2P-Shopping/server#181: Added scheduling enablement that is directly related to the changed @Scheduled behavior in GlobalCatalogPopulationJob.

Suggested reviewers:

  • bmbianca
  • Bianca-Alexandru
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Fix/better ai' is vague and does not clearly convey the specific changes made; it lacks detail about what aspects of AI functionality were improved or fixed. Consider a more descriptive title that specifies the key improvements, such as 'Improve AI quantity normalization for recipes' or 'Enhance catalog-based quantity conversion for recipe items'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/better-ai

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/main/java/com/p2ps/catalog/service/GlobalCatalogPopulationJob.java`:
- Line 14: Update the test in GlobalCatalogPopulationJobTest to reflect the
changed default minDistinctUsers from 3 to 1: locate the setUp that calls
ReflectionTestUtils.setField(globalCatalogPopulationJob, "minDistinctUsers", 3)
and change the value to 1 (or remove the ReflectionTestUtils.setField call to
rely on the real default), and update the assertion in
populateGlobalCatalogShouldDelegateToService to verify
globalCatalogPopulationService.populateFromPopularUnknownProducts(1) instead of
3; ensure the test still constructs globalCatalogPopulationJob and calls
populateGlobalCatalog() before the verify.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e4e3939-1f8e-45bd-9f6c-6f95de151f83

📥 Commits

Reviewing files that changed from the base of the PR and between da3bfe7 and 6eee8d3.

📒 Files selected for processing (2)
  • src/main/java/com/p2ps/catalog/service/GlobalCatalogPopulationJob.java
  • src/main/resources/application.properties

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@src/main/java/com/p2ps/ai/service/AiOrchestrationService.java`:
- Line 163: The equality check for recipeList uses response.getListType()
directly, which fails on surrounding whitespace; update the logic in
AiOrchestrationService where recipeList is set (the boolean recipeList =
"RECIPE".equalsIgnoreCase(response.getListType())) to trim the list type first
(e.g., obtain a trimmed value from response.getListType().trim() or call trim()
inline before equalsIgnoreCase) so values like " RECIPE " are normalized and the
RECIPE conversion path is not skipped.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9a5c0704-af4e-41f3-924d-4f55ae21ae4a

📥 Commits

Reviewing files that changed from the base of the PR and between 6eee8d3 and 825f88a.

📒 Files selected for processing (8)
  • src/main/java/com/p2ps/ai/service/AiOrchestrationService.java
  • src/main/java/com/p2ps/ai/service/AiService.java
  • src/main/java/com/p2ps/catalog/service/GlobalCatalogPopulationJob.java
  • src/main/java/com/p2ps/catalog/service/ProductResolutionService.java
  • src/main/java/com/p2ps/util/QuantityParser.java
  • src/main/resources/application.properties
  • src/test/java/com/p2ps/ai/service/AiOrchestrationServiceTest.java
  • src/test/java/com/p2ps/util/QuantityParserTest.java
✅ Files skipped from review due to trivial changes (1)
  • src/main/resources/application.properties

Comment thread src/main/java/com/p2ps/ai/service/AiOrchestrationService.java Outdated
@sonarqubecloud

Copy link
Copy Markdown

@driedpampas
driedpampas merged commit 9a8c162 into main May 26, 2026
4 checks passed
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.

2 participants