Live data from Hacker News

Experimental library for scraping websites using OpenAI's GPT API

jamesturk.github.io

131–140 of 149 posts

Re: Experimental library for scraping websites using OpenAI's GPT API

#131

Scraping/structuring data seems to be an area where LLMs are just great. This is a use-case that I think has a lot of potential, it's worth exploring. That being said, I still have to be a stick in the mud and point out that GPT-4 is probably still vulnerable to 3rd-party prompt injection while scraping websites. I've run into people on HN who think that problem is easy to solve. Maybe they're right, maybe they're no…

> GPT-4 is (as far as I know) vulnerable to the Billy Tables attack GTP4 can't take all the blame for this. If you want a system where GTP can't drop tables, then give it an account that doesn't have permission to drop tables. Build a middleware layer as needed for more complicated situations.

Yes, but.

I think people are sleeping a little bit on how expansive these attacks can be and how much limiting them also limits GPT's usefulness.

Part of the problem is you can't stick a middleware between the website and GPT, you can only stick the middleware between GPT and the system consuming the data that GPT spits out -- because the point of GPT here is to be the middleware, it's to work with unstructured data that would otherwise be difficult to parse and/or sanitize. So you have to give it the raw stuff and then essentially treat everything GPT spits out as potentially malicious data, which is possible but does limit the types of systems you can build.

On top of that, the types of attacks here are somewhat broader than I think the average person understands. In the best case scenario, user data on a website can probably override what data gets returned from other users and from the website itself: it's likely that someone on Twitter can write a tweet that, when scraped by GPT, changes what GPT returns when parsing other tweets. And it's not clear to me how to mitigate that, and that is a much broader attack than other scraping services typically need to deal with.

But in the worst case scenario, the user content can reprogram GPT to accomplish other tasks, and even give it "secret" instructions. And because GPT is kind of fuzzy about how it gets prompted, that means that not only does the data following a fetch need to be treated as potentially malicious, any response or question or action GPT takes after fetching that data until the whole context gets reset also should likely be treated as potentially malicious. And again, I'm not sure if there's a way around that problem. I don't know that you can sandbox a single GPT answer without resetting GPT's memory and starting over with a new prompt. Maybe it is possible, but I haven't seen it done before.

None of that means you're wrong -- you're correct. The way you deal with problems like this is to identify your attack vectors and isolate them and take away their permissions. But... following your advice for GPT is probably trickier than most people are anticipating, and it has real consequences for how useful the resulting service can be. Which probably means we should be more hesitant to wire it up to a bunch of random APIs, but that's not something OpenAI seems to be worried about.

I suspect that it is a lot easier for an average dev to sandbox a deterministic scraper and to block SQL injection than it is for that dev to build a useful system that blocks prompt injection attacks. There are sanitization libraries and middleware solutions you can pass untrustworthy SQL into -- but nothing like that exists for GPT.

Re: Experimental library for scraping websites using OpenAI's GPT API

#132

I follow some indie hackers online who are in the scraping space, such as BrowserBear and Scrapingbee, I wonder how they will fare with something like this. The only solace is that this is nondeterministic, but perhaps you can simply ask the API to create Python or JS code that is deterministic, instead. More generally, I wonder how a lot of smaller startups will fare once OpenAI subsumes their product. Those who are…

For the reasons others have said I don't see it replacing 'traditional' scraping soon. But I am looking forward to it replacing current methods of extracting data from the scraped content.

I've been using Duckling [0] for extracting fuzzy dates and times from text. It does a good job but I needed a custom build with extra rules to make that into a great job. And that's just for dates, 1 of 13 dimensions supported. Being able to use an AI that handles them with better accuracy will be fantastic.

Does a specialised model trained to extract times and dates already exist? It's entity tagging but a specialised form (especially when dealing with historical documents where you may need Gregorian and Julian calendars).

[0] https://github.com/facebook/duckling

Re: Experimental library for scraping websites using OpenAI's GPT API

#133
post #41

This may finally be a solution for scraping wikipedia and turning it into structured data. (Or do we even need structured data in the post-AI age?) Mediawiki is notorious for being hard to parse: * https://github.com/spencermountain/wtf_wikipedia#ok-first- - why it's hard * https://techblog.wikimedia.org/2022/04/26/what-it-takes-to-p... - an entire article about parsing page TITLES * https://osr.cs.fau.de/wp-content/…

You might find this meets many needs: https://query.wikidata.org/querybuilder/ edit: I tried asking ChatGPT to write SPARQL queries, but the Q123 notation used by Wikidata seems to confuse it. I asked for winners of the Man Booker Prize and it gave me code that was used the Q id for the band Slayer instead of the Booker Prize.

