fix(api): avoid distinct on json product fields in shopping suggestions
This commit is contained in:
parent
fecfa0b9e4
commit
cebea2ac86
2 changed files with 21 additions and 4 deletions
|
|
@ -1082,12 +1082,12 @@ def suggest_shopping(session: Session = Depends(get_session)):
|
|||
raise HTTPException(status_code=502, detail=f"LLM returned invalid JSON: {e}")
|
||||
|
||||
# Get products with inventory (those user already owns)
|
||||
products_with_inventory = session.exec(
|
||||
select(Product).join(ProductInventory).distinct()
|
||||
products_with_inventory_ids = session.exec(
|
||||
select(ProductInventory.product_id).distinct()
|
||||
).all()
|
||||
|
||||
shopping_context = ShoppingValidationContext(
|
||||
owned_product_ids=set(p.id for p in products_with_inventory),
|
||||
owned_product_ids=set(products_with_inventory_ids),
|
||||
valid_categories=set(ProductCategory),
|
||||
valid_targets=set(SkinConcern),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -87,6 +87,23 @@ def test_suggest_shopping(client, session):
|
|||
with patch(
|
||||
"innercontext.api.products.call_gemini_with_function_tools"
|
||||
) as mock_gemini:
|
||||
product = Product(
|
||||
id=uuid.uuid4(),
|
||||
short_id=str(uuid.uuid4())[:8],
|
||||
name="Owned Serum",
|
||||
brand="BrandX",
|
||||
category="serum",
|
||||
recommended_time="both",
|
||||
leave_on=True,
|
||||
product_effect_profile={},
|
||||
)
|
||||
session.add(product)
|
||||
session.commit()
|
||||
session.add(
|
||||
ProductInventory(id=uuid.uuid4(), product_id=product.id, is_opened=True)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
mock_response = type(
|
||||
"Response",
|
||||
(),
|
||||
|
|
@ -94,7 +111,7 @@ def test_suggest_shopping(client, session):
|
|||
"text": '{"suggestions": [{"category": "cleanser", "product_type": "cleanser", "priority": "high", "key_ingredients": [], "target_concerns": [], "why_needed": "reason", "recommended_time": "am", "frequency": "daily"}], "reasoning": "Test shopping"}'
|
||||
},
|
||||
)
|
||||
mock_gemini.return_value = mock_response
|
||||
mock_gemini.return_value = (mock_response, None)
|
||||
|
||||
r = client.post("/products/suggest")
|
||||
assert r.status_code == 200
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue