Skip to content

Commit

Permalink
Merge branch 'ts' into updating-package-and-some-minor-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Raghuwanshi authored May 14, 2024
2 parents e10b2d6 + b6d19a9 commit f0d88f4
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,14 @@ export class ChatOpenAi {
Authorization: "Bearer " + this.openAIApiKey,
"content-type": "application/json",
},
},
}
)
.then((response) => {
return response.data.choices;
})
.catch((error) => {
if (error.response) {
console.log(
"Server responded with status code:",
error.response.status,
);
console.log("Server responded with status code:", error.response.status);
console.log("Response data:", error.response.data);
} else if (error.request) {
console.log("No response received:", error);
Expand All @@ -86,17 +83,14 @@ export class ChatOpenAi {
Authorization: `Bearer ${this.openAIApiKey}`,
"content-type": "application/json",
},
},
}
)
.then((response) => {
return response.data.data;
})
.catch((error) => {
if (error.response) {
console.log(
"Server responded with status code:",
error.response.status,
);
console.log("Server responded with status code:", error.response.status);
console.log("Response data:", error.response.data);
} else if (error.request) {
console.log("No response received:", error.request);
Expand All @@ -121,18 +115,15 @@ export class ChatOpenAi {
Authorization: "Bearer " + this.openAIApiKey,
"content-type": "application/json",
},
},
}
)
.then((response) => {
return response.data.choices;
})
.catch((error) => {
console.log({ error });
if (error.response) {
console.log(
"Server responded with status code:",
error.response.status,
);
console.log("Server responded with status code:", error.response.status);
console.log("Response data:", error.response.data);
} else if (error.request) {
console.log("No response received:", error.request);
Expand Down Expand Up @@ -163,17 +154,14 @@ export class ChatOpenAi {
Authorization: "Bearer " + this.openAIApiKey,
"content-type": "application/json",
},
},
}
)
.then(function (response) {
return response.data.choices;
})
.catch(function (error) {
if (error.response) {
console.log(
"Server responded with status code:",
error.response.status,
);
console.log("Server responded with status code:", error.response.status);
console.log("Response data:", error.response.data);
} else if (error.request) {
console.log("No response received:", error.request);
Expand Down
2 changes: 1 addition & 1 deletion JS/edgechains/examples/chat-with-pdf/src/routes/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Supabase } from "arakoodev/vector-db";
import { PdfLoader } from "arakoodev/document-loader";
import { TextSplitter } from "arakoodev/splitter";
import { ArakooServer } from "arakoodev/arakooserver";
import { Spinner } from "cli-spinner"
import { Spinner } from "cli-spinner";
const server = new ArakooServer();

const __dirname = fileURLToPath(import.meta.url);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test, expect } from 'vitest'
import { test, expect } from "vitest";

test('should be return expected answer', async () => {
const res = await fetch("http://localhost:3000/chatWithpdf?question=who is Nirmala Sitharaman")
test("should be return expected answer", async () => {
const res = await fetch("http://localhost:3000/chatWithpdf?question=who is Nirmala Sitharaman");

const data = await res.json()
expect(data.res).toString()
}, 40000);
const data = await res.json();
expect(data.res).toString();
}, 40000);
10 changes: 5 additions & 5 deletions JS/edgechains/examples/chat-with-pdf/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configDefaults, defineConfig } from 'vitest/config'
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, 'packages/template/*'],
},
})
test: {
exclude: [...configDefaults.exclude, "packages/template/*"],
},
});
22 changes: 10 additions & 12 deletions JS/edgechains/examples/react-chain/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

import { ArakooServer } from "arakoodev/arakooserver";
import { ReactChainRouter } from "./routes/react-chain.js";

const server = new ArakooServer();

const app = server.createApp();

app.route("/", ReactChainRouter);

server.listen(5000)

import { ArakooServer } from "arakoodev/arakooserver";
import { ReactChainRouter } from "./routes/react-chain.js";

