Skip to content

Commit

Permalink
doing-minor-fixes-for-build
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Raghuwanshi committed Jun 4, 2024
1 parent 1859524 commit 2dfab45
Show file tree
Hide file tree
Showing 26 changed files with 98 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ArakooServer {
return this.app;
}

listen(port: number) {
listen(port?: number) {
const portNumber = port || 3000;

serve(
Expand Down
5 changes: 2 additions & 3 deletions JS/edgechains/examples/chat-with-llm/dist/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
1 change: 1 addition & 0 deletions JS/edgechains/examples/chat-with-llm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion JS/edgechains/examples/chat-with-llm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions JS/edgechains/examples/chat-with-pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 13 additions & 4 deletions JS/edgechains/examples/chat-with-pdf/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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("|/-\\");
Expand Down
4 changes: 2 additions & 2 deletions JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function openAICall() {
return openai.zodSchemaResponse({ prompt, schema: schema }).then((res) => {
return JSON.stringify(res);
});
} catch (error) {
}
catch (error) {
return error;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion JS/edgechains/examples/react-chain/jsonnet/secrets.jsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

local OPENAI_API_KEY = "sk-**";
local OPENAI_API_KEY = "sk-proj-***";

{
"openai_api_key":OPENAI_API_KEY,
Expand Down
4 changes: 4 additions & 0 deletions JS/edgechains/examples/react-chain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 1 addition & 3 deletions JS/edgechains/examples/react-chain/src/routes/react-chain.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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"));

Expand Down
3 changes: 2 additions & 1 deletion JS/edgechains/examples/summarize-page/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions JS/edgechains/examples/summarize-page/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
2 changes: 1 addition & 1 deletion JS/edgechains/examples/summarize-page/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 2dfab45

Please sign in to comment.