From 9c2cab949ab9281b8e0ab134aeb502a2885b2d0f Mon Sep 17 00:00:00 2001 From: Emad Hanif <132761026+EmadHanif@users.noreply.github.com> Date: Sun, 3 Sep 2023 01:55:24 +0500 Subject: [PATCH] ArkRequest ~ Fixing JsonParsing (#209) --- Examples/supabase-miniLM/SupabaseMiniLMExample.java | 13 +++++++++---- .../java/com/edgechain/lib/request/ArkRequest.java | 13 +++++++++++-- .../controllers/index/PostgresController.java | 3 --- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Examples/supabase-miniLM/SupabaseMiniLMExample.java b/Examples/supabase-miniLM/SupabaseMiniLMExample.java index 7346a057e..42e3b401c 100644 --- a/Examples/supabase-miniLM/SupabaseMiniLMExample.java +++ b/Examples/supabase-miniLM/SupabaseMiniLMExample.java @@ -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; @@ -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 ids = retrieval.upsert(); + + ids.forEach(System.out::println); + + System.out.println("Size: " + ids.size()); // Printing the UUIDs } @PostMapping(value = "/miniLM/query") diff --git a/FlySpring/edgechain-app/src/main/java/com/edgechain/lib/request/ArkRequest.java b/FlySpring/edgechain-app/src/main/java/com/edgechain/lib/request/ArkRequest.java index dd047758f..d61023fab 100644 --- a/FlySpring/edgechain-app/src/main/java/com/edgechain/lib/request/ArkRequest.java +++ b/FlySpring/edgechain-app/src/main/java/com/edgechain/lib/request/ArkRequest.java @@ -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; @@ -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() { diff --git a/FlySpring/edgechain-app/src/main/java/com/edgechain/service/controllers/index/PostgresController.java b/FlySpring/edgechain-app/src/main/java/com/edgechain/service/controllers/index/PostgresController.java index da0cbac88..5da0721e7 100644 --- a/FlySpring/edgechain-app/src/main/java/com/edgechain/service/controllers/index/PostgresController.java +++ b/FlySpring/edgechain-app/src/main/java/com/edgechain/service/controllers/index/PostgresController.java @@ -62,9 +62,6 @@ public Single insertIntoJoinTable( @PostMapping("/query") public Single> query( @RequestBody PostgresEndpoint postgresEndpoint) { - - System.out.println(postgresEndpoint); - return this.postgresClient.query(postgresEndpoint).toSingle(); }