Files
nexus/scripts/ui-pruefung/embeddings.mjs

58 lines
4.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// browser2embeddings.1 bis .3: Reiter Embeddings, Knöpfe je Modellart, Vektor-Test (Testinstanz mit bge-m3 und einem Chat-Modell).
// Aufruf: node embeddings.mjs <Passwort> [kurz] (Benutzer „claude“, NEXUS_BASE wie bei den anderen Skripten)
import * as cdp from './lib.mjs';
import fs from 'node:fs';
const BASE = process.env.NEXUS_BASE || 'http://127.0.0.1:18097';
const [pw, modus] = process.argv.slice(2);
const b = await cdp.start({ port: 9341 });
const ok = (n, c, d = '') => { console.log(`${c ? 'ok ' : 'FEHLER'} ${n}${d ? ' – ' + d : ''}`); if (!c) process.exitCode = 1; };
try {
await b.login(BASE, 'claude', pw);
const seite = async (pfad) => { await b.goto(BASE + pfad); await new Promise(r => setTimeout(r, 800)); return b.eval('document.body.innerText'); };
// .1 Reiter und Chat-Auswahl
const llm = await seite('/ui/modelle');
ok('.1 Reiter LLM zeigt das Chat-Modell', llm.includes('bonsai'));
ok('.1 Reiter LLM zeigt das Embedding-Modell nicht', !llm.includes('bge-m3'));
const emb = await seite('/ui/modelle?art=embedding');
ok('.1 Reiter Embeddings zeigt bge-m3', emb.includes('bge-m3'));
ok('.1 Reiter Embeddings zeigt das Chat-Modell nicht', !emb.includes('bonsai'));
const tabs = await b.eval(`[...document.querySelectorAll('a,button')].map(e=>e.textContent.trim()).filter(t=>/^(LLM|Embeddings|Sprache|Bild|Musik)$/.test(t)).join(',')`);
ok('.1 Reiter vorhanden', tabs.includes('Embeddings') && tabs.includes('LLM'), tabs);
await b.goto(BASE + '/ui/chat'); await new Promise(r => setTimeout(r, 800));
const chatModelle = await b.eval(`[...document.querySelectorAll('select option')].map(o=>o.textContent.trim()).join('|')`);
ok('.1 Chat bietet bonsai an, bge-m3 nicht', chatModelle.includes('bonsai') && !chatModelle.includes('bge-m3'), chatModelle);
// .2 Knöpfe
await b.goto(BASE + '/ui/modelle'); await new Promise(r => setTimeout(r, 800));
const llmKnoepfe = await b.eval(`[...document.querySelectorAll('button[title],button[aria-label]')].map(e=>e.title||e.getAttribute('aria-label')).join('|')`);
ok('.2 Chat-Modell hat „Fähigkeiten prüfen“ und kein „Embedding prüfen“', llmKnoepfe.includes('Fähigkeiten prüfen') && !llmKnoepfe.includes('Embedding prüfen'), llmKnoepfe);
await b.goto(BASE + '/ui/modelle?art=embedding'); await new Promise(r => setTimeout(r, 800));
const embKnoepfe = await b.eval(`[...document.querySelectorAll('button[title],button[aria-label]')].map(e=>e.title||e.getAttribute('aria-label')).join('|')`);
ok('.2 Embedding-Modell hat „Embedding prüfen“ und kein „Fähigkeiten prüfen“', embKnoepfe.includes('Embedding prüfen') && !embKnoepfe.includes('Fähigkeiten prüfen'), embKnoepfe);
// Direkter Aufruf der Chat-Prüfung für bge-m3: Formular von bonsai übernehmen
await b.goto(BASE + '/ui/modelle'); await new Promise(r => setTimeout(r, 800));
const direkt = await b.eval(`(async()=>{const f=[...document.querySelectorAll('form')].find(f=>f.action.includes('/ui/modelle/faehigkeiten'));
const d=new URLSearchParams(new FormData(f)); d.set('name','bge-m3');
const r=await fetch(f.getAttribute('action'),{method:'POST',headers:{'content-type':'application/x-www-form-urlencoded'},body:d});
const t=await r.text(); const m=/Ein Embedding-Modell kann nicht chatten[^<]*/.exec(t); return {status:r.status,meldung:m?m[0]:null}; })()`);
ok('.2 direkter Aufruf meldet „kann nicht chatten“', !!direkt.meldung, JSON.stringify(direkt));
// Dass nichts gestartet wurde, belegt der Lauf auf srv04 mit dem Log der Testinstanz und `nvidia-smi` (nicht in diesem Skript).
if (modus === 'kurz') { b.close(); process.exit(); }
// .3 Embedding prüfen
await b.goto(BASE + '/ui/modelle?art=embedding'); await new Promise(r => setTimeout(r, 800));
await b.eval(`[...document.querySelectorAll('button')].find(e=>(e.title||e.getAttribute('aria-label'))==='Embedding prüfen').click()`);
const verlauf = [];
for (let i = 0; i < 60; i++) {
await new Promise(r => setTimeout(r, 2000));
const t = await b.eval('document.body.innerText');
const z = /[^\n]*(Embedding-Test|Vektor)[^\n]*/.exec(t)?.[0] ?? '';
if (z && verlauf[verlauf.length - 1] !== z) verlauf.push(z);
const kann = await b.eval(`[...document.querySelectorAll('tr')].filter(r=>r.innerText.includes('bge-m3')).map(r=>r.innerHTML).join('')`);
if (/1024/.test(kann)) break;
}
console.log(' Prüfzeilen im Verlauf:', JSON.stringify(verlauf));
await b.goto(BASE + '/ui/modelle?art=embedding'); await new Promise(r => setTimeout(r, 1200));
const zeile = await b.eval(`[...document.querySelectorAll('tr')].filter(r=>r.innerText.includes('bge-m3')).map(r=>r.innerHTML).join('')`);
ok('.3 „Kann“ zeigt die Vektorgröße 1024 auch nach Neuladen', /1024/.test(zeile));
await b.shot('/tmp/emb-tab.png');
} catch (e) { console.log('Fehler im Lauf:', e.message); process.exitCode = 1; } finally { b.close(); }