const server = new ArakooServer();

const app = server.createApp();

app.route("/", ReactChainRouter);

server.listen(5000);
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const axios = require('axios');

function findMatch(text: string, searchString: string): Boolean {
Expand Down Expand Up @@ -47,4 +46,4 @@ function callWikipediaApi() {

}

module.exports = callWikipediaApi;
module.exports = callWikipediaApi;
17 changes: 6 additions & 11 deletions JS/edgechains/examples/react-chain/src/lib/generateResponse.cts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,23 @@ const Jsonnet = require("@arakoodev/jsonnet");
const jsonnet = new Jsonnet();

const secretsPath = path.join(__dirname, "../../jsonnet/secrets.jsonnet");
const openAIApiKey = JSON.parse(jsonnet.evaluateFile(secretsPath)).openai_api_key
const openAIApiKey = JSON.parse(jsonnet.evaluateFile(secretsPath)).openai_api_key;

const openai = new ChatOpenAi({
openAIApiKey,
temperature: 0,
})

});

function openAICall() {

return function (prompt: string) {
try {
return openai.generateResponse(prompt).then((res: any) => {
return res
})

return res;
});
} catch (error) {
return error;
}
}

};
}


module.exports = openAICall;
module.exports = openAICall;
23 changes: 11 additions & 12 deletions JS/edgechains/examples/react-chain/src/lib/getExtractedSummary.cts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
const axios = require('axios');
const axios = require("axios");

function getExtractedSummary() {
return function (pageId: string) {
const url = 'https://en.wikipedia.org/w/api.php';
const url = "https://en.wikipedia.org/w/api.php";
const queryParams = new URLSearchParams({
action: 'query',
format: 'json',
exintro: '',
explaintext: '',
prop: 'extracts',
redirects: '1',
action: "query",
format: "json",
exintro: "",
explaintext: "",
prop: "extracts",
redirects: "1",
pageids: pageId,
});
const apiUrl = `${url}?${queryParams.toString()}`;
try {
return axios(apiUrl).then((res: any) => {
return res.data.query.pages[pageId].extract;
});
}
catch (err) {
} catch (err) {
console.error(err);
}
}
};
}

module.exports = getExtractedSummary;
module.exports = getExtractedSummary;
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ ReactChainRouter.get("/", async (c:any) => {
return c.json({ response: "Any error occured while finding the answer. Please try again!" })
}
})

14 changes: 8 additions & 6 deletions JS/edgechains/examples/react-chain/src/test/react-chain.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { test, expect, } from 'vitest'
import { test, expect } from "vitest";

test('should be return expected answer', async () => {
const res = await fetch("http://localhost:5000?question=Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?")
test("should be return expected answer", async () => {
const res = await fetch(
"http://localhost:5000?question=Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?"
);

const data = await res.json()
expect(data).toContain("Bill Clinton")
}, 40000);
const data = await res.json();
expect(data).toContain("Bill Clinton");
}, 40000);
28 changes: 14 additions & 14 deletions JS/edgechains/examples/react-chain/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"compilerOptions": {
"target": "ES2022",
"moduleResolution": "NodeNext",
"module": "NodeNext",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["./**/*.test.ts", "vitest.config.ts"]
}
{
"compilerOptions": {
"target": "ES2022",
"moduleResolution": "NodeNext",
"module": "NodeNext",
"rootDir": "./src",
"outDir": "./dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["./**/*.test.ts", "vitest.config.ts"]
}
10 changes: 5 additions & 5 deletions JS/edgechains/examples/react-chain/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { configDefaults, defineConfig } from 'vitest/config'
import { configDefaults, defineConfig } from "vitest/config";

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, 'packages/template/*'],
},
})
test: {
exclude: [...configDefaults.exclude, "packages/template/*"],
},
});

0 comments on commit f0d88f4

Please sign in to comment.