# # test_llm.py # """ # Test harness for StyleSavvy LLM prompts. # Defines multiple prompt templates and evaluates the generated outputs, # checking for the expected number of bullet-point style tips. # """ # from models.llm import StyleSavvy # # Variant prompt templates with placeholders # PROMPT_TEMPLATES = { # "occasion_driven": ( # "You are an expert fashion stylist. A client is preparing for {occasion}. " # "They have a {body_type}-shaped body and a {face_shape} face. They’re currently wearing: {items}. " # "Give 3 to 5 *distinct* style tips focused on making them look their best at the event. " # "Make the suggestions relevant to the setting, weather, and formality of the occasion. " # "Avoid repeating any advice." # ), # "function_based": ( # "You're advising someone with a {body_type} build and {face_shape} face. " # "They're attending a {occasion} and are wearing {items}. " # "Suggest 3–5 concise fashion improvements or enhancements. " # "Each suggestion should be unique and tailored to the event. " # "Include practical choices for color, layering, accessories, or footwear. " # "Avoid repeating words or phrases." # ), # "intent_style": ( # "Act as a high-end personal stylist. Your client has a {body_type} body shape and a {face_shape} face. " # "They're going to a {occasion} and are wearing {items}. " # "Write 3 to 5 brief but powerful styling suggestions to elevate their look. " # "Focus on intent—what feeling or impression each style choice creates for the event." # ), # } # # Test parameters # BODY_TYPE = "Slim" # FACE_SHAPE = "Round" # OCCASION = "Rooftop Evening Party" # ITEMS = ["shirt", "jeans", "jacket","shoes"] # if __name__ == "__main__": # advisor = StyleSavvy() # for name, template in PROMPT_TEMPLATES.items(): # # Build prompt by replacing placeholders # prompt = template.format( # body_type=BODY_TYPE, # face_shape=FACE_SHAPE, # occasion=OCCASION, # items=", ".join(ITEMS) # ) # print(f"=== Testing template: {name} ===") # print("Prompt:") # print(prompt) # # Generate output (use only supported args) # result = advisor.pipe( # prompt, # max_length=advisor.max_length, # early_stopping=True, # do_sample=False # )[0]["generated_text"].strip() # print("Generated output:") # print(result) # # Extract bullet lines # bullets = [ln for ln in result.splitlines() if ln.strip().startswith("- ")] # print(f"Number of bullets detected: {len(bullets)}") # for i, b in enumerate(bullets, start=1): # print(f" {i}. {b}") # print("" + "-"*40) # test_llm.py """ Test harness for StyleSavvy LLM prompts. Evaluates multiple prompt templates and parses the generated outputs into distinct tips. """ from models.llm import StyleSavvy # Variant prompt templates with placeholders PROMPT_TEMPLATES = { "direct_instruction": ( "You are a professional fashion stylist. A client with a {body_type} body shape " "and {face_shape} face is preparing for a {occasion}. They are currently wearing {items}. " "Give exactly five different styling tips to improve their outfit. " "Each tip should be concise, actionable, and relevant to the event. Start each tip on a new line." ), "category_expansion": ( "As a high-end fashion advisor, provide five styling tips for a {body_type}-shaped person " "with a {face_shape} face attending a {occasion}. They are currently wearing {items}. " "Offer one tip for each of the following categories: silhouette, color, accessories, footwear, and layering. " "Each tip must be brief, specific, and clearly separated by a line break." ), "event_aesthetic": ( "Imagine you're curating a perfect outfit for a {body_type}-shaped individual with a {face_shape} face " "attending {occasion}. They are wearing {items}. Suggest 5 ways to enhance their style, focusing on event-appropriate aesthetics. " "Write each tip as a separate sentence on a new line. Do not repeat advice or themes." ), "fashion_editor": ( "As a fashion editor writing for a style magazine, outline five unique styling tips for a {body_type}-shaped reader " "with a {face_shape} face who is attending {occasion}. They currently wear {items}. " "Each recommendation should reflect expertise, relevance to the occasion, and a unique style element. " "Deliver all five tips in a list format, starting each on a new line." ), "influencer_style": ( "You’re an influencer known for your sharp styling advice. One of your followers has a {body_type} body and " "{face_shape} face, and they're attending {occasion}. They’ve sent you a photo wearing {items}. " "Reply with exactly five snappy, modern style tips they can use to upgrade their outfit for the event. " "Make sure each tip is short, non-repetitive, and on its own line." ), } # Test parameters BODY_TYPE = "Slim" FACE_SHAPE = "Round" OCCASION = "Rooftop Evening Party" ITEMS = ["jeans", "jacket", "shoes"] if __name__ == "__main__": advisor = StyleSavvy() for name, template in PROMPT_TEMPLATES.items(): print(f"=== Testing template: {name} ===") # Build prompt prompt = template.format( body_type=BODY_TYPE, face_shape=FACE_SHAPE, occasion=OCCASION, items=", ".join(ITEMS) ) print("Prompt:\n" + prompt) # Generate response result = advisor.pipe( prompt, max_length=advisor.max_length, early_stopping=True, num_beams=4, no_repeat_ngram_size=3, do_sample=False)[0]["generated_text"].strip() print("\nRaw generated output:\n" + result) # Parse into tips (bullets or sentence) lines = result.splitlines() tips = [ln.strip("-*0123456789. ").strip() for ln in lines if ln.strip()] if len(tips) < 3: # fallback to sentence split tips = [p.strip() for p in result.split(".") if p.strip()] tips = list(dict.fromkeys(tips)) # remove duplicates print(f"\n💡 Parsed {len(tips)} style tips:") for i, tip in enumerate(tips[:5], 1): print(f"{i}. {tip}") print("-" * 40)