Skip to content

Commit fe93cbf

Browse files
authored
Refactor agentql repo (#97)
* Refactor agentql repo * Update github action workflow * Change file name to main * Update folder name / readme * add some missing files back into JS examples * rename folder * Update workflow * Update template folder name as well * Address comments * Add JS template file for CLI (#99)
1 parent d0a3ffe commit fe93cbf

File tree

135 files changed

+320
-3452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+320
-3452
lines changed

.dockerignore

Lines changed: 0 additions & 18 deletions
This file was deleted.

.github/workflows/js-precommit.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: JSPre-commit checks
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
paths:
7+
- "examples/js/**"
8+
9+
jobs:
10+
js-pre-commit:
11+
name: JS Pre-commit checks
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout Repository
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v3
19+
with:
20+
node-version: "18"
21+
22+
- name: Install dependencies
23+
working-directory: ./examples/js
24+
run: npm install
25+
26+
- name: Run ESLint
27+
working-directory: ./examples/js
28+
run: npm run lint
29+
30+
- name: Run Prettier
31+
working-directory: ./examples/js
32+
run: npx prettier --check .
Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
name: Pre-commit checks
1+
name: Python Pre-commit checks
22

33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
6+
paths:
7+
- "examples/Python/**"
68

79
jobs:
810
python-pre-commit:
@@ -32,44 +34,25 @@ jobs:
3234
# ----- install dependencies -----
3335
#----------------------------------------------
3436
- name: Install dependencies
37+
working-directory: ./examples/Python
3538
run: |
3639
poetry install --no-interaction --no-root --with dev
3740
3841
- name: Lint check
42+
working-directory: ./examples/Python
3943
run: pylint --disable=R,C application_examples examples
4044

4145
- name: Code style check
46+
working-directory: ./examples/Python
4247
run: black . --check
4348

4449
- name: Imports sort check
50+
working-directory: ./examples/Python
4551
uses: isort/isort-action@master
4652

4753
- name: Static check
54+
working-directory: ./examples/Python
4855
uses: jakebailey/pyright-action@v2
4956
continue-on-error: true
5057
with:
5158
pylance-version: latest-release
52-
53-
js-pre-commit:
54-
name: JS Pre-commit checks
55-
runs-on: ubuntu-latest
56-
steps:
57-
- name: Checkout Repository
58-
uses: actions/checkout@v4
59-
60-
- name: Setup Node.js
61-
uses: actions/setup-node@v3
62-
with:
63-
node-version: "20"
64-
65-
- name: Install dependencies
66-
working-directory: ./javascript-sdk
67-
run: npm install
68-
69-
- name: Run ESLint
70-
working-directory: ./javascript-sdk
71-
run: npm run lint
72-
73-
- name: Run Prettier
74-
working-directory: ./javascript-sdk
75-
run: npx prettier --check .

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ tmp/
3737

3838
*env.local
3939

40-
javascript-sdk/node_modules
40+
examples/js/node_modules/
41+
examples/python/__pycache__/
42+
examples/python/.venv/

.stylelintrc.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

.templates/js/template.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const { chromium } = require('playwright');
2+
const { wrap, configure } = require('agentql');
3+
4+
// Set URLs to the desired websites
5+
const WEBSITE_URL_1 = "<Replace with the correct url>";
6+
const WEBSITE_URL_2 = "<Replace with the correct url>";
7+
const WEBSITE_URL_3 = "<Replace with the correct url>";
8+
9+
async function main() {
10+
// Configure the AgentQL API key
11+
configure({ apiKey: process.env.AGENTQL_API_KEY });
12+
13+
const browser = await chromium.launch({ headless: false });
14+
const context = await browser.newContext();
15+
16+
// Open multiple tabs in the same browser context to fetch data concurrently
17+
await Promise.all([
18+
fetchData(context, WEBSITE_URL_1),
19+
fetchData(context, WEBSITE_URL_2),
20+
fetchData(context, WEBSITE_URL_3),
21+
]);
22+
23+
await browser.close();
24+
}
25+
26+
async function fetchData(context, sessionUrl) {
27+
// Create a page in a new tab in the browser context and wrap it to get access to the AgentQL's querying API
28+
const page = await wrap(await context.newPage());
29+
await page.goto(sessionUrl);
30+
31+
// Update the query to locate the desired element on the page
32+
const elementsQuery = `
33+
{
34+
search_input
35+
search_btn
36+
}
37+
`;
38+
39+
// Locate desired web elements using AgentQL's queryElements() method
40+
const response = await page.queryElements(elementsQuery);
41+
// Update to use the actual query terms to interact with the elements
42+
await response.search_input.fill("<Replace with needed search query>");
43+
await response.search_btn.click();
44+
45+
// Update the query to fetch the desired data from the page
46+
const dataQuery = `
47+
{
48+
products[] {
49+
name
50+
price
51+
}
52+
}
53+
`;
54+
55+
// Fetch the data from the page using AgentQL's queryData() method
56+
const data = await page.queryData(dataQuery);
57+
// Update to use the actual keys corresponding to query terms
58+
console.log(`Prices fetched from ${sessionUrl}:`);
59+
for (const product of data.products) {
60+
console.log(`Product: ${product.name}, Price: ${product.price}`);
61+
}
62+
}
63+
64+
main();
File renamed without changes.
File renamed without changes.

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"eslint.workingDirectories": [
1818
{
19-
"directory": "./javascript-sdk",
19+
"directory": "./examples/js",
2020
"changeProcessCWD": true
2121
}
2222
],
@@ -34,7 +34,7 @@
3434
],
3535
"pylint.importStrategy": "fromEnvironment",
3636
"pylint.args": [
37-
"--rcfile=.pylintrc"
37+
"--rcfile=./examples/python/.pylintrc"
3838
],
3939
"python.analysis.typeCheckingMode": "standard",
4040
"editor.rulers": [100]

0 commit comments

Comments
 (0)