puppet

Puppeteer script for anything
Log | Files | Refs

tasks.js (966B)


      1 import readline from 'node:readline/promises';
      2 import { stdin as input, stdout as output } from 'node:process';
      3 import { setTimeout } from 'node:timers/promises';
      4 import { exec, spawn } from 'child_process';
      5 
      6 const rl = readline.createInterface({ input, output });
      7 
      8 const runlm = (lmPrompt, model) => {
      9   return new Promise((resolve, reject) => {
     10     const child = spawn('ollama', ['run', model], { stdio: ['pipe', 'pipe', 'pipe'] });
     11 
     12     let out = '', err = '';
     13 
     14     child.stdout.on('data', d => out += d.toString());
     15     child.stderr.on('data', d => err += d.toString());
     16 
     17     child.stdin.write(lmPrompt);
     18     child.stdin.end();
     19 
     20     child.on('close', code => {
     21       if (code !== 0) return reject(new Error(err || `Exit ${code}`));
     22       resolve(out.trim());
     23     });
     24   });
     25 }
     26 
     27 export async function browseAndScreenshot(page) {
     28 	for(let n = 0; n < 60; n++) {
     29 		await setTimeout(1000);
     30 	}
     31 	await page.screenshot({ path: 'files/screenshot.png', fullPage: true });
     32 }