Update nutrition score retrieval using OFF v2 REST API and title cleaning
This commit is contained in:
8
backend/scripts/check_stores.py
Normal file
8
backend/scripts/check_stores.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import sys
|
||||
sys.path.insert(0, ".")
|
||||
from app.services.store_db import list_stores
|
||||
|
||||
stores = list_stores()
|
||||
print("Stores in DB:")
|
||||
for s in stores:
|
||||
print(f" - {s['store_id']}: {s['store_name']} ({s.get('city')}) [{s.get('tier')}]")
|
||||
34
backend/scripts/fast_test.py
Normal file
34
backend/scripts/fast_test.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, ".")
|
||||
from app.services.rag_service import retrieve, answer_query
|
||||
from app.services.query_intent import extract_max_price, extract_brand_mention, is_count_query, detected_category
|
||||
|
||||
print("=== Q1: How many products are there in Cadbury? ===")
|
||||
print(" Is Count:", is_count_query("How many products are there in Cadbury?"))
|
||||
print(" Brand Mention:", extract_brand_mention("How many products are there in Cadbury?"))
|
||||
print(" Category:", detected_category("How many products are there in Cadbury?"))
|
||||
|
||||
print("\n=== Q2: Suggest panner less than ₹100 ===")
|
||||
print(" Is Count:", is_count_query("Suggest panner less than ₹100"))
|
||||
print(" Brand Mention:", extract_brand_mention("Suggest panner less than ₹100"))
|
||||
print(" Category:", detected_category("Suggest panner less than ₹100"))
|
||||
print(" Max Price:", extract_max_price("Suggest panner less than ₹100"))
|
||||
q2_prods = retrieve("Suggest panner less than ₹100")
|
||||
for p in q2_prods:
|
||||
print(f" - [{p.brand}] {p.product_name} | Price: {p.price_range} | Category: {p.category}")
|
||||
|
||||
print("\n=== Q3: Recommend Paneer under ₹150 ===")
|
||||
print(" Is Count:", is_count_query("Recommend Paneer under ₹150"))
|
||||
print(" Brand Mention:", extract_brand_mention("Recommend Paneer under ₹150"))
|
||||
print(" Category:", detected_category("Recommend Paneer under ₹150"))
|
||||
print(" Max Price:", extract_max_price("Recommend Paneer under ₹150"))
|
||||
q3_prods = retrieve("Recommend Paneer under ₹150")
|
||||
for p in q3_prods:
|
||||
print(f" - [{p.brand}] {p.product_name} | Price: {p.price_range} | Category: {p.category}")
|
||||
|
||||
print("\n=== Q4: Suggest low sugar biscuits ===")
|
||||
print(" Category:", detected_category("Suggest low sugar biscuits"))
|
||||
q4_prods = retrieve("Suggest low sugar biscuits")
|
||||
for p in q4_prods:
|
||||
print(f" - [{p.brand}] {p.product_name} | Price: {p.price_range} | Category: {p.category}")
|
||||
@@ -43,8 +43,22 @@ def main() -> None:
|
||||
"--only", nargs="*", default=None,
|
||||
help="Optional list of brand names (case-insensitive substring match on filename) to limit seeding to",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-if-seeded", action="store_true",
|
||||
help="Skip seeding if database already contains products",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.skip_if_seeded:
|
||||
from app.services.vector_store import count_products_all_brands
|
||||
try:
|
||||
cnt = count_products_all_brands()
|
||||
if cnt > 0:
|
||||
logger.info("⚡ Database already contains %d products. Skipping sample data seed.", cnt)
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not SEED_DIR.exists():
|
||||
logger.error("Seed directory not found: %s", SEED_DIR)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -34,8 +34,19 @@ def main() -> None:
|
||||
parser.add_argument("--days", type=int, default=90, help="Days of order history to simulate (default: 90)")
|
||||
parser.add_argument("--seed", type=int, default=42, help="Random seed for reproducible store/order generation")
|
||||
parser.add_argument("--no-reset-orders", action="store_true", help="Append to existing order history instead of clearing it first")
|
||||
parser.add_argument("--skip-if-seeded", action="store_true", help="Skip if stores are already provisioned")
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.skip_if_seeded:
|
||||
from app.services.store_db import list_stores
|
||||
try:
|
||||
stores = list_stores()
|
||||
if stores and len(stores) >= 5:
|
||||
logger.info("⚡ Stores already provisioned (%d stores). Skipping store intelligence seed.", len(stores))
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
from app.services.store_seed_service import run_seed
|
||||
|
||||
logger.info("Seeding store intelligence (days=%d, seed=%d, reset_orders=%s)...", args.days, args.seed, not args.no_reset_orders)
|
||||
|
||||
30
backend/scripts/test_rag.py
Normal file
30
backend/scripts/test_rag.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import sys
|
||||
from app.services.rag_service import retrieve, answer_query
|
||||
from app.services.query_intent import extract_max_price, extract_brand_mention, is_count_query
|
||||
|
||||
def run_test():
|
||||
queries = [
|
||||
"How many products are there in Cadbury?",
|
||||
"Suggest low sugar biscuits",
|
||||
"Recommend Paneer under ₹150",
|
||||
"Suggest panner less than ₹100",
|
||||
]
|
||||
|
||||
for q in queries:
|
||||
print("="*60)
|
||||
print(f"QUERY: {q}")
|
||||
print(f" Is Count: {is_count_query(q)}")
|
||||
print(f" Brand Mention: {extract_brand_mention(q)}")
|
||||
print(f" Max Price: {extract_max_price(q)}")
|
||||
|
||||
prods = retrieve(q)
|
||||
print(" Retrieved Products:")
|
||||
for p in prods[:5]:
|
||||
print(f" - {p.brand} | {p.product_name} | Price: {p.price_range} | Cat: {p.category}")
|
||||
|
||||
ans = answer_query(q)
|
||||
print(f" ANSWER:\n{ans.answer}")
|
||||
print("="*60)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_test()
|
||||
12
backend/scripts/test_rag_response.py
Normal file
12
backend/scripts/test_rag_response.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import sys
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
sys.path.insert(0, ".")
|
||||
from app.services.rag_service import answer_query
|
||||
|
||||
res = answer_query("Recommend a low sugar biscuit")
|
||||
print("=== RAG ANSWER ===")
|
||||
print(res.answer)
|
||||
print("=== SOURCES FOUND ===")
|
||||
print(len(res.sources))
|
||||
for p in res.sources[:3]:
|
||||
print(f" - {p.product_name} ({p.brand}) - {p.price_range}")
|
||||
Reference in New Issue
Block a user