Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supabase connection error on multiple requests #264

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions JS/edgechains/examples/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions JS/edgechains/examples/src/lib/PostgresClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createConnection, getManager } from 'typeorm';
import { createConnection } from 'typeorm';

export class PostgresClient {
wordEmbeddings: number[][];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions JS/edgechains/examples/src/testGeneration/TestGenerator.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
20 changes: 20 additions & 0 deletions JS/edgechains/examples/src/testGeneration/prompts.jsonnet
Original file line number Diff line number Diff line change
@@ -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
}
Loading