Skip to content

Commit

Permalink
Google Java Format
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed Jul 25, 2023
1 parent 2a044e3 commit 8b581b0
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 88 deletions.
14 changes: 0 additions & 14 deletions Examples/doc2vec/Doc2VecExample.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,19 @@
package com.edgechain;

import static com.edgechain.lib.constants.EndpointConstants.OPENAI_CHAT_COMPLETION_API;
import static com.edgechain.lib.constants.EndpointConstants.OPENAI_EMBEDDINGS_API;

import com.edgechain.lib.chains.RedisRetrieval;
import com.edgechain.lib.chains.Retrieval;
import com.edgechain.lib.chunk.enums.LangType;
import com.edgechain.lib.configuration.domain.CorsEnableOrigins;
import com.edgechain.lib.configuration.domain.ExcludeMappingFilter;
import com.edgechain.lib.configuration.domain.RedisEnv;
import com.edgechain.lib.context.domain.HistoryContext;
import com.edgechain.lib.embeddings.WordEmbeddings;
import com.edgechain.lib.embeddings.request.Doc2VecRequest;
import com.edgechain.lib.endpoint.impl.Doc2VecEndpoint;
import com.edgechain.lib.endpoint.impl.OpenAiEndpoint;
import com.edgechain.lib.endpoint.impl.RedisEndpoint;
import com.edgechain.lib.endpoint.impl.RedisHistoryContextEndpoint;
import com.edgechain.lib.index.enums.RedisDistanceMetric;
import com.edgechain.lib.jsonnet.JsonnetArgs;
import com.edgechain.lib.jsonnet.JsonnetLoader;
import com.edgechain.lib.jsonnet.enums.DataType;
import com.edgechain.lib.jsonnet.impl.FileJsonnetLoader;
import com.edgechain.lib.openai.response.ChatCompletionResponse;
import com.edgechain.lib.reader.impl.PdfReader;
import com.edgechain.lib.request.ArkRequest;
import com.edgechain.lib.response.ArkResponse;
import com.edgechain.lib.rxjava.retry.impl.ExponentialDelay;
import com.edgechain.lib.rxjava.retry.impl.FixedDelay;
import com.edgechain.lib.rxjava.transformer.observable.EdgeChain;

import java.io.FileInputStream;
Expand All @@ -38,7 +25,6 @@

import org.deeplearning4j.models.embeddings.loader.WordVectorSerializer;
import org.deeplearning4j.models.paragraphvectors.ParagraphVectors;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
Expand Down
4 changes: 0 additions & 4 deletions Examples/postgresql/PostgreSQLExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
import static com.edgechain.lib.constants.EndpointConstants.OPENAI_EMBEDDINGS_API;

import com.edgechain.lib.chains.PostgresRetrieval;
import com.edgechain.lib.chains.RedisRetrieval;
import com.edgechain.lib.chains.Retrieval;
import com.edgechain.lib.chunk.enums.LangType;
import com.edgechain.lib.configuration.domain.CorsEnableOrigins;
import com.edgechain.lib.configuration.domain.ExcludeMappingFilter;
import com.edgechain.lib.configuration.domain.RedisEnv;
import com.edgechain.lib.configuration.domain.SupabaseEnv;
import com.edgechain.lib.context.domain.HistoryContext;
import com.edgechain.lib.embeddings.WordEmbeddings;
import com.edgechain.lib.endpoint.impl.*;
import com.edgechain.lib.index.enums.PostgresDistanceMetric;
import com.edgechain.lib.index.enums.RedisDistanceMetric;
import com.edgechain.lib.jsonnet.JsonnetArgs;
import com.edgechain.lib.jsonnet.JsonnetLoader;
import com.edgechain.lib.jsonnet.enums.DataType;
Expand Down
1 change: 0 additions & 1 deletion Examples/redis/RedisExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.edgechain.lib.endpoint.impl.OpenAiEndpoint;
import com.edgechain.lib.endpoint.impl.RedisEndpoint;
import com.edgechain.lib.endpoint.impl.RedisHistoryContextEndpoint;
import com.edgechain.lib.endpoint.impl.WikiEndpoint;
import com.edgechain.lib.index.enums.RedisDistanceMetric;
import com.edgechain.lib.jsonnet.JsonnetArgs;
import com.edgechain.lib.jsonnet.JsonnetLoader;
Expand Down
61 changes: 29 additions & 32 deletions Examples/wiki/WikiExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ public static void main(String[] args) {
SpringApplication.run(WikiExample.class, args);
}


