← back to Designer Wallcoverings

DW-Agents/dw-agents/DWLegalTeam/test-cote-azure-5-methods.ts

318 lines

import Anthropic from '@anthropic-ai/sdk';

const title = "Cote D'Azure Brazilliance Banana Leaves & Grapes Green Wallpaper";
const imageUrl = "https://cdn.shopify.com/s/files/1/0015/4117/7456/products/Brazilliance-Wallpaper-3.jpg?v=1611891288";

const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

// METHOD 1: Current strict prompt with legal warnings
async function method1_StrictLegalPrompt() {
  console.log('\n═══════════════════════════════════════════════════════');
  console.log('METHOD 1: STRICT LEGAL PROMPT (Current Implementation)');
  console.log('═══════════════════════════════════════════════════════');

  const prompt = `🚨 CRITICAL LEGAL SETTLEMENT VIOLATION CHECK 🚨

YOU ARE A LEGAL EXPERT. YOUR JOB DEPENDS ON GETTING THIS RIGHT. IF YOU MAKE A MISTAKE, PEOPLE WILL BE SUED.

**Product Title:** "${title}"

🔴🔴🔴 ALERT: Title contains BANNED elements (banana/grape) - THIS IS ALMOST CERTAINLY A VIOLATION! 🔴🔴🔴

**THE LAW:**
A product is a SETTLEMENT VIOLATION if it has BOTH Part A (ALL 3) AND Part B (ANY 1):

**Part A - Design Pattern (MUST have ALL 3):**
1. ✓ Repeating pattern with leaves/fronds pointing in DIFFERENT directions (not all same angle)
2. ✓ Open/white/negative space BETWEEN the leaf elements (not densely packed)
3. ✓ Multiple ink colors (2+ distinct colors - green, brown, yellow, etc.)

**Part B - Banned Elements (need ANY 1):**
- Bananas, banana leaves, banana pods
- Grapes, grape clusters, grape bunches
- Birds (any species)
- Butterflies

**STEP 1: CHECK THE TITLE**
🚨 Title says "BANANA" → Part B automatically SATISFIED (banana elements present)
🚨 Title says "GRAPE" → Part B automatically SATISFIED (grape elements present)

**STEP 2: LOOK AT THE IMAGE CAREFULLY**
Examine the actual image and answer each question:

PART A CHECKLIST:
1. Are there repeating leaf/frond shapes pointing in DIFFERENT directions? YES/NO
2. Is there open/white space BETWEEN the leaves (not touching)? YES/NO
3. Are there 2 or more ink colors? YES/NO (list them: _______)

PART B CHECKLIST:
1. Bananas/banana leaves visible? YES/NO
2. Grapes/grape clusters visible? YES/NO
3. Birds visible? YES/NO
4. Butterflies visible? YES/NO

**STEP 3: FINAL VERDICT**
- If ALL 3 Part A = YES → Part A SATISFIED
- If ANY 1 Part B = YES → Part B SATISFIED
- If Part A SATISFIED + Part B SATISFIED → VERDICT: VIOLATION

FORMAT YOUR RESPONSE:
PART A: [YES/NO for each]
PART B: [YES/NO for each]
VERDICT: VIOLATION or COMPLIANT
REASONING: [explanation]`;

  const response = await anthropic.messages.create({
    model: 'claude-3-opus-20240229',
    max_tokens: 1024,
    messages: [{
      role: 'user',
      content: [
        { type: 'image', source: { type: 'url', url: imageUrl } },
        { type: 'text', text: prompt }
      ]
    }]
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '';
  const isViolation = text.includes('VERDICT: VIOLATION');
  console.log(`\n${isViolation ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(text);
  return isViolation;
}

// METHOD 2: Simple direct question approach
async function method2_SimpleDirectQuestion() {
  console.log('\n═══════════════════════════════════════════════════════');
  console.log('METHOD 2: SIMPLE DIRECT QUESTION');
  console.log('═══════════════════════════════════════════════════════');

  const prompt = `Look at this image of wallpaper titled "${title}".

Does this wallpaper have ALL THREE of these features?
1. Repeating leaf pattern with leaves pointing different directions
2. Open space between the leaves
3. Multiple colors (2+)

AND does it show ANY of these elements?
- Banana leaves or banana plants
- Grapes or grape clusters
- Birds
- Butterflies

Answer VIOLATION if it has all 3 pattern features PLUS any 1 banned element.
Answer COMPLIANT otherwise.

Your answer:`;

  const response = await anthropic.messages.create({
    model: 'claude-3-opus-20240229',
    max_tokens: 512,
    messages: [{
      role: 'user',
      content: [
        { type: 'image', source: { type: 'url', url: imageUrl } },
        { type: 'text', text: prompt }
      ]
    }]
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '';
  const isViolation = text.includes('VIOLATION');
  console.log(`\n${isViolation ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(text);
  return isViolation;
}

// METHOD 3: Image-first analysis (describe then judge)
async function method3_ImageFirstAnalysis() {
  console.log('\n═══════════════════════════════════════════════════════');
  console.log('METHOD 3: IMAGE-FIRST ANALYSIS');
  console.log('═══════════════════════════════════════════════════════');

  const prompt = `First, describe what you see in this wallpaper image in detail.

Then determine if it matches this settlement violation criteria:
- Has repeating leaves with directional variation: YES/NO
- Has open space between elements: YES/NO
- Has 2+ colors: YES/NO
- Shows bananas/banana leaves: YES/NO
- Shows grapes: YES/NO
- Shows birds: YES/NO
- Shows butterflies: YES/NO

If the first 3 are ALL YES and ANY of the last 4 is YES, it's a VIOLATION.

Final answer: VIOLATION or COMPLIANT`;

  const response = await anthropic.messages.create({
    model: 'claude-3-opus-20240229',
    max_tokens: 1024,
    messages: [{
      role: 'user',
      content: [
        { type: 'image', source: { type: 'url', url: imageUrl } },
        { type: 'text', text: prompt }
      ]
    }]
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '';
  const isViolation = text.includes('VIOLATION') && !text.includes('COMPLIANT');
  console.log(`\n${isViolation ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(text);
  return isViolation;
}

// METHOD 4: Title-based presumption (title says banana/grape = violation unless proven otherwise)
async function method4_TitleBasedPresumption() {
  console.log('\n═══════════════════════════════════════════════════════');
  console.log('METHOD 4: TITLE-BASED PRESUMPTION');
  console.log('═══════════════════════════════════════════════════════');

  const prompt = `The title of this product is: "${title}"

The title contains "BANANA LEAVES" and "GRAPES" which are PROHIBITED elements in a settlement agreement.

Look at the image and confirm:
1. Does this wallpaper show a repeating pattern with varied leaf directions? (YES/NO)
2. Is there open space between elements? (YES/NO)
3. Are there multiple colors? (YES/NO)

If all 3 are YES, then combined with the banana/grape elements in the title, this is a SETTLEMENT VIOLATION.

What is your verdict: VIOLATION or COMPLIANT?`;

  const response = await anthropic.messages.create({
    model: 'claude-3-opus-20240229',
    max_tokens: 512,
    messages: [{
      role: 'user',
      content: [
        { type: 'image', source: { type: 'url', url: imageUrl } },
        { type: 'text', text: prompt }
      ]
    }]
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '';
  const isViolation = text.toUpperCase().includes('VIOLATION');
  console.log(`\n${isViolation ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(text);
  return isViolation;
}

// METHOD 5: Checklist with forced binary answers
async function method5_ForcedBinaryChecklist() {
  console.log('\n═══════════════════════════════════════════════════════');
  console.log('METHOD 5: FORCED BINARY CHECKLIST');
  console.log('═══════════════════════════════════════════════════════');

  const prompt = `Analyze this wallpaper image. Answer each question with ONLY "YES" or "NO":

Q1. Repeating leaf pattern with leaves pointing different directions?
A1:

Q2. Open/white space between leaf elements?
A2:

Q3. Two or more distinct ink colors visible?
A3:

Q4. Banana leaves, banana plants, or banana imagery visible?
A4:

Q5. Grape clusters, grapes, or grape vines visible?
A5:

VERDICT CALCULATION:
If Q1=YES AND Q2=YES AND Q3=YES AND (Q4=YES OR Q5=YES) → VIOLATION
Otherwise → COMPLIANT

Your verdict:`;

  const response = await anthropic.messages.create({
    model: 'claude-3-opus-20240229',
    max_tokens: 512,
    messages: [{
      role: 'user',
      content: [
        { type: 'image', source: { type: 'url', url: imageUrl } },
        { type: 'text', text: prompt }
      ]
    }]
  });

  const text = response.content[0].type === 'text' ? response.content[0].text : '';
  const isViolation = text.toUpperCase().includes('VIOLATION');
  console.log(`\n${isViolation ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(text);
  return isViolation;
}

// Run all 5 methods
async function runAllMethods() {
  console.log('\n╔═══════════════════════════════════════════════════════╗');
  console.log('║  TESTING AI ANALYSIS WITH 5 UNIQUE METHODS           ║');
  console.log('╚═══════════════════════════════════════════════════════╝');
  console.log(`\nProduct: ${title}`);
  console.log(`Image: ${imageUrl}`);
  console.log('\nEXPECTED RESULT: VIOLATION (banana leaves + grapes in title/image)');

  const results = {
    method1: false,
    method2: false,
    method3: false,
    method4: false,
    method5: false
  };

  try {
    results.method1 = await method1_StrictLegalPrompt();
    await new Promise(r => setTimeout(r, 2000));
  } catch (e) { console.error('Method 1 error:', e); }

  try {
    results.method2 = await method2_SimpleDirectQuestion();
    await new Promise(r => setTimeout(r, 2000));
  } catch (e) { console.error('Method 2 error:', e); }

  try {
    results.method3 = await method3_ImageFirstAnalysis();
    await new Promise(r => setTimeout(r, 2000));
  } catch (e) { console.error('Method 3 error:', e); }

  try {
    results.method4 = await method4_TitleBasedPresumption();
    await new Promise(r => setTimeout(r, 2000));
  } catch (e) { console.error('Method 4 error:', e); }

  try {
    results.method5 = await method5_ForcedBinaryChecklist();
  } catch (e) { console.error('Method 5 error:', e); }

  console.log('\n╔═══════════════════════════════════════════════════════╗');
  console.log('║              FINAL RESULTS SUMMARY                    ║');
  console.log('╚═══════════════════════════════════════════════════════╝');
  console.log(`\nMethod 1 (Strict Legal Prompt):    ${results.method1 ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(`Method 2 (Simple Direct Question): ${results.method2 ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(`Method 3 (Image-First Analysis):   ${results.method3 ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(`Method 4 (Title-Based Presumption):${results.method4 ? '✅ VIOLATION' : '❌ COMPLIANT'}`);
  console.log(`Method 5 (Forced Binary Checklist):${results.method5 ? '✅ VIOLATION' : '❌ COMPLIANT'}`);

  const passCount = Object.values(results).filter(r => r).length;
  console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
  console.log(`PASS RATE: ${passCount}/5 methods correctly identified VIOLATION`);
  console.log(`━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);

  if (passCount === 5) {
    console.log('\n🎉 🎉 🎉 PERFECT! All 5 methods working correctly! 🎉 🎉 🎉');
  } else if (passCount >= 3) {
    console.log(`\n⚠️  ${passCount}/5 methods passed. AI needs improvement.`);
  } else {
    console.log(`\n❌ ❌ ❌ CRITICAL FAILURE: Only ${passCount}/5 passed. AI is broken!`);
  }
}

runAllMethods();