| 1 | // ¿Dos generaciones con el MISMO prompt salen distintas? Si el decodificado es |
| 2 | // voraz, salen idénticas y muestrear N veces no aporta nada: best-of-N sería |
| 3 | // pagar N veces por el mismo resultado. |
| 4 | import { createRequire } from 'module'; |
| 5 | import os from 'os'; |
| 6 | const req = createRequire(import.meta.url); |
| 7 | const { chromium } = req(process.env.PW || 'playwright'); |
| 8 | const { execSync } = req('child_process'); |
| 9 | try { execSync('pkill -f elffuss-e4b'); } catch {} |
| 10 | await new Promise(r => setTimeout(r, 3000)); |
| 11 | try { execSync('rm -f ~/.cache/elffuss-e4b/Singleton*'); } catch {} |
| 12 | const ctx = await chromium.launchPersistentContext(os.homedir() + '/.cache/elffuss-e4b', |
| 13 | { channel: 'chrome', headless: true, args: ['--enable-unsafe-webgpu'] }); |
| 14 | const p = await ctx.newPage(); |
| 15 | await p.goto('https://claw.elffuss.com/', { waitUntil: 'domcontentloaded' }); |
| 16 | await p.waitForTimeout(1500); |
| 17 | await p.evaluate(async () => { const m = await import('/js/providers/litert.js'); m.configure('gemma-e4b'); await m.load(() => {}); }); |
| 18 | |
| 19 | const r = await p.evaluate(async () => { |
| 20 | const m = await import('/js/providers/litert.js'); m.configure('gemma-e4b'); |
| 21 | const salidas = []; |
| 22 | for (let i = 0; i < 3; i++) { |
| 23 | m.setSampling({ temperature: 0.8, seed: 1000 + i }); |
| 24 | // historial NUEVO cada vez → se recrea la conversación (rama «reiniciada») |
| 25 | salidas.push(String(await m.chat([{ role: 'user', content: 'Escribe una función JavaScript que baraje un array. Solo el código.' }], |
| 26 | 'Eres un programador. Responde solo con código.', () => {}))); |
| 27 | } |
| 28 | return salidas; |
| 29 | }); |
| 30 | console.log('tres generaciones con el mismo prompt, temperatura 0.8 y semillas distintas:\n'); |
| 31 | r.forEach((s, i) => console.log(` [${i}] ${s.length} car · hash ${[...s].reduce((a,c)=>(a*31+c.charCodeAt(0))>>>0,7)}`)); |
| 32 | const iguales = r.every(x => x === r[0]); |
| 33 | console.log(`\n ${iguales ? '⚠ IDÉNTICAS — decodificado voraz: muestrear N veces no aporta NADA' |
| 34 | : '✓ distintas — hay diversidad, best-of-N tiene sentido'}`); |
| 35 | if (!iguales) { console.log('\n primeras líneas de cada una:'); r.forEach((s,i)=>console.log(` [${i}] ${s.split('\n').find(l=>l.trim())||''}`.slice(0,100))); } |
| 36 | await ctx.close(); |