Live data from Hacker News

Minifying HTML for GPT-4o: Remove all the HTML tags

blancas.io

21–30 of 52 posts

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#21

What I do is convert to markdown, that way you still get some semantic structure. Even built an Elixir library for this: https://github.com/agoodway/html2markdown

Seems to be the most common method I've seen, it makes sense given how well LLMs understand markdown.

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#23

Isn't GPT-4o multimodal? Shouldn't I be able to just feed in an image of the rendered HTML, instead of doing work to strip tags out?

it is theoretically possible, but the results and bandwidth would be worse. sending an image that large would take a lot longer than sending text

This. Images passed to LLMs are typically downsampled to something like 512x512 because that’s perfectly good for feature extraction. Getting text would mean very large images so the text is still readable.

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#24
I built a CLI tool (and Python library) for this a while ago called strip-tags: https://github.com/simonw/strip-tags

By default it will strip all HTML tags and return just the text:

    curl 'https://simonwillison.net/' | strip-tags
But you can also tell it you just want to get back the area of a page identified by one or more CSS selectors:

    curl 'https://simonwillison.net/' | strip-tags .quote
Or you can ask it to keep specific tags if you think those might help provide extra context to the LLM:

    curl 'https://simonwillison.net/' | strip-tags .quote -t div -t blockquote
Add "-m" to minify the output (basically stripping most whitespace)

Running this command:

    curl 'https://simonwillison.net/' | strip-tags .quote -t div -t blockquote -m
Gives me back output that starts like this:

     
history | tail -n 2000 | llm -s "Write aliases for my zshrc based on my terminal history. Only do this for most common features. Don't use any specific files or directories."
— anjor # 3:01 pm / ai, generative-ai, llms, llm
Art is notoriously hard to define, and so are the differences between good art and bad art. But let me offer a generalization: art is something that results from making a lot of choices. […] to oversimplify, we can imagine that a ten-thousand-word short story requires something on the order of ten thousand choices. When you give a generative-A.I. program a prompt, you are making very few choices; if you supply a hundred-word prompt, you have made on the order of a hundred choices. If an A.I. generates a ten-thousand-word story based on your prompt, it has to fill in for all of the choices that you are not making.
— Ted Chiang # 10:09 pm / art, new-yorker, ai, generative-ai, ted-chiang
I also often use the https://r.jina.ai/ proxy - add a URL to that and it extracts the key content (using Puppeteer) and returns it converted to Markdown, e.g. https://r.jina.ai/https://simonwillison.net/2024/Sep/2/anato...

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#25
In Elixir, I select the ``, then remove all script and style tags. Then extract the text.

This results in a kind of innerText you get in browsers, great and light to pass into LLMs.

    defp extract_inner_text(html) do
      html
      |> Floki.parse_document!()
      |> Floki.find("body")
      |> Floki.traverse_and_update(fn
        {tag, _attrs, _children} = _node when tag in ["script", "style"] ->
          nil
  
        node ->
          node
      end)
      |> Floki.text(sep: " ")
      |> String.trim()
      |> String.replace(~r/\s+/, " ")
    end

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#27

ChatGPT is clearly trained on wikipedia, is there any concern about its knowledge from there polluting the responses? Seems like it would be better to try against data it didn't potentially already know.

Yep - one good option is to use Wikipedia pages from the recent Olympics, which GPT has no knowledge of: https://github.com/openai/openai-cookbook/blob/457f4310700f9...

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#28
I've been building an AI chat client and I use this exact technique to develop the "Web Browsing" plugin. Basically I use Function Calling to extract content from a web page and then pass it to the LLM.

There are a few optimizations we can make:

- trip all content in and - use Readability.js for articles - extract structured content from oEmbed

It works surprisingly well for me, even with gpt-4o-mini

Re: Minifying HTML for GPT-4o: Remove all the HTML tags

#29
Anecdotally, the same seems to apply to the output format as well. I’ve seen much better performance when instructing the model to output something like this:

  name=john,age=23
  name=anna,age=26

Rather than this:

  {
    matches: [
      { name: "john", age: 23 },
      { name: "anna", age: 26 }
    ]
  }
Post reply on HN