gpt-crawler README

The project's README from github.com/BuilderIO/gpt-crawler. As one markdown file: README.md.

GPT Crawler

Deutsch | Español | français | 日本語 | 한국어 | Português | Русский | 中文

Crawl a site to generate knowledge files to create your own custom GPT from one or multiple URLs

Gif showing the crawl run

Example

Here is a custom GPT that I quickly made to help answer questions about how to use and integrate Builder.io by simply providing the URL to the Builder docs.

This project crawled the docs and generated the file that I uploaded as the basis for the custom GPT.

Try it out yourself by asking questions about how to integrate Builder.io into a site.

Note that you may need a paid ChatGPT plan to access this feature

Get started

Running locally

Clone the repository

Be sure you have Node.js >= 16 installed.

git clone https://github.com/builderio/gpt-crawler

Install dependencies

npm i

Configure the crawler

Open config.ts and edit the url and selector properties to match your needs.

E.g. to crawl the Builder.io docs to make our custom GPT you can use:

export const defaultConfig: Config = {
  url: "https://www.builder.io/c/docs/developers",
  match: "https://www.builder.io/c/docs/**",
  selector: `.docs-builder-container`,
  maxPagesToCrawl: 50,
  outputFileName: "output.json",
};

See config.ts for all available options. Here is a sample of the common configuration options:

type Config = {
  /** URL to start the crawl, if sitemap is provided then it will be used instead and download all pages in the sitemap */
  url: string;
  /** Pattern to match against for links on a page to subsequently crawl */
  match: string;
  /** Selector to grab the inner text from */
  selector: string;
  /** Don't crawl more than this many pages */
  maxPagesToCrawl: number;
  /** File name for the finished data */
  outputFileName: string;
  /** Optional resources to exclude
   *
   * @example
   * ['png','jpg','jpeg','gif','svg','css','js','ico','woff','woff2','ttf','eot','otf','mp4','mp3','webm','ogg','wav','flac','aac','zip','tar','gz','rar','7z','exe','dmg','apk','csv','xls','xlsx','doc','docx','pdf','epub','iso','dmg','bin','ppt','pptx','odt','avi','mkv','xml','json','yml','yaml','rss','atom','swf','txt','dart','webp','bmp','tif','psd','ai','indd','eps','ps','zipx','srt','wasm','m4v','m4a','webp','weba','m4b','opus','ogv','ogm','oga','spx','ogx','flv','3gp','3g2','jxr','wdp','jng','hief','avif','apng','avifs','heif','heic','cur','ico','ani','jp2','jpm','jpx','mj2','wmv','wma','aac','tif','tiff','mpg','mpeg','mov','avi','wmv','flv','swf','mkv','m4v','m4p','m4b','m4r','m4a','mp3','wav','wma','ogg','oga','webm','3gp','3g2','flac','spx','amr','mid','midi','mka','dts','ac3','eac3','weba','m3u','m3u8','ts','wpl','pls','vob','ifo','bup','svcd','drc','dsm','dsv','dsa','dss','vivo','ivf','dvd','fli','flc','flic','flic','mng','asf','m2v','asx','ram','ra','rm','rpm','roq','smi','smil','wmf','wmz','wmd','wvx','wmx','movie','wri','ins','isp','acsm','djvu','fb2','xps','oxps','ps','eps','ai','prn','svg','dwg','dxf','ttf','fnt','fon','otf','cab']
   */
  resourceExclusions?: string[];
  /** Optional maximum file size in megabytes to include in the output file */
  maxFileSize?: number;
  /** Optional maximum number tokens to include in the output file */
  maxTokens?: number;
};

Run your crawler

npm start

Alternative methods

Running in a container with Docker

To obtain the output.json with a containerized execution, go into the containerapp directory and modify the config.ts as shown above. The output.jsonfile should be generated in the data folder. Note: the outputFileName property in the config.ts file in the containerapp directory is configured to work with the container.

Running as an API

To run the app as an API server you will need to do an npm install to install the dependencies. The server is written in Express JS.

To run the server.

npm run start:server to start the server. The server runs by default on port 3000.

You can use the endpoint /crawl with the post request body of config json to run the crawler. The api docs are served on the endpoint /api-docs and are served using swagger.

To modify the environment you can copy over the .env.example to .env and set your values like port, etc. to override the variables for the server.

Upload your data to OpenAI

The crawl will generate a file called output.json at the root of this project. Upload that to OpenAI to create your custom assistant or custom GPT.

Create a custom GPT

Use this option for UI access to your generated knowledge that you can easily share with others

Note: you may need a paid ChatGPT plan to create and use custom GPTs right now

  1. Go to https://chat.openai.com/
  2. Click your name in the bottom left corner
  3. Choose "My GPTs" in the menu
  4. Choose "Create a GPT"
  5. Choose "Configure"
  6. Under "Knowledge" choose "Upload a file" and upload the file you generated
  7. if you get an error about the file being too large, you can try to split it into multiple files and upload them separately using the option maxFileSize in the config.ts file or also use tokenization to reduce the size of the file with the option maxTokens in the config.ts file

Gif of how to upload a custom GPT

Create a custom assistant

Use this option for API access to your generated knowledge that you can integrate into your product.

  1. Go to https://platform.openai.com/assistants
  2. Click "+ Create"
  3. Choose "upload" and upload the file you generated

Gif of how to upload to an assistant

Contributing

Know how to make this project better? Send a PR!



Made with love by Builder.io

gpt-crawler (BuilderIO/gpt-crawler)

Searching Database…

这是什么?一个爬虫,可以抓取网站(一个或多个 URL)的页面,并把内容转换成知识文件,你可以将其上传到 OpenAI,用来创建自定义 GPT 或助手。
这是命令行工具,还是也能作为服务器运行?两种都支持:默认情况下它以命令行或脚本的形式在本地运行,也可以作为带有 /crawl 接口和 Swagger 文档的 Express API 服务器运行,或者在 Docker 容器中运行。
我该怎么把它跑起来?克隆仓库,安装依赖,编辑 config.ts 中的 url 和 selector 属性,使其指向你的网站,然后运行爬虫生成 output.json。
运行之前我需要先安装什么?Node.js 16 或更高版本;Playwright 会通过 preinstall 脚本自动安装。
我上传到 OpenAI 的文件有大小限制吗?有。如果生成的 output.json 对自定义 GPT 来说太大,你需要把它拆分成多个文件,或者使用 maxFileSize 或 maxTokens 配置项将其缩小。
使用输出结果是否需要付费的 ChatGPT 套餐?要在 ChatGPT 界面中创建和使用自定义 GPT,目前可能需要付费的 ChatGPT 套餐;通过 Assistants API 使用输出结果则不需要。
爬虫实际会生成什么?它会在项目根目录输出一个 output.json 文件,其中包含抓取到的内容,可以直接上传到 OpenAI,作为自定义 GPT 或助手的知识库。
我能不改代码就运行它吗?运行前仍需编辑 config.ts,设置目标 URL 和 CSS 选择器;不过使用 Docker 和 API 模式,可以不必直接管理 Node 进程。
它底层使用什么爬取引擎?它基于 Crawlee,使用 Playwright 进行浏览器自动化,可选的 API 服务器则使用 Express。
我能同时抓取多个网站吗?可以,README 明确支持从一个或多个 URL 生成知识文件。
Creator
BuilderIO
Size
0.9 MB
Stars
22.4K
Age
2y
Commits · 90 Days