// Adding Cors ==> You can configure multiple cors w.r.t your urls.;
@Bean
@Primary
public CorsEnableOrigins corsEnableOrigins() {
CorsEnableOrigins origins = new CorsEnableOrigins();
origins.setOrigins(
Arrays.asList("http://localhost:4200","http://localhost:4201"));
origins.setOrigins(Arrays.asList("http://localhost:4200", "http://localhost:4201"));
return origins;
}

Expand All @@ -72,18 +70,18 @@ public class WikiController {
* @return ArkResponse
*/
@GetMapping(
value = "/wiki-summary",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_EVENT_STREAM_VALUE})
value = "/wiki-summary",
produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_EVENT_STREAM_VALUE})
public ArkResponse wikiSummary(ArkRequest arkRequest) {

String query = arkRequest.getQueryParam("query");
boolean stream = arkRequest.getBooleanHeader("stream");

// Step 1: Create JsonnetLoader to Load JsonnetFile & Pass Args To Jsonnet
JsonnetLoader loader =
new FileJsonnetLoader("R:\\Github\\wiki.jsonnet")
.put("keepMaxTokens", new JsonnetArgs(DataType.BOOLEAN, "true"))
.put("maxTokens", new JsonnetArgs(DataType.INTEGER, "4096"));
new FileJsonnetLoader("R:\\Github\\wiki.jsonnet")
.put("keepMaxTokens", new JsonnetArgs(DataType.BOOLEAN, "true"))
.put("maxTokens", new JsonnetArgs(DataType.INTEGER, "4096"));

/* Step 2: Create WikiEndpoint to extract content from Wikipedia;
If RetryPolicy is not passed; then there won't be any backoff mechanism.... */
Expand All @@ -93,32 +91,31 @@ public ArkResponse wikiSummary(ArkRequest arkRequest) {

/* Step 3: Create OpenAiEndpoint to communicate with OpenAiServices; */
OpenAiEndpoint openAiEndpoint =
new OpenAiEndpoint(
OPENAI_CHAT_COMPLETION_API,
OPENAI_AUTH_KEY,
"gpt-3.5-turbo",
"user",
0.7,
stream,
new ExponentialDelay(3, 5, 2, TimeUnit.SECONDS));
new OpenAiEndpoint(
OPENAI_CHAT_COMPLETION_API,
OPENAI_AUTH_KEY,
"gpt-3.5-turbo",
"user",
0.7,
stream,
new ExponentialDelay(3, 5, 2, TimeUnit.SECONDS));

return new EdgeChain<>(wikiEndpoint.getPageContent(query))
.transform(
wiki -> {
loader
.put("keepContext", new JsonnetArgs(DataType.BOOLEAN, "true"))
.put(
"context",
new JsonnetArgs(
DataType.STRING,
wiki.getText())) // Step 4: Concatenate ${Base Prompt} + ${Wiki Output}
.loadOrReload(); // Step 5: Reloading Jsonnet File

return loader.get("prompt");
})
.transform(openAiEndpoint::getChatCompletion)
.getArkResponse();
.transform(
wiki -> {
loader
.put("keepContext", new JsonnetArgs(DataType.BOOLEAN, "true"))
.put(
"context",
new JsonnetArgs(
DataType.STRING,
wiki.getText())) // Step 4: Concatenate ${Base Prompt} + ${Wiki Output}
.loadOrReload(); // Step 5: Reloading Jsonnet File

return loader.get("prompt");
})
.transform(openAiEndpoint::getChatCompletion)
.getArkResponse();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ public ArkRequest() {

String contentType = request.getContentType();

if(Objects.isNull(contentType)) {
logger.error("ArkRequest can only accept Content-Type:application/json ||"
if (Objects.isNull(contentType)) {
logger.error(
"ArkRequest can only accept Content-Type:application/json ||"
+ " Content-Type:multipart/form-data - You haven't specified Content-Type");

throw new InvalidArkRequest(
"ArkRequest can only accept Content-Type:application/json ||"
+ " Content-Type:multipart/form-data - You haven't specified Content-Type");
}

else if (!contentType.contains("application/json") && !contentType.contains("multipart/form-data")) {
logger.error("ArkRequest can only accept Content-Type:application/json ||"
"ArkRequest can only accept Content-Type:application/json ||"
+ " Content-Type:multipart/form-data - You haven't specified Content-Type");
} else if (!contentType.contains("application/json")
&& !contentType.contains("multipart/form-data")) {
logger.error(
"ArkRequest can only accept Content-Type:application/json ||"
+ " Content-Type:multipart/form-data");

throw new InvalidArkRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.edgechain.doc2vec;


import com.edgechain.lib.endpoint.impl.Doc2VecEndpoint;
import io.reactivex.rxjava3.observers.TestObserver;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -31,7 +30,8 @@ public void setup() {

@Test
@DisplayName("Test Doc2Vec Model Training")
public void doc2VecEndpoint_TrainModel_AssertNoErrors(TestInfo testInfo) throws InterruptedException {
public void doc2VecEndpoint_TrainModel_AssertNoErrors(TestInfo testInfo)
throws InterruptedException {

logger.info("======== " + testInfo.getDisplayName() + " ========");

Expand All @@ -57,5 +57,4 @@ public void doc2VecEndpoint_TrainModel_AssertNoErrors(TestInfo testInfo) throws

test.assertNoErrors();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;


import com.edgechain.lib.jsonnet.JsonnetLoader;
import com.edgechain.lib.jsonnet.impl.FileJsonnetLoader;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,19 @@

import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import com.edgechain.lib.openai.plugin.parser.PluginParser;

@SpringBootTest
public class PluginParserTest {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Test
@DisplayName("Test Plugin Parser")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import com.edgechain.lib.openai.parser.Scratchpad;

Expand All @@ -19,7 +17,6 @@ public class ScratchpadTest {

private final Logger logger = LoggerFactory.getLogger(this.getClass());


@Test
@DisplayName("Test Get Action Content")
public void Scratchpad_GetActionContent_ReturnsExpectedValue(TestInfo testInfo) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import com.edgechain.lib.openai.parser.StringParser;

@SpringBootTest
public class StringParserTest {


private final Logger logger = LoggerFactory.getLogger(this.getClass());


@Test
@DisplayName("Test string parser Get Thought Content")
public void StringParser_GetThoughtContent_ReturnsExpectedValue() {
Expand Down Expand Up @@ -58,7 +54,7 @@ public void StringParser_GetActionContent_ReturnsExpectedValue() {

@Test
@DisplayName("Test string parser Get Observation Content")
public void StringParser_GetObservationContent_ReturnsExpectedValue() {
public void StringParser_GetObservationContent_ReturnsExpectedValue() {

logger.info("======== " + "Test Get Observation Content" + " ========");

Expand All @@ -76,7 +72,7 @@ public void StringParser_GetObservationContent_ReturnsExpectedValue() {

@Test
@DisplayName("Test string parser Get Final Answer")
public void StringParser_GetFinalAnswer_ReturnsExpectedValue() {
public void StringParser_GetFinalAnswer_ReturnsExpectedValue() {

logger.info("======== " + "Test Get Final Answer" + " ========");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.util.Optional;
import java.util.UUID;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
Expand All @@ -22,7 +21,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import com.edgechain.lib.supabase.entities.User;
import com.edgechain.lib.supabase.exceptions.SupabaseAuthException;
Expand All @@ -49,7 +47,6 @@ public class AuthControllerTest {

@Mock private SupabaseAuthService supabaseAuthService;


@Test
@DisplayName("Test Signup with valid credential")
public void authController_SignupWithValidCredential_ReturnSupabaseUser(TestInfo testInfo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.edgechain.wiki;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import io.reactivex.rxjava3.observers.TestObserver;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -13,15 +11,12 @@
import org.junit.jupiter.api.TestMethodOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;

import com.edgechain.lib.endpoint.impl.WikiEndpoint;
import com.edgechain.lib.wiki.response.WikiResponse;
import com.edgechain.service.controllers.wiki.WikiController;

import io.reactivex.rxjava3.core.Single;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Expand All @@ -36,11 +31,11 @@ public void setup() {
System.setProperty("server.port", "" + randomServerPort);
}


@Test
@DisplayName("Test WikiContent Method Returns WikiResponse")
@Order(1)
public void wikiControllerTest_TestWikiContentMethod_ReturnsWikiResponse(TestInfo testInfo) throws InterruptedException {
public void wikiControllerTest_TestWikiContentMethod_ReturnsWikiResponse(TestInfo testInfo)
throws InterruptedException {

logger.info("======== " + testInfo.getDisplayName() + " ========");

Expand All @@ -54,7 +49,5 @@ public void wikiControllerTest_TestWikiContentMethod_ReturnsWikiResponse(TestInf
logger.info(String.valueOf(test.values().get(0)));

test.assertNoErrors();

}

}

0 comments on commit 8b581b0

Please sign in to comment.