Skip to content
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

updating-library-version-and video link #400

Merged
merged 2 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions JS/edgechains/arakoodev/src/scraper/src/utils/page-parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { parse } from "node-html-parser";
import { JSDOM } from "jsdom";
import fs from "fs";
import { parse } from 'node-html-parser';
import { JSDOM } from 'jsdom';
const { document } = new JSDOM(`...`).window;

const tagsToLog = [
Expand Down Expand Up @@ -32,7 +31,6 @@ const tagsToLog = [

function createElement(node) {
const elem = document.createElement(node.tagName);
fs.writeFileSync("node.json", JSON.stringify(node.attributes) + "\n\n\n\n", { flag: "a" });

const dataAttributes = Object.entries(node.attributes).filter(
(a) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async function openAICall({ prompt, openAIApiKey }) {
try {
const openai = new OpenAI({ apiKey: openAIApiKey });
let res = await openai.zodSchemaResponse({ prompt, schema: schema });
console.log({ res });
return JSON.stringify(res);
} catch (error) {
return error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
Object.defineProperty(exports, "__esModule", { value: true });
const scraper_1 = require("@arakoodev/edgechains.js/scraper");
const scraper = new scraper_1.Playwright();
async function getPageContent({ pageUrl, openai }) {
async function getPageContent({ task, openai }) {
try {
return await scraper.call({
chatApi: openai,
task: `go to ${pageUrl} and scrap the hole page text`,
headless: false,
});
} catch (error) {
return await scraper.call({ chatApi: openai, task, headless: false });
}
catch (error) {
console.log(error);
}
}
Expand Down
3 changes: 2 additions & 1 deletion JS/edgechains/examples/summarize-page/jsonnet/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ local promptTemplate = |||


local pageUrl = std.extVar("pageUrl");
local task = "go to" + pageUrl + "and scrap the hole page text";
local key = std.extVar('openai_api_key');
local getPageContent(pageUrl) =
local content = arakoo.native("getPageContent")({pageUrl:pageUrl, openai:key});
local content = arakoo.native("getPageContent")({task:task, openai:key});
local pageContent = std.slice(content, 0, 20000, 1);
local promptWithPageContent = std.strReplace(promptTemplate,'{content}', pageContent + "\n");
promptWithPageContent;
Expand Down
4 changes: 2 additions & 2 deletions JS/edgechains/examples/summarize-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"license": "ISC",
"dependencies": {
"@arakoodev/edgechains.js": "file:../../arakoodev",
"@arakoodev/jsonnet": "^0.23.6",
"@arakoodev/edgechains.js": "^0.25.0",
"@arakoodev/jsonnet": "^0.25.0",
"file-uri-to-path": "^2.0.0",
"path": "^0.12.7",
"sync-rpc": "^1.3.6",
Expand Down
2 changes: 1 addition & 1 deletion JS/edgechains/examples/summarize-page/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Video

```
https://youtu.be/4gouiNUuBr4
https://youtu.be/S289kMubG10
```

## Installation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ async function openAICall({ prompt, openAIApiKey }: any) {
try {
const openai = new OpenAI({ apiKey: openAIApiKey });
let res = await openai.zodSchemaResponse({ prompt, schema: schema });
console.log({ res });
return JSON.stringify(res);
} catch (error) {
return error;
}
}


module.exports = openAICall;
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Playwright } from "@arakoodev/edgechains.js/scraper";
const scraper = new Playwright();

async function getPageContent({ pageUrl, openai }: { pageUrl: string; openai: string }) {
async function getPageContent({ task, openai }: { task: string, openai: string }) {
try {
return await scraper.call({
chatApi: openai,
task: `go to ${pageUrl} and scrap the hole page text`,
headless: false,
});
return await scraper.call({ chatApi: openai, task, headless: false });
} catch (error) {
console.log(error);
}
Expand Down
Loading