-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
browser automation support #668
Changes from 5 commits
298ee5d
7db0f07
eebbb79
0c170e2
b1d5130
3e4b3ce
3ebc166
388179d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,8 +49,8 @@ | |
Extension](/genaiscript/getting-started/installation/) to get started. | ||
</Card> | ||
<Card title="Configure your LLMs" icon="setting"> | ||
Configure the [secrets](/genaiscript/getting-started/configuration) to access your | ||
LLMs. | ||
Configure the [secrets](/genaiscript/getting-started/configuration) to | ||
access your LLMs. | ||
</Card> | ||
<Card title="Write your first script" icon="pencil"> | ||
Follow [Getting | ||
|
@@ -190,9 +190,19 @@ | |
Grep or fuzz search [files](/genaiscript/referen/script/files) | ||
|
||
```js wrap | ||
const { files } = await workspace.grep( | ||
/[a-z][a-z0-9]+/, | ||
"**/*.md") | ||
const { files } = await workspace.grep(/[a-z][a-z0-9]+/, "**/*.md") | ||
``` | ||
|
||
</Card> | ||
|
||
<Card title="Browser automation" icon="document"> | ||
|
||
Browse and scrape the web with [Playwright](/genaiscript/reference/scripts/browse). | ||
|
||
```js | ||
const page = await host.browse("https://...") | ||
const table = await page.locator("table[...]").innerHTML() | ||
def("TABLE", HTML.convertToMarkdown(table)) | ||
``` | ||
|
||
</Card> | ||
|
@@ -233,17 +243,19 @@ | |
<Card title="LLM Tools" icon="setting"> | ||
|
||
Register JavaScript functions as [LLM tools](/genaiscript/reference/scripts/tools/) | ||
|
||
```js wrap | ||
defTool("weather", "live weahter", | ||
{ city: "Paris" }, // schema | ||
async ({ city }) => // callback | ||
defTool("weather", "live weahter", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a typo in the word "weahter". It should be "weather".
|
||
{ city: "Paris" }, // schema | ||
async ({ city }) => // callback | ||
{ ... "sunny" } | ||
) | ||
``` | ||
|
||
or use built-in [@agentic tools](/genaiscript/guides/agentic-tools/) | ||
|
||
```js wrap | ||
import { WeatherClient } | ||
from "@agentic/weather" | ||
import { WeatherClient } from "@agentic/weather" | ||
defTool(new WeatherClient()) | ||
``` | ||
|
||
|
@@ -254,7 +266,7 @@ | |
Let the LLM run code in a sandboxed execution environment. | ||
|
||
```js wrap | ||
script({ tools: ["python_code_interpreter"]}) | ||
script({ tools: ["python_code_interpreter"] }) | ||
``` | ||
|
||
</Card> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
title: Browse | ||
sidebar: | ||
order: 30 | ||
--- | ||
|
||
GenAIScript provides a simplified API to interact with a headless browser using [Playwright](https://playwright.dev/) . | ||
This allows you to interact with web pages, scrape data, and automate tasks. | ||
|
||
```js | ||
const page = await host.browse( | ||
"https://github.com/microsoft/genaiscript/blob/main/packages/sample/src/penguins.csv" | ||
) | ||
const table = page.locator('table[data-testid="csv-table"]') | ||
const csv = parsers.HTMLToMarkdown(await table.innerHTML()) | ||
def("DATA", csv) | ||
$`Analyze DATA.` | ||
``` | ||
|
||
# `host.browse` | ||
|
||
This function launches a new browser instance and optionally navigates to the page. | ||
|
||
```js | ||
const page = await host.browse(url) | ||
``` | ||
|
||
You can configure a number of options for the browser instance: | ||
|
||
```js | ||
const page = await host.browse(url, { incognito: true }) | ||
``` | ||
|
||
## (Advanced) Native Playwright APIs | ||
|
||
The `page` instance returned is a native [Playwright Page](https://playwright.dev/docs/api/class-page) object. | ||
You can import `playwright` and case the instance back to the native playwright object. | ||
|
||
```js | ||
import { Page } from "playwright" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a typo here. The correct word should be "cast" not "case".
|
||
const page = await host.browse(url) as Page | ||
``` | ||
Check notice on line 43 in docs/src/content/docs/reference/scripts/browse.md GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new file "browse.md" has been added in the "scripts" reference section. This file provides documentation for interacting with a headless browser using Playwright.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a typo in the word "weahter". It should be "weather".