""" Generates English fashion sentences to enrich the Router Agent dataset. Uses GPT-4o-mini to generate sentences for each of the 5 classes (product, sales, support, account, bugs) specific to the fashion/clothing domain. The product/sales sentences use clothing types specific to the Amazon Fashion catalog (dress, boots, shoes, shirt, bag, jeans, sandals, hoodie, skirt) with real attributes (colors, materials, gender) to maximize the semantic proximity both to the user's Italian queries and to the English products in the catalog. Output: artifacts/fashion_examples.json Format: [{"query": "...", "route": "product"}, ...] The sentences must be reviewed manually before being integrated into the FAISS index (pipeline/6_build_router_index.py). """ import json import os import re import sys # Add project root to the path to import utils sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from langchain_openai import ChatOpenAI from utils.config import LLM_MODEL_NAME, ARTIFACTS_DIR llm = ChatOpenAI(model=LLM_MODEL_NAME, temperature=0.9) # high temperature for variety OUTPUT_PATH = os.path.join(ARTIFACTS_DIR, "fashion_examples.json") # Clothing types specific to the Amazon Fashion catalog. # Chosen to maximize the match between Italian queries and English products. FASHION_ITEMS = [ "dress", "red dress", "black dress", "evening dress", "summer dress", "women's dress", "boots", "leather boots", "ankle boots", "winter boots", "women's boots", "men's boots", "shoes", "women's shoes", "men's shoes", "black shoes", "running shoes", "casual shoes", "t-shirt", "men's t-shirt", "women's t-shirt", "cotton t-shirt", "graphic t-shirt", "shirt", "dress shirt", "flannel shirt", "button-down shirt", "men's shirt", "bag", "handbag", "leather bag", "women's handbag", "crossbody bag", "tote bag", "jeans", "men's jeans", "women's jeans", "skinny jeans", "high-waist jeans", "sandals", "women's sandals", "summer sandals", "flat sandals", "leather sandals", "hoodie", "zip-up hoodie", "pullover hoodie", "men's hoodie", "fleece hoodie", "skirt", "black skirt", "mini skirt", "pleated skirt", "women's skirt", "jacket", "leather jacket", "denim jacket", "winter jacket", "bomber jacket", "coat", "winter coat", "trench coat", "wool coat", "women's coat", "sweater", "cashmere sweater", "knit sweater", "turtleneck sweater", "sneakers", "white sneakers", "men's sneakers", "casual sneakers", "heels", "high heels", "stiletto heels", "block heels", "women's heels", ] # Prompt for each class — specific to fashion/clothing CLASS_PROMPTS = { "product": """Generate {n} unique English sentences that a customer would type in a fashion e-commerce chatbot when SEARCHING FOR or BROWSING fashion products. These are people who want to FIND and LOOK AT products. IMPORTANT: The sentences must express the intent of SEARCHING, LOOKING FOR, WANTING, or BROWSING products. They should sound like someone typing a search query or asking to see products. You MUST use these specific fashion items (spread them evenly across sentences): {items} Examples of what to generate: - "I'm looking for a red dress for a party" - "Show me women's leather boots" - "I need a cotton t-shirt for men" - "Do you have black high heels?" - "I want a leather handbag" - "Looking for men's jeans size 32" - "Can you show me summer sandals?" - "I need a hoodie with a zip" - "Show me black skirts" - "women's running shoes" - "red dress size M" - "men's leather boots" Rules: - Each sentence on a new line, numbered 1-{n} - The sentence must express SEARCHING or WANTING a product - Use the fashion items listed above — every item must appear at least once - Include attributes: colors (red, black, white, blue, green, brown), sizes (S, M, L, XL, 38, 40, 42), materials (leather, cotton, silk, wool, denim), gender (men's, women's), occasions (party, wedding, casual, work, summer, winter) - Mix long and short forms: "I'm looking for a red dress" AND "red dress size M" AND "women's leather boots" - NO returns, NO shipping, NO account questions, NO website bugs - Just the sentence, no quotes""", "sales": """Generate {n} unique English sentences that a customer would type in a fashion e-commerce chatbot when asking about BUYING, AVAILABILITY, PRICES, DEALS, or DISCOUNTS on fashion items. These are people ready to purchase or asking about purchasing conditions. You MUST use these specific fashion items (spread them evenly across sentences): {items} Examples of what to generate: - "How much does this red dress cost?" - "Are these leather boots on sale?" - "Is this cotton t-shirt available in large?" - "Any discounts on women's handbags?" - "When will you restock men's jeans in size 32?" - "What's the price of those summer sandals?" - "I want to buy this hoodie, is it in stock?" - "Are there any deals on black skirts this week?" - "Do you have a coupon for sneakers?" Rules: - Each sentence on a new line, numbered 1-{n} - Focus on: buying intent, prices, availability, stock, discounts, sales, deals, coupons, new arrivals, restocking - Use the fashion items listed above — every item must appear at least once - Mix formal and informal tone - NO returns, NO shipping, NO account questions, NO website bugs - Just the sentence, no quotes""", "support": """Generate {n} unique English sentences that a customer would type in a fashion e-commerce chatbot when asking about CUSTOMER SUPPORT: shipping, returns, refunds, exchanges, order tracking, delivery problems. IMPORTANT: Focus on the SUPPORT ACTION (returning, exchanging, tracking, shipping), NOT on describing the product. Mention product names only briefly if at all. Examples of what to generate: - "How do I return an item that doesn't fit?" - "Can I exchange this for a different size?" - "How long does standard shipping take?" - "My order arrived damaged, what should I do?" - "Where's my package? It's been two weeks" - "What's your return policy?" - "Can I get a refund if I changed my mind?" - "Do you offer free shipping?" Rules: - Each sentence on a new line, numbered 1-{n} - Cover: returns, exchanges, refunds, shipping times, tracking, damaged orders, wrong items, delivery issues, return policy, shipping costs - Keep product references MINIMAL - say "item", "order", "package" instead of specific product names - The focus should be on the PROCESS (returning, shipping, tracking), not on the product - Mix formal and informal tone - NO product search, NO account/password questions, NO website bugs - Just the sentence, no quotes""", "account": """Generate {n} unique English sentences that a customer would type in a fashion e-commerce chatbot when asking about ACCOUNT MANAGEMENT: login, password, profile, payment methods, addresses, order history, wishlist. IMPORTANT: Focus on the ACCOUNT ACTION (logging in, changing password, updating profile), NOT on products. Examples of what to generate: - "I forgot my password and can't log in" - "How do I update my shipping address?" - "I want to delete my account" - "How do I view my past orders?" - "Can I change my email address?" - "My login isn't working" - "How do I add a new credit card?" Rules: - Each sentence on a new line, numbered 1-{n} - Cover: login issues, password reset, profile updates, payment methods, saved addresses, order history, wishlist, notifications, preferences, account deletion, email changes - Keep product references MINIMAL - focus on account operations - Mix formal and informal tone - NO product search, NO shipping/returns, NO website bugs - Just the sentence, no quotes""", "bugs": """Generate {n} unique English sentences that a customer would type in a fashion e-commerce chatbot when REPORTING WEBSITE/APP BUGS or technical problems. IMPORTANT: Focus on the TECHNICAL ISSUE (crashing, not loading, error message), NOT on products. Mention UI elements generically. Examples of what to generate: - "The website keeps crashing when I try to checkout" - "The search bar isn't working" - "I'm getting an error when I try to add items to cart" - "The page won't load on my phone" - "Images aren't displaying properly" - "The filter options are broken" - "I keep getting a 404 error" Rules: - Each sentence on a new line, numbered 1-{n} - Cover: crashes, loading issues, error messages, broken features, display problems, mobile bugs, cart issues, checkout errors, search problems, filter bugs - Keep product references MINIMAL - say "page", "filter", "images" instead of specific product names - The focus should be on the TECHNICAL PROBLEM, not on the product - Mix formal and informal tone - NO product search, NO shipping/returns, NO account questions - Just the sentence, no quotes""", } # Sentences per class: more for product/sales (critical classes for fashion routing) EXAMPLES_PER_CLASS = { "product": 200, "sales": 200, "support": 100, "account": 100, "bugs": 100, } def parse_numbered_list(text): """Extracts the sentences from a numbered list generated by the LLM.""" lines = text.strip().split("\n") sentences = [] for line in lines: line = line.strip() if not line: continue # Remove numbering (1. , 1) , 1- , etc.) cleaned = re.sub(r"^\d+[\.\)\-\:]\s*", "", line).strip() # Remove quotes cleaned = cleaned.strip('"').strip("'") if cleaned and len(cleaned) > 5: sentences.append(cleaned) return sentences def generate_short_product_queries(): """Generates short deterministic (keyword-style) sentences for product and sales. Systematic combinations of product + attribute that are semantically very close to the Italian queries in the multilingual embedding. E.g.: "green t-shirt" is close to "maglietta verde" in the multilingual space. """ products = [ "dress", "t-shirt", "shirt", "boots", "shoes", "sandals", "sneakers", "heels", "jeans", "skirt", "jacket", "coat", "sweater", "hoodie", "bag", "handbag", "scarf", "belt", "hat", "shorts", "pants", "blouse", "cardigan", "vest", "leggings", "jumpsuit", "romper", "blazer", ] colors = ["red", "black", "white", "blue", "green", "brown", "pink", "gray", "beige", "navy"] genders = ["women's", "men's"] materials = ["leather", "cotton", "silk", "wool", "denim", "linen", "suede", "velvet"] intents_product = [ "I'm looking for a {color} {product}", "Show me {gender} {product}", "I need a {product} for {occasion}", "I want a {color} {product}", "Looking for {gender} {color} {product}", "{color} {product}", "{gender} {product}", "{material} {product}", "{color} {material} {product}", "{gender} {color} {product}", "I'm searching for a {product}", "Do you have {color} {product}?", "Can you show me {product}?", ] intents_sales = [ "How much is this {color} {product}?", "Is this {product} on sale?", "Any discounts on {gender} {product}?", "What's the price of that {product}?", "Is this {color} {product} in stock?", ] occasions = ["a party", "work", "summer", "winter", "a wedding", "casual wear", "a date"] import random as _rnd _rnd.seed(42) product_queries = [] sales_queries = [] # Generate product combinations for template in intents_product: for _ in range(15): q = template.format( color=_rnd.choice(colors), product=_rnd.choice(products), gender=_rnd.choice(genders), material=_rnd.choice(materials), occasion=_rnd.choice(occasions), ) product_queries.append(q) # Generate sales combinations for template in intents_sales: for _ in range(15): q = template.format( color=_rnd.choice(colors), product=_rnd.choice(products), gender=_rnd.choice(genders), ) sales_queries.append(q) # Deduplicate product_queries = list(dict.fromkeys(product_queries)) sales_queries = list(dict.fromkeys(sales_queries)) return product_queries, sales_queries def generate_examples(): all_examples = [] items_str = ", ".join(FASHION_ITEMS) for intent_class, prompt_template in CLASS_PROMPTS.items(): n = EXAMPLES_PER_CLASS[intent_class] print(f"\n--- Generating class '{intent_class}' ({n} LLM sentences)... ---") prompt = prompt_template.format(n=n, items=items_str) response = llm.invoke(prompt) sentences = parse_numbered_list(response.content) print(f" Obtained {len(sentences)} sentences") # Show the first 5 as a preview for s in sentences[:5]: print(f" - {s}") if len(sentences) > 5: print(f" ... and {len(sentences) - 5} more") for sentence in sentences: all_examples.append({ "query": sentence, "route": intent_class, }) # Add short deterministic (keyword-style) sentences short_product, short_sales = generate_short_product_queries() print(f"\n--- Short deterministic sentences ---") print(f" product: {len(short_product)}") print(f" sales: {len(short_sales)}") for q in short_product: all_examples.append({"query": q, "route": "product"}) for q in short_sales: all_examples.append({"query": q, "route": "sales"}) # Final statistics print(f"\n--- Total sentences generated: {len(all_examples)} ---") from collections import Counter counts = Counter(e["route"] for e in all_examples) for cls, count in sorted(counts.items()): print(f" {cls}: {count}") # Save with open(OUTPUT_PATH, "w", encoding="utf-8") as f: json.dump(all_examples, f, indent=2, ensure_ascii=False) print(f"\n--- Saved to {OUTPUT_PATH} ---") print(f"Review the file, then run pipeline/6_build_router_index.py to rebuild the index.") if __name__ == "__main__": generate_examples()