diff --git a/JS/edgechains/examples/rpa-challenge/.gitignore b/JS/edgechains/examples/rpa-challenge/.gitignore new file mode 100644 index 00000000..76add878 --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/JS/edgechains/examples/rpa-challenge/jsonnet/main.jsonnet b/JS/edgechains/examples/rpa-challenge/jsonnet/main.jsonnet new file mode 100644 index 00000000..99c9bcfc --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/jsonnet/main.jsonnet @@ -0,0 +1,8 @@ +local promptTemplate = ||| + go to https://rpachallenge.com/ and click on the start button we have fiels in this pattern First Name Last Name Company Name Role in Company Address Email Phone Number and then fill this fields John Smith IT Solutions Analyst 98 North Road jsmith@itsolutions.co.uk 40716543298 in the given inputs and click the input with value Submit and then fill this fields Jane Dorsey MediCare Medical Engineer 11 Crown Street jdorsey@mc.com 40791345621 in the given inputs and click the input with value Submit and then fill this fields Albert Kipling Waterfront Accountant 22 Guild Street kipling@waterfront.com 40735416854 in the given inputs and click the input with value Submit and then fill this fields Michael Robertson MediCare IT Specialist 17 Farburn Terrace mrobertson@mc.com 40733652145 in the given inputs and click the input with value Submit and then fill this fields Doug Derrick Timepath Inc. Analyst 99 Shire Oak Road dderrick@timepath.co.uk 40799885412 in the given inputs and click the input with value Submit and then fill this fields Jessie Marlowe Aperture Inc. Scientist 27 Cheshire Street jmarlowe@aperture.us40733154268 in the given inputs and click the input with value Submit and then fill this fields Stan Hamm Sugarwell Advisor 10 Dam Road shamm@sugarwell.org 40712462257 in the given inputs and click the input with value Submit and then fill this fields Michelle Norton Aperture Inc. Scientist 13 White Rabbit Street mnorton@aperture.us 40731254562 in the given inputs and click the input with value Submit and then fill this fields Stacy Shelby TechDev HR Manager 19 Pineapple Boulevard sshelby@techdev.com 40741785214 in the given inputs and click the input with value Submit and then fill this fields Lara Palmer Timepath Inc. Programmer 87 Orange Street lpalmer@timepath.co.uk 40731653845 in the given inputs and click the input with value Submit + |||; + +local key = std.extVar('openai_api_key'); +local content = arakoo.native("call")({task:promptTemplate, openai:key}); + +content \ No newline at end of file diff --git a/JS/edgechains/examples/rpa-challenge/jsonnet/secrets.jsonnet b/JS/edgechains/examples/rpa-challenge/jsonnet/secrets.jsonnet new file mode 100644 index 00000000..0f65557f --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/jsonnet/secrets.jsonnet @@ -0,0 +1,7 @@ + +local OPENAI_API_KEY = "sk-***"; + +{ + "openai_api_key":OPENAI_API_KEY, +} + diff --git a/JS/edgechains/examples/rpa-challenge/package.json b/JS/edgechains/examples/rpa-challenge/package.json new file mode 100644 index 00000000..0403b144 --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/package.json @@ -0,0 +1,25 @@ +{ + "name": "summarizer-app", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "keywords": [], + "author": "", + "scripts": { + "start": "tsc && node --experimental-wasm-modules ./dist/index.js" + }, + "license": "ISC", + "dependencies": { + "@arakoodev/edgechains.js": "file:../../arakoodev", + "@arakoodev/jsonnet": "^0.25.0", + "file-uri-to-path": "^2.0.0", + "path": "^0.12.7", + "sync-rpc": "^1.3.6", + "zod": "^3.23.8" + }, + "devDependencies": { + "@types/node": "^20.14.1", + "@types/request": "^2.48.12" + } +} diff --git a/JS/edgechains/examples/rpa-challenge/readme.md b/JS/edgechains/examples/rpa-challenge/readme.md new file mode 100644 index 00000000..64c7b882 --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/readme.md @@ -0,0 +1,35 @@ +## Video + + ``` + https://youtu.be/iqph8HA4nas + ``` + +## Installation + +1. Install the required dependencies: + + ```bash + npm install + ``` + +## Configuration + +1 Add OpenAiApi key in secrets.jsonnet +`bash + local OPENAI_API_KEY = "sk-****"; + ` + +## Usage + +1. Start the server: + + ```bash + npm run start + ``` + +2. Hit the `GET` endpoint. + + ```bash + + http://localhost:3000/ + ``` diff --git a/JS/edgechains/examples/rpa-challenge/src/index.ts b/JS/edgechains/examples/rpa-challenge/src/index.ts new file mode 100644 index 00000000..57084fba --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/src/index.ts @@ -0,0 +1,25 @@ +import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; +import Jsonnet from "@arakoodev/jsonnet"; +//@ts-ignore +import createClient from "@arakoodev/edgechains.js/sync-rpc"; +import fileURLToPath from "file-uri-to-path"; +import path from "path"; +const server = new ArakooServer(); + +const app = server.createApp(); + +const jsonnet = new Jsonnet(); +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const call = createClient(path.join(__dirname, "./lib/playwright.cjs")); +app.get("/", async (c: any) => { + const key = JSON.parse( + jsonnet.evaluateFile(path.join(__dirname, "../jsonnet/secrets.jsonnet")) + ).openai_api_key; + + jsonnet.extString("openai_api_key", key); + jsonnet.javascriptCallback("call", call); + let response = jsonnet.evaluateFile(path.join(__dirname, "../jsonnet/main.jsonnet")); + return c.text(response); +}); + +server.listen(3000); diff --git a/JS/edgechains/examples/rpa-challenge/src/lib/playwright.ts b/JS/edgechains/examples/rpa-challenge/src/lib/playwright.ts new file mode 100644 index 00000000..5cb49c9f --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/src/lib/playwright.ts @@ -0,0 +1,12 @@ +import { Playwright } from "@arakoodev/edgechains.js/scraper"; + +async function call({ task, openai }: { task: string, openai: string }) { + const scraper = new Playwright({ apiKey: openai }); + try { + return await scraper.call({ task, headless: false }); + } catch (error) { + console.log(error); + } +} + +module.exports = call; diff --git a/JS/edgechains/examples/rpa-challenge/tsconfig.json b/JS/edgechains/examples/rpa-challenge/tsconfig.json new file mode 100644 index 00000000..01890f93 --- /dev/null +++ b/JS/edgechains/examples/rpa-challenge/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "ES2022", + "moduleResolution": "NodeNext", + "module": "NodeNext", + "rootDir": "./src", + "outDir": "./dist", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "jsx": "react-jsx", + "jsxImportSource": "hono/jsx" + }, + "exclude": ["./**/*.test.ts", "vitest.config.ts"] +}