Skip to content

Commit

Permalink
Automatically applying Prettier changes
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Apr 22, 2024
1 parent a300904 commit e7b2d9d
Show file tree
Hide file tree
Showing 34 changed files with 462 additions and 316 deletions.
2 changes: 1 addition & 1 deletion JS/edgechains/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Installation

```
npm install arakoodev
```
```
2 changes: 1 addition & 1 deletion JS/edgechains/arakooserver/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"moduleResolution": "NodeNext",
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"rootDir": "./src"
},
"exclude": ["node_modules", "dist", "./**/*.test.ts"]
}
7 changes: 6 additions & 1 deletion JS/edgechains/db/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.PostgresClient = void 0;
var PostgresClient_js_1 = require("./lib/postgres-client/PostgresClient.js");
Object.defineProperty(exports, "PostgresClient", { enumerable: true, get: function () { return PostgresClient_js_1.PostgresClient; } });
Object.defineProperty(exports, "PostgresClient", {
enumerable: true,
get: function () {
return PostgresClient_js_1.PostgresClient;
},
});
2 changes: 1 addition & 1 deletion JS/edgechains/db/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"moduleResolution": "NodeNext",
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"rootDir": "./src"
},
"exclude": ["node_modules", "dist", "./**/*.test.ts"]
}
7 changes: 6 additions & 1 deletion JS/edgechains/document-loader/dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
Object.defineProperty(exports, "__esModule", { value: true });
exports.PdfLoader = void 0;
var pdfLoader_js_1 = require("./lib/pdf-loader/pdfLoader.js");
Object.defineProperty(exports, "PdfLoader", { enumerable: true, get: function () { return pdfLoader_js_1.PdfLoader; } });
Object.defineProperty(exports, "PdfLoader", {
enumerable: true,
get: function () {
return pdfLoader_js_1.PdfLoader;
},
});
2 changes: 1 addition & 1 deletion JS/edgechains/document-loader/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"moduleResolution": "NodeNext",
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"rootDir": "./src"
},
"exclude": ["node_modules", "dist", "./**/*.test.ts"]
}
2 changes: 1 addition & 1 deletion JS/edgechains/examples/Test01/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@
"typeorm": "^0.3.17",
"typescript": "^5.0.2"
}
}
}
4 changes: 2 additions & 2 deletions JS/edgechains/lib/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-env"]
}
"presets": ["@babel/preset-env"]
}
15 changes: 8 additions & 7 deletions JS/edgechains/lib/create-edgechains/__common/htmljs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export const rootLayout = (layoutToApply) => {
export const layout = (layoutToApply) => {
return async (c, next) => {
await next();
if ((c.req.header("HX-Request") === "true" &&
(c.req.header("HX-Boosted") === "true" || !c.req.header("HX-Target"))) ||
c.req.header("HX-Request") !== "true") {
if (
(c.req.header("HX-Request") === "true" &&
(c.req.header("HX-Boosted") === "true" || !c.req.header("HX-Target"))) ||
c.req.header("HX-Request") !== "true"
) {
// Req is regular req or boosted link, so we apply layouts
const curBody = await c.res.text();
c.res = undefined; // To overwrite res, set it to undefined before setting new value https://github.com/honojs/hono/pull/970 released in https://github.com/honojs/hono/releases/tag/v3.1.0
Expand All @@ -36,7 +38,7 @@ export const layout = (layoutToApply) => {
};
export const Link = ({ to, "hx-target": hxTarget, class: className, children }) => {
if (hxTarget) {
return html `<a
return html`<a
href="${to}"
class="${className}"
hx-get="${to}"
Expand All @@ -45,8 +47,7 @@ export const Link = ({ to, "hx-target": hxTarget, class: className, children })
hx-swap="morph"
>${children}</a
>`;
}
else {
return html `<a href="${to}" class="${className}" hx-boost="true">${children}</a>`;
} else {
return html`<a href="${to}" class="${className}" hx-boost="true">${children}</a>`;
}
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { html } from "hono/html";
const ExampleLayout = (props) => html `
const ExampleLayout = (props) => html`
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ HydeSearchRouter.get("/search", async (c) => {
},
orderRRF: query.orderRRF,
};
const answer = await hydeSearchAdaEmbedding(arkRequest, process.env.OPENAI_API_KEY, process.env.OPENAI_ORG_ID);
const answer = await hydeSearchAdaEmbedding(
arkRequest,
process.env.OPENAI_API_KEY,
process.env.OPENAI_ORG_ID
);
const final_answer = answer.finalAnswer;
const responses = answer.wordEmbeddings;
const data = { responses, final_answer };
Expand All @@ -32,26 +36,36 @@ HydeSearchRouter.get("/search", async (c) => {
<div class="card-body">${data.final_answer}</div>
</div>
<ul class="list-unstyled mb-0">
${data.responses.map((item) => `
${data.responses.map(
(item) => `
<li>
<div class="card">
<div class="card-body">
${item.rawText != null
? `<div class="card card-body">${item.rawText}</div>`
: `<div class="card card-body">${item.metadata}</div>`}
${item.filename != null
? `<div class="card card-body" style="color: blue;">${item.filename}</div>`
: ""}
${item.titleMetadata != null
? `<div class="card card-body" style="color: blue;">${item.titleMetadata}</div>`
: ""}
${item.documentDate != null
? `<div class="card card-body" style="color: blue;">${item.documentDate}</div>`
: ""}
${
item.rawText != null
? `<div class="card card-body">${item.rawText}</div>`
: `<div class="card card-body">${item.metadata}</div>`
}
${
item.filename != null
? `<div class="card card-body" style="color: blue;">${item.filename}</div>`
: ""
}
${
item.titleMetadata != null
? `<div class="card card-body" style="color: blue;">${item.titleMetadata}</div>`
: ""
}
${
item.documentDate != null
? `<div class="card card-body" style="color: blue;">${item.documentDate}</div>`
: ""
}
</div>
</div>
</li>
`)}
`
)}
</ul>
</html>
`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { ArkRequest } from "@arakoodev/edgechains.js";
declare function hydeSearchAdaEmbedding(arkRequest: ArkRequest, apiKey: string, orgId: string): Promise<{
declare function hydeSearchAdaEmbedding(
arkRequest: ArkRequest,
apiKey: string,
orgId: string
): Promise<{
wordEmbeddings: any;
finalAnswer: any;
}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ var PostgresDistanceMetric;
})(PostgresDistanceMetric || (PostgresDistanceMetric = {}));
async function hydeSearchAdaEmbedding(arkRequest, apiKey, orgId) {
try {
const gpt3endpoint = new OpenAiEndpoint("https://api.openai.com/v1/chat/completions", apiKey, orgId, "gpt-3.5-turbo", "user", parseInt("0.7"));
const gpt3endpoint = new OpenAiEndpoint(
"https://api.openai.com/v1/chat/completions",
apiKey,
orgId,
"gpt-3.5-turbo",
"user",
parseInt("0.7")
);
// Get required params from API...
const table = "ada_hyde_prod";
const namespace = "360_docs";
Expand All @@ -37,17 +44,30 @@ async function hydeSearchAdaEmbedding(arkRequest, apiKey, orgId) {
// Chain 1 ==> Get Gpt3Response & split
const gpt3Responses = gptResponse.split("\n");
// Chain 2 ==> Get Embeddings from OpenAI using Each Response
const embeddingsListChain = Promise.all(gpt3Responses.map(async (resp) => {
const embedding = await gpt3endpoint.embeddings(resp);
return embedding;
}));
const embeddingsListChain = Promise.all(
gpt3Responses.map(async (resp) => {
const embedding = await gpt3endpoint.embeddings(resp);
return embedding;
})
);
// Chain 5 ==> Query via EmbeddingChain
const dbClient = new PostgresClient(await embeddingsListChain, PostgresDistanceMetric.IP, topK, 20, table, namespace, arkRequest, 15);
const dbClient = new PostgresClient(
await embeddingsListChain,
PostgresDistanceMetric.IP,
topK,
20,
table,
namespace,
arkRequest,
15
);
const queryResult = await dbClient.dbQuery();
// Chain 6 ==> Create Prompt using Embeddings
const retrievedDocs = [];
for (const embeddings of queryResult) {
retrievedDocs.push(`${embeddings.raw_text}\n score:${embeddings.score}\n filename:${embeddings.filename}\n`);
retrievedDocs.push(
`${embeddings.raw_text}\n score:${embeddings.score}\n filename:${embeddings.filename}\n`
);
}
if (retrievedDocs.join("").length > 4096) {
retrievedDocs.length = 4096;
Expand Down Expand Up @@ -79,8 +99,7 @@ async function hydeSearchAdaEmbedding(arkRequest, apiKey, orgId) {
finalAnswer: finalAnswer,
};
return response;
}
catch (error) {
} catch (error) {
// Handle errors here
console.error(error);
throw error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ describe("Hyde Search", () => {
},
orderRRF: "default",
};
expect((await hydeSearchAdaEmbedding(arkRequest, process.env.OPENAI_API_KEY, process.env.OPENAI_ORG_ID)).finalAnswer).toContain("Java");
expect(
(
await hydeSearchAdaEmbedding(
arkRequest,
process.env.OPENAI_API_KEY,
process.env.OPENAI_ORG_ID
)
).finalAnswer
).toContain("Java");
}, 30000);
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import { OpenAiEndpoint } from "@arakoodev/edgechains.js";
const jsonnet = new Jsonnet();
const promptPath = path.join(process.cwd(), "./src/testGeneration/prompts.jsonnet");
const testGeneratorPath = path.join(process.cwd(), "./src/testGeneration/testGenerator.jsonnet");
const gpt3endpoint = new OpenAiEndpoint("https://api.openai.com/v1/chat/completions", "", "", "gpt-3.5-turbo", "user", 0.7);
const classText = "public class ChatMessage {\n" +
const gpt3endpoint = new OpenAiEndpoint(
"https://api.openai.com/v1/chat/completions",
"",
"",
"gpt-3.5-turbo",
"user",
0.7
);
const classText =
"public class ChatMessage {\n" +
" String role;\n" +
" String content;\n\n" +
" public ChatMessage(String role, String content) {\n" +
Expand Down Expand Up @@ -42,8 +50,7 @@ export async function getContent() {
finalResponse += await gpt3endpoint.gptFnTestGenerator(responce);
console.log("Final Response.......\n\n");
return finalResponse;
}
catch (error) {
} catch (error) {
console.log(error);
}
}
Loading

0 comments on commit e7b2d9d

Please sign in to comment.