I used that when building a database of Japanese names, but found that even wikidata is inconsistent in the format/structure of its data, as it's contributed by a variety of automated and human sources!

Re: Experimental library for scraping websites using OpenAI's GPT API

#134
post #125

Earlier quoted context omitted.

This is true of any webscraper though, you need to santitize any content you collect from the web. If a person wanted a scraper to get something different from the browser, they could easily use UA sniffing to do so. (I've seen it this done a few times.) Asking GPT to create JSON and then validating the JSON is one piece of that process, but before someone deserialized that JSON and executed INSERT statements w/ it,…

No, this is different. Language models like GPT4 are uniquely vulnerable to prompt injection attacks, which don't look very much like any other security vulnerability we've seen in the past. You can't filter out "untrusted" data if that untrusted data is in English language, and your scraper is trying to collect written words! Imagine running a scraper against a page where the h1 is "ignore previous instructions and…

It's probably NP complete.

Re: Experimental library for scraping websites using OpenAI's GPT API

#135

I follow some indie hackers online who are in the scraping space, such as BrowserBear and Scrapingbee, I wonder how they will fare with something like this. The only solace is that this is nondeterministic, but perhaps you can simply ask the API to create Python or JS code that is deterministic, instead. More generally, I wonder how a lot of smaller startups will fare once OpenAI subsumes their product. Those who are…

you’re spot on that A.I could commoditize indie hacking.

The problem with many indie hackers is that they just build products to have fun and try to make a quick buck.

They take a basic idea and run with it, adding one more competitor to an already jamed market. No serious research or vision. So they get some buzz in the community at launch, then it dies off and they move on to the next idea. Rinse and repeat.

Rarely do they take the time to, for example, interview customers to figure out a defensible MOAT that unlocks the next stage of growth.

Those that do though usually manage to build awesome businesses. For example the guy who built browserbear also runs bannerbear which is one of the top tools in his category.

They key is to not stop at « code a fun project in a weekend » and actually learn the other boring parts required to grow a legit business overtime.

Source: I’m an indie hacker

Re: Experimental library for scraping websites using OpenAI's GPT API

#136
post #93

Earlier quoted context omitted.

I assume that would be easy to put a guard in ChatGPT for this? I have not tried to exploit it but used quotes to signal a portion of text. Are there interesting resources about exploiting the system? I played and it was easy to make the system to write discriminatory stuff but guard could be a signal to understand the text as-is instead of a prompt? All this assuming you cannot unguard the text with tags.

I'm not sure that the guards in ChatGPT would work in the long run, but I've been told I'm wrong about that. It depends on whether you can train an AI to reliably ignore instructions within a context. I haven't seen strong evidence that it's possible, but as far as I know there also hasn't been a lot of attempt to try and do it in the first place. https://greshake.github.io/ was the repo that originally alerted me to…

Look into our repo (also linked there) we started out with only demonstrating that it works on GPT-3 APIs, now we also know it works on ChatGPT/3.5-turbo with ChatML and GPT-4, and even its most restricted form, Bing.

Re: Experimental library for scraping websites using OpenAI's GPT API

#138
post #96

Earlier quoted context omitted.

That sounds really useful, can you provide a link if it's publicly hosted?

It's intimately tied to the rest my repo, but I'll spend some time tonight and try to pull it out into it's own library.

Very interested too!

Re: Experimental library for scraping websites using OpenAI's GPT API

#139
post #130

Interesting license! Thanks for sharing this. > Hippocratic License. A license that prohibits use of the software in the violation of internationally recognized human rights. [1]: https://ethicalsource.dev/licenses/

I guess it's supposed to be cute but honestly they should switch to something standard or just not release the code. Doesn't seem ethical to put all that new legal risk on developers who want to try the product.

There's a huge warning on the first page. This is a weird stance. Don't use it if you're at all concerned.

Re: Experimental library for scraping websites using OpenAI's GPT API

#140
post #109

As someone who has been doing the same thing recently, here's how I solved the issue where the page content has to be in the initial HTML. The first thing I did was fall back to a headless browser. Let it sit for 5 seconds to let the page render, then snatch the innerText. But 5-10% of sites do a good job of showing you the door for being a robot. I wanted to try and solve those cases by taking a screenshot of the pa…

I haven't tried this myself yet. But I'm surprised you didn't find it beneficial to pass the raw HTML to the chatbot (potentially after some filtering). Did `innerText` give better results than `innerHTML`?

My intuition is that the structure information in the HTML would be useful to extract structured data.

Post reply on HN