Skip to content

Commit

Permalink
ArkRequest ~ Fixing JsonParsing (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmadHanif01 authored Sep 2, 2023
1 parent 2b5c778 commit 9c2cab9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
13 changes: 9 additions & 4 deletions Examples/supabase-miniLM/SupabaseMiniLMExample.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.edgechain;

import com.edgechain.lib.chains.PostgresRetrieval;
import com.edgechain.lib.chains.Retrieval;
import com.edgechain.lib.context.domain.HistoryContext;
import com.edgechain.lib.embeddings.WordEmbeddings;
import com.edgechain.lib.embeddings.miniLLM.enums.MiniLMModel;
Expand Down Expand Up @@ -160,10 +159,16 @@ public void upsert(ArkRequest arkRequest) throws IOException {

String[] arr = pdfReader.readByChunkSize(file, 512);

Retrieval retrieval =
new PostgresRetrieval(postgresEndpoint, filename, 384, miniLMEndpoint, arkRequest);
PostgresRetrieval retrieval = new PostgresRetrieval(arr, miniLMEndpoint, postgresEndpoint, 1536, filename, arkRequest);

IntStream.range(0, arr.length).parallel().forEach(i -> retrieval.upsert(arr[i]));
// retrieval.setBatchSize(100); // Modifying batchSize....

// Getting ids from upsertion... Internally, it automatically parallelizes the operation...
List<String> ids = retrieval.upsert();

ids.forEach(System.out::println);

System.out.println("Size: " + ids.size()); // Printing the UUIDs
}

@PostMapping(value = "/miniLM/query")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.io.BufferedReader;
import java.io.IOException;
import java.security.Principal;
import java.util.Collection;
Expand Down Expand Up @@ -99,11 +100,19 @@ public int getIntQueryParam(String key) {
}

public JSONObject getBody() {
try {
return new JSONObject(this.request.getReader().lines().collect(Collectors.joining()));

StringBuilder jsonContent = new StringBuilder();

try (BufferedReader reader = request.getReader()) {
String line;
while ((line = reader.readLine()) != null) {
jsonContent.append(line);
}
} catch (IOException e) {
throw new RuntimeException(e);
}

return new JSONObject(jsonContent.toString());
}

public Cookie[] getCookies() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public Single<StringResponse> insertIntoJoinTable(
@PostMapping("/query")
public Single<List<PostgresWordEmbeddings>> query(
@RequestBody PostgresEndpoint postgresEndpoint) {

System.out.println(postgresEndpoint);

return this.postgresClient.query(postgresEndpoint).toSingle();
}

Expand Down

0 comments on commit 9c2cab9

Please sign in to comment.