From 2dfab457d822c102b0791ee941476d5568883b17 Mon Sep 17 00:00:00 2001 From: shyam-raghuwanshi Date: Tue, 4 Jun 2024 16:15:29 +0530 Subject: [PATCH] doing-minor-fixes-for-build --- .../src/arakooserver/src/lib/hono/hono.ts | 2 +- .../examples/chat-with-llm/dist/index.js | 5 ++--- .../examples/chat-with-llm/package.json | 1 + .../examples/chat-with-llm/src/index.ts | 2 +- .../examples/chat-with-pdf/package.json | 3 +++ .../examples/chat-with-pdf/readme.md | 17 +++++++++++---- .../chat-with-pdf/src/lib/InsertToSupabase.ts | 4 ++-- .../examples/chat-with-pdf/src/routes/chat.ts | 4 ++-- .../dist/index.js | 2 +- .../dist/lib/lookupTime.cjs | 17 ++++++++------- .../dist/lib/lookupWeather.cjs | 15 ++++++------- .../dist/lib/openAIChat.cjs | 21 ++++++++++--------- .../dist/lib/openAIFunction.cjs | 21 ++++++++++--------- .../package.json | 5 +++++ .../src/index.ts | 2 +- .../language-translater/backend/dist/index.js | 2 +- .../backend/dist/lib/generateResponse.cjs | 3 ++- .../language-translater/backend/src/index.ts | 2 +- .../react-chain/jsonnet/secrets.jsonnet | 2 +- .../examples/react-chain/package.json | 4 ++++ .../react-chain/src/routes/react-chain.ts | 4 +--- .../examples/summarize-page/dist/index.js | 3 ++- .../dist/lib/generateResponse.cjs | 6 +++--- .../dist/lib/getDataFromUrl.cjs | 11 +++++++--- .../examples/summarize-page/package.json | 3 +++ .../examples/summarize-page/src/index.ts | 2 +- 26 files changed, 98 insertions(+), 65 deletions(-) diff --git a/JS/edgechains/arakoodev/src/arakooserver/src/lib/hono/hono.ts b/JS/edgechains/arakoodev/src/arakooserver/src/lib/hono/hono.ts index 84b266d40..6d5c5550e 100644 --- a/JS/edgechains/arakoodev/src/arakooserver/src/lib/hono/hono.ts +++ b/JS/edgechains/arakoodev/src/arakooserver/src/lib/hono/hono.ts @@ -18,7 +18,7 @@ export class ArakooServer { return this.app; } - listen(port: number) { + listen(port?: number) { const portNumber = port || 3000; serve( diff --git a/JS/edgechains/examples/chat-with-llm/dist/index.js b/JS/edgechains/examples/chat-with-llm/dist/index.js index 694a2300e..01754b35d 100644 --- a/JS/edgechains/examples/chat-with-llm/dist/index.js +++ b/JS/edgechains/examples/chat-with-llm/dist/index.js @@ -1,9 +1,8 @@ -//@ts-ignore import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore -import createClient from 'sync-rpc'; -import { fileURLToPath } from "url"; +import createClient from "sync-rpc"; +import fileURLToPath from "file-uri-to-path"; import path from "path"; const server = new ArakooServer(); const app = server.createApp(); diff --git a/JS/edgechains/examples/chat-with-llm/package.json b/JS/edgechains/examples/chat-with-llm/package.json index 80e58a0b4..c013005c7 100644 --- a/JS/edgechains/examples/chat-with-llm/package.json +++ b/JS/edgechains/examples/chat-with-llm/package.json @@ -13,6 +13,7 @@ "dependencies": { "@arakoodev/edgechains.js": "^0.1.23", "@arakoodev/jsonnet": "^0.3.1", + "path": "^0.12.7", "sync-rpc": "^1.3.6", "zod": "^3.23.8" }, diff --git a/JS/edgechains/examples/chat-with-llm/src/index.ts b/JS/edgechains/examples/chat-with-llm/src/index.ts index d17ac79c2..7046cfc0c 100644 --- a/JS/edgechains/examples/chat-with-llm/src/index.ts +++ b/JS/edgechains/examples/chat-with-llm/src/index.ts @@ -3,7 +3,7 @@ import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore import createClient from "sync-rpc"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import path from "path"; const server = new ArakooServer(); diff --git a/JS/edgechains/examples/chat-with-pdf/package.json b/JS/edgechains/examples/chat-with-pdf/package.json index fdffae838..0a2083481 100644 --- a/JS/edgechains/examples/chat-with-pdf/package.json +++ b/JS/edgechains/examples/chat-with-pdf/package.json @@ -17,12 +17,15 @@ "@arakoodev/jsonnet": "^0.3.1", "@babel/preset-env": "^7.24.4", "cli-spinner": "^0.2.10", + "file-uri-to-path": "^2.0.0", + "path": "^0.12.7", "regenerator-runtime": "^0.14.1", "sync-rpc": "^1.3.6", "zod": "^3.23.8" }, "devDependencies": { "@types/cli-spinner": "^0.2.3", + "@types/node": "^20.14.1", "esbuild": "^0.20.2" } } diff --git a/JS/edgechains/examples/chat-with-pdf/readme.md b/JS/edgechains/examples/chat-with-pdf/readme.md index e5f10bbdf..e4cb59423 100644 --- a/JS/edgechains/examples/chat-with-pdf/readme.md +++ b/JS/edgechains/examples/chat-with-pdf/readme.md @@ -89,11 +89,20 @@ as $$ - You should see a success message in the Result tab. ![image](https://github.com/Shyam-Raghuwanshi/EdgeChains/assets/94217498/052d9a15-838f-4e68-9888-072cecb78a13) -5. Run the example -``` - npm run start -``` +## Usage + +1. Start the server: + + ```bash + npm run start + ``` + +2. Hit the `GET` endpoint. + + ```bash + http://localhost:3000/chatWithpdf?question=who is nirmala sitaraman + ``` - Then you can run the ChatWithPdf example using npm run start and continue chatting with the example.pdf. diff --git a/JS/edgechains/examples/chat-with-pdf/src/lib/InsertToSupabase.ts b/JS/edgechains/examples/chat-with-pdf/src/lib/InsertToSupabase.ts index 80c946617..1ac68672f 100644 --- a/JS/edgechains/examples/chat-with-pdf/src/lib/InsertToSupabase.ts +++ b/JS/edgechains/examples/chat-with-pdf/src/lib/InsertToSupabase.ts @@ -1,4 +1,4 @@ -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import { Spinner } from "cli-spinner" import { PdfLoader } from "@arakoodev/edgechains.js/document-loader"; import { TextSplitter } from "@arakoodev/edgechains.js/splitter"; @@ -32,7 +32,7 @@ const supabaseUrl = await JSON.parse(secretsLoader).supabase_url; const supabase = new Supabase(supabaseUrl, supabaseApiKey); const client = supabase.createClient(); -export async function InsertToSupabase(content:any) { +export async function InsertToSupabase(content: any) { var spinner = new Spinner("Inserting to Supabase.. %s"); try { spinner.setSpinnerString("|/-\\"); diff --git a/JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts b/JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts index 2b29f9e25..29ef75d73 100644 --- a/JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts +++ b/JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts @@ -1,7 +1,7 @@ import path from "path"; //@ts-ignore import createClient from "sync-rpc" -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import { InsertToSupabase, splitedDocs } from "../lib/InsertToSupabase.js"; @@ -17,7 +17,7 @@ const getQueryMatch = createClient(path.join(__dirname, "../../lib/getQueryMatch const getEmbeddings = createClient(path.join(__dirname, "../../lib/getEmbeddings.cjs")); // this should run only once for uploding pdf data to supabase then you can continue with the chatbot functionality -await InsertToSupabase(splitedDocs); +// await InsertToSupabase(splitedDocs); export const ChatRouter: any = server.createApp(); diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/index.js b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/index.js index 57549f2d0..e1d445670 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/index.js +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/index.js @@ -1,5 +1,5 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path"; import Jsonnet from "@arakoodev/jsonnet"; import path from "path"; //@ts-ignore diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupTime.cjs b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupTime.cjs index 6e3e6e414..db9300ff4 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupTime.cjs +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupTime.cjs @@ -8,16 +8,17 @@ function lookupTime() { const response = axios .get(`http://worldtimeapi.org/api/timezone/${location}`) .then((response) => { - const { datetime } = response.data; - const dateTime = moment.tz(datetime, location).format("h:mmA"); - const timeResponse = `The current time in ${location} is ${dateTime}.`; - return timeResponse; - }) + const { datetime } = response.data; + const dateTime = moment.tz(datetime, location).format("h:mmA"); + const timeResponse = `The current time in ${location} is ${dateTime}.`; + return timeResponse; + }) .catch((error) => { - console.error(error); - }); + console.error(error); + }); return response; - } catch (error) { + } + catch (error) { console.error(error); } }; diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupWeather.cjs b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupWeather.cjs index c1c110f3e..695fde722 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupWeather.cjs +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/lookupWeather.cjs @@ -23,19 +23,20 @@ function lookupWeather() { const response = axios .request(options) .then((response) => { - const weather = response.data; - const weatherForecast = `Location: ${weather.location.name} \ + const weather = response.data; + const weatherForecast = `Location: ${weather.location.name} \ Current Temperature: ${weather.current.temp_c} \ Condition: ${weather.current.condition.text}. \ Low Today: ${weather.forecast.forecastday[0].day.mintemp_c} \ High Today: ${weather.forecast.forecastday[0].day.maxtemp_c}`; - return weatherForecast; - }) + return weatherForecast; + }) .catch((error) => { - console.error(error); - }); + console.error(error); + }); return response; - } catch (error) { + } + catch (error) { console.error(error); return "No forecast found"; } diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIChat.cjs b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIChat.cjs index 96ccfbd72..f26d23f8e 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIChat.cjs +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIChat.cjs @@ -14,19 +14,20 @@ function openAIChat() { try { const completion = openai .chat({ - model: "gpt-3.5-turbo-0613", - messages: [ - { role: "user", content: "Summarize the following input." + prompt }, - ], - }) + model: "gpt-3.5-turbo-0613", + messages: [ + { role: "user", content: "Summarize the following input." + prompt }, + ], + }) .then((completion) => { - return JSON.stringify(completion); - }) + return JSON.stringify(completion); + }) .catch((error) => { - console.error(error); - }); + console.error(error); + }); return completion; - } catch (error) { + } + catch (error) { console.error(error); } }; diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIFunction.cjs b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIFunction.cjs index 20d4d3232..6a6cba021 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIFunction.cjs +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/dist/lib/openAIFunction.cjs @@ -14,19 +14,20 @@ function openAIFunction() { try { const completion = openai .chatWithFunction({ - model: "gpt-3.5-turbo-0613", - messages: [{ role: "user", content: prompt }], - functions, - function_call: "auto", - }) + model: "gpt-3.5-turbo-0613", + messages: [{ role: "user", content: prompt }], + functions, + function_call: "auto", + }) .then((completion) => { - return JSON.stringify(completion); - }) + return JSON.stringify(completion); + }) .catch((error) => { - console.error(error); - }); + console.error(error); + }); return completion; - } catch (error) { + } + catch (error) { console.error(error); } }; diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/package.json b/JS/edgechains/examples/getWeather-or-time-function-calling/package.json index 9b47d4d6e..a64a461e4 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/package.json +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/package.json @@ -15,8 +15,13 @@ "@arakoodev/edgechains.js": "^0.1.23", "@arakoodev/jsonnet": "^0.2.1", "axios": "^1.7.1", + "file-uri-to-path": "^2.0.0", "moment-timezone": "^0.5.45", "openai": "^4.47.1", "sync-rpc": "^1.3.6" + }, + "devDependencies": { + "@types/node": "^20.14.1", + "path": "^0.12.7" } } diff --git a/JS/edgechains/examples/getWeather-or-time-function-calling/src/index.ts b/JS/edgechains/examples/getWeather-or-time-function-calling/src/index.ts index f9168a551..9eff5eb6f 100644 --- a/JS/edgechains/examples/getWeather-or-time-function-calling/src/index.ts +++ b/JS/edgechains/examples/getWeather-or-time-function-calling/src/index.ts @@ -1,5 +1,5 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import Jsonnet from "@arakoodev/jsonnet"; import path from "path"; diff --git a/JS/edgechains/examples/language-translater/backend/dist/index.js b/JS/edgechains/examples/language-translater/backend/dist/index.js index 67dd66300..68f1feb22 100644 --- a/JS/edgechains/examples/language-translater/backend/dist/index.js +++ b/JS/edgechains/examples/language-translater/backend/dist/index.js @@ -2,7 +2,7 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore import createClient from "sync-rpc"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path"; import path from "path"; const server = new ArakooServer(); const app = server.createApp(); diff --git a/JS/edgechains/examples/language-translater/backend/dist/lib/generateResponse.cjs b/JS/edgechains/examples/language-translater/backend/dist/lib/generateResponse.cjs index de7f355cc..62c1762be 100644 --- a/JS/edgechains/examples/language-translater/backend/dist/lib/generateResponse.cjs +++ b/JS/edgechains/examples/language-translater/backend/dist/lib/generateResponse.cjs @@ -17,7 +17,8 @@ function openAICall() { return openai.zodSchemaResponse({ prompt, schema: schema }).then((res) => { return JSON.stringify(res); }); - } catch (error) { + } + catch (error) { return error; } }; diff --git a/JS/edgechains/examples/language-translater/backend/src/index.ts b/JS/edgechains/examples/language-translater/backend/src/index.ts index ccd853ff0..ceb77510d 100644 --- a/JS/edgechains/examples/language-translater/backend/src/index.ts +++ b/JS/edgechains/examples/language-translater/backend/src/index.ts @@ -2,7 +2,7 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore import createClient from "sync-rpc"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import path from "path"; const server = new ArakooServer(); diff --git a/JS/edgechains/examples/react-chain/jsonnet/secrets.jsonnet b/JS/edgechains/examples/react-chain/jsonnet/secrets.jsonnet index aa979aece..978cacd33 100644 --- a/JS/edgechains/examples/react-chain/jsonnet/secrets.jsonnet +++ b/JS/edgechains/examples/react-chain/jsonnet/secrets.jsonnet @@ -1,5 +1,5 @@ -local OPENAI_API_KEY = "sk-**"; +local OPENAI_API_KEY = "sk-proj-***"; { "openai_api_key":OPENAI_API_KEY, diff --git a/JS/edgechains/examples/react-chain/package.json b/JS/edgechains/examples/react-chain/package.json index ce601d1a4..e0d5f3450 100644 --- a/JS/edgechains/examples/react-chain/package.json +++ b/JS/edgechains/examples/react-chain/package.json @@ -14,10 +14,14 @@ "dependencies": { "@arakoodev/edgechains.js": "^0.1.23", "@arakoodev/jsonnet": "^0.3.1", + "axios": "^1.7.2", + "file-uri-to-path": "^2.0.0", + "path": "^0.12.7", "sync-rpc": "^1.3.6" }, "devDependencies": { "@types/deasync": "^0.1.5", + "@types/node": "^20.14.1", "vitest": "^1.5.3" } } diff --git a/JS/edgechains/examples/react-chain/src/routes/react-chain.ts b/JS/edgechains/examples/react-chain/src/routes/react-chain.ts index a02a89b17..7cb16933d 100644 --- a/JS/edgechains/examples/react-chain/src/routes/react-chain.ts +++ b/JS/edgechains/examples/react-chain/src/routes/react-chain.ts @@ -1,6 +1,6 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import Jsonnet from "@arakoodev/jsonnet"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import path from "path"; //@ts-ignore import createClient from "sync-rpc"; @@ -9,8 +9,6 @@ const server = new ArakooServer(); const jsonnet = new Jsonnet(); const __dirname = fileURLToPath(import.meta.url); -// const getExtractedSummary = createClient(path.join(__dirname, "../../lib/getExtractedSummary.cjs")); -// const callWikipediaApi = createClient(path.join(__dirname, "../../lib/callWikipediaApi.cjs")); const openAICall = createClient(path.join(__dirname, "../../lib/generateResponse.cjs")); const apiCall = createClient(path.join(__dirname, "../../lib/apiCall.cjs")); diff --git a/JS/edgechains/examples/summarize-page/dist/index.js b/JS/edgechains/examples/summarize-page/dist/index.js index c17473d21..c4055ed4b 100644 --- a/JS/edgechains/examples/summarize-page/dist/index.js +++ b/JS/edgechains/examples/summarize-page/dist/index.js @@ -2,7 +2,7 @@ import { ArakooServer } from "@arakoodev/edgechains.js/arakooserver"; import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore import createClient from "sync-rpc"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path"; import path from "path"; const server = new ArakooServer(); const app = server.createApp(); @@ -16,6 +16,7 @@ app.get("/", async (c) => { jsonnet.javascriptCallback("openAICall", openAICall); jsonnet.javascriptCallback("getPageContent", getPageContent); let response = jsonnet.evaluateFile(path.join(__dirname, "../../jsonnet/main.jsonnet")); + console.log(response); return c.json(response); }); server.listen(3000); diff --git a/JS/edgechains/examples/summarize-page/dist/lib/generateResponse.cjs b/JS/edgechains/examples/summarize-page/dist/lib/generateResponse.cjs index b49febcdb..5a5f489ac 100644 --- a/JS/edgechains/examples/summarize-page/dist/lib/generateResponse.cjs +++ b/JS/edgechains/examples/summarize-page/dist/lib/generateResponse.cjs @@ -17,11 +17,11 @@ const openai = new OpenAI({ function openAICall() { return function (prompt) { try { - return openai.zodSchemaResponse({ prompt, schema: schema }).then((res) => { - console.log({ res }); + return openai.zodSchemaResponse({ prompt, schema }).then((res) => { return JSON.stringify(res); }); - } catch (error) { + } + catch (error) { return error; } }; diff --git a/JS/edgechains/examples/summarize-page/dist/lib/getDataFromUrl.cjs b/JS/edgechains/examples/summarize-page/dist/lib/getDataFromUrl.cjs index a60eb860f..b9201fb0c 100644 --- a/JS/edgechains/examples/summarize-page/dist/lib/getDataFromUrl.cjs +++ b/JS/edgechains/examples/summarize-page/dist/lib/getDataFromUrl.cjs @@ -4,9 +4,14 @@ const { WebScraper } = require("@arakoodev/edgechains.js/scraper"); const scraper = new WebScraper(); function getPageContent() { return (url) => { - return scraper.getContent(url).then((res) => { - return res; - }); + try { + return scraper.getContent(url).then((res) => { + return res; + }); + } + catch (error) { + console.log(error); + } }; } module.exports = getPageContent; diff --git a/JS/edgechains/examples/summarize-page/package.json b/JS/edgechains/examples/summarize-page/package.json index 838417b13..b56185e4b 100644 --- a/JS/edgechains/examples/summarize-page/package.json +++ b/JS/edgechains/examples/summarize-page/package.json @@ -13,10 +13,13 @@ "dependencies": { "@arakoodev/edgechains.js": "^0.1.23", "@arakoodev/jsonnet": "^0.3.1", + "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/summarize-page/src/index.ts b/JS/edgechains/examples/summarize-page/src/index.ts index 38474c079..baf166f22 100644 --- a/JS/edgechains/examples/summarize-page/src/index.ts +++ b/JS/edgechains/examples/summarize-page/src/index.ts @@ -3,7 +3,7 @@ import Jsonnet from "@arakoodev/jsonnet"; //@ts-ignore import createClient from "sync-rpc"; -import { fileURLToPath } from "url"; +import fileURLToPath from "file-uri-to-path" import path from "path"; const server = new ArakooServer();