Skip to content

surfly/D2Snap

Repository files navigation

D2Snap

Example of downsampling on an image (top) and a DOM (bottom) instance

D2Snap is a first-of-its-kind DOM downsampling algorithm, designed for use with LLM-based web agents.

Integrate

D2Snap.d2Snap(
  dom: DOM,
  k: number, l: number, m: number,
  options?: Options
): Promise<string>

D2Snap.adaptiveD2Snap(
  dom: DOM,
  maxTokens: number = 4096,
  maxIterations: number = 5,
  options?: Options
): Promise<string>
type DOM = Document | Element | string;
type Options = {
  assignUniqueIDs?: boolean; // false
  debug?: boolean;           // true
};

Browser

<script src="https://cdn.jsdelivr.net/gh/surfly/D2Snap@main/dist/D2Snap.browser.js"></script>

Module

npm install surfly/D2Snap

Install jsdom to use the library with Node.js:

npm install jsdom
import D2Snap from "@surfly/d2snap";

Experiment

Setup

npm install
npm install jsdom

Build

npm run build

Test

npm run test

Evaluate

Provide LLM API provider key(s) to .env (compare example).

npm run eval:<snapshot>

<snapshot> ∈ { gui, dom, bu, D2Snap }

npm run eval:D2Snap -- --verbose --split 10,20 --provider openai --model gpt-4o

Re-create Snapshots

npm run snapshots:create

Beyond Pixels: Exploring DOM Downsampling for LLM-Based Web Agents
Thassilo M. SchiepanskiNicholas Piël
Surfly BV

About

Beyond Pixels: Exploring DOM Downsampling for LLM-Based Web Agents

Resources

License

Stars

Watchers

Forks