diff --git a/JS/edgechains/examples/.env b/JS/edgechains/examples/.env index eb659b3a8..4fc13b9f1 100644 --- a/JS/edgechains/examples/.env +++ b/JS/edgechains/examples/.env @@ -5,10 +5,10 @@ SERVER_ADDRESS=127.0.0.1 SERVER_PORT=8080 ### DATABASE -DB_HOST=db.bpuebaflhzmcvqsnzvuy.supabase.co +DB_HOST= DB_PORT=5432 DB_USERNAME=postgres -DB_PASSWORD=TCCzWekTKUEzYYi9 +DB_PASSWORD= DB_DATABASE=postgres ### AUTH0 diff --git a/JS/edgechains/examples/src/lib/PostgresClient.ts b/JS/edgechains/examples/src/lib/PostgresClient.ts index 40309f3f8..45ed7c738 100644 --- a/JS/edgechains/examples/src/lib/PostgresClient.ts +++ b/JS/edgechains/examples/src/lib/PostgresClient.ts @@ -1,4 +1,4 @@ -import { createConnection, getManager } from 'typeorm'; +import { createConnection } from 'typeorm'; export class PostgresClient { wordEmbeddings: number[][]; @@ -31,8 +31,8 @@ export class PostgresClient { } async dbQuery() { - await createConnection(); - const entityManager = getManager(); + const con = await createConnection(); + const entityManager = con.createEntityManager(); try { const query1 = `SET LOCAL ivfflat.probes = ${this.probes};`; await entityManager.query(query1); @@ -107,6 +107,7 @@ export class PostgresClient { query += ` ORDER BY rrf_score DESC LIMIT ${this.topK};`; } const results = await entityManager.query(query); + await con.destroy(); return results; } catch (error) { // Handle errors here diff --git a/JS/edgechains/examples/src/testGeneration/TestGenerator.ts b/JS/edgechains/examples/src/testGeneration/TestGenerator.ts new file mode 100644 index 000000000..81dbcaf2c --- /dev/null +++ b/JS/edgechains/examples/src/testGeneration/TestGenerator.ts @@ -0,0 +1,40 @@ +import { Jsonnet } from "@hanazuki/node-jsonnet"; +import * as path from 'path'; + +const jsonnet = new Jsonnet(); +const promptPath = path.join(process.cwd(),'./src/testGeneration/prompts.jsonnet') + +const classText = "public class ChatMessage {\n" + + " String role;\n" + + " String content;\n\n" + + " public ChatMessage(String role, String content) {\n" + + " this.role = role;\n" + + " this.content = content;\n" + + " }\n\n" + + " public ChatMessage() {}\n\n" + + " public String getRole() {\n" + + " return role;\n" + + " }\n\n" + + " public String getContent() {\n" + + " return content;\n" + + " }\n\n" + + " public void setContent(String content) {\n" + + " this.content = content;\n" + + " }\n\n" + + " @Override\n" + + " public String toString() {\n" + + " return \"ChatMessage{\" + \"role='\" + role + \"', content='\" + content + \"'}\";\n" + + " }\n" + + "}"; +export async function getContent(){ + try{ + + var prompt = await jsonnet.extString('testPackage','JUnit') + .extString('testClass',classText) + .evaluateFile(promptPath); + + console.log(JSON.parse(prompt)); + }catch(error){ + console.log(error); + } +} \ No newline at end of file diff --git a/JS/edgechains/examples/src/testGeneration/prompts.jsonnet b/JS/edgechains/examples/src/testGeneration/prompts.jsonnet new file mode 100644 index 000000000..53a175dfe --- /dev/null +++ b/JS/edgechains/examples/src/testGeneration/prompts.jsonnet @@ -0,0 +1,20 @@ +local prompt = ||| + # How to write great unit tests with {test_package} + In this advanced tutorial for experts, we'll use Java and {test_package} to write a suite of unit tests to verify the behavior of the following function. + ```java + {test_class} + ``` + Before writing any unit tests, let's review what each element of the function is doing exactly and what the author's intentions may have been. + - First, + |||; + +local test_package = std.extVar("testPackage"); +local test_class = std.extVar("testClass"); + + + +{ + "testpackage" : test_package, + "testclass" : test_class, + "prompt" : prompt +} \ No newline at end of file