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 Sep 30, 2023
1 parent e8162ff commit 4cdea9c
Show file tree
Hide file tree
Showing 41 changed files with 1,684 additions and 1,681 deletions.
23 changes: 12 additions & 11 deletions Examples/airtable/AirtableExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
import java.util.Properties;

/**
* For the purpose, of this example, create a simple table using AirTable i.e, "Speakers"
* Following are some basic fields: "speaker_name", "designation", "organization", "biography", "speaker_photo", "rating
* To get, your BASE_ID of specific database; use the following API https://api.airtable.com/v0/meta/bases
* --header 'Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN'
* You can create, complex tables using Airtable; also define relationships b/w tables via lookups.
* For the purpose, of this example, create a simple table using AirTable i.e, "Speakers" Following
* are some basic fields: "speaker_name", "designation", "organization", "biography",
* "speaker_photo", "rating To get, your BASE_ID of specific database; use the following API
* https://api.airtable.com/v0/meta/bases --header 'Authorization: Bearer
* YOUR_PERSONAL_ACCESS_TOKEN' You can create, complex tables using Airtable; also define
* relationships b/w tables via lookups.
*/
@SpringBootApplication
public class AirtableExample {
Expand Down Expand Up @@ -123,11 +124,11 @@ public ArkResponse update(ArkRequest arkRequest) {
return new EdgeChain<>(airtableEndpoint.update("Speakers", record)).getArkResponse();
}

@DeleteMapping("/delete")
public ArkResponse delete(ArkRequest arkRequest) {
JSONObject body = arkRequest.getBody();
String id = body.getString("id");
return new EdgeChain<>(airtableEndpoint.delete("Speakers", id)).getArkResponse();
}
@DeleteMapping("/delete")
public ArkResponse delete(ArkRequest arkRequest) {
JSONObject body = arkRequest.getBody();
String id = body.getString("id");
return new EdgeChain<>(airtableEndpoint.delete("Speakers", id)).getArkResponse();
}
}
}
8 changes: 4 additions & 4 deletions Examples/pinecone/PineconeExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void main(String[] args) {

// Redis Configuration
properties.setProperty("redis.url", "");
properties.setProperty("redis.port","");
properties.setProperty("redis.port", "");
properties.setProperty("redis.username", "default");
properties.setProperty("redis.password", "");
properties.setProperty("redis.ttl", "3600");
Expand All @@ -72,12 +72,11 @@ public static void main(String[] args) {
properties.setProperty("postgres.db.username", "postgres");
properties.setProperty("postgres.db.password", "");


new SpringApplicationBuilder(PineconeExample.class).properties(properties).run(args);

gpt3Endpoint =
new OpenAiChatEndpoint(
OPENAI_CHAT_COMPLETION_API,
OPENAI_CHAT_COMPLETION_API,
OPENAI_AUTH_KEY,
OPENAI_ORG_ID,
"gpt-3.5-turbo",
Expand All @@ -96,7 +95,8 @@ public static void main(String[] args) {
true,
new ExponentialDelay(3, 5, 2, TimeUnit.SECONDS));

OpenAiEmbeddingEndpoint ada002 = new OpenAiEmbeddingEndpoint(
OpenAiEmbeddingEndpoint ada002 =
new OpenAiEmbeddingEndpoint(
OPENAI_EMBEDDINGS_API,
OPENAI_AUTH_KEY,
OPENAI_ORG_ID,
Expand Down
28 changes: 12 additions & 16 deletions Examples/postgresql/PostgreSQLExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public static void main(String[] args) {
true,
new ExponentialDelay(3, 5, 2, TimeUnit.SECONDS));

OpenAiEmbeddingEndpoint adaEmbedding = new OpenAiEmbeddingEndpoint(
OpenAiEmbeddingEndpoint adaEmbedding =
new OpenAiEmbeddingEndpoint(
OPENAI_EMBEDDINGS_API,
OPENAI_AUTH_KEY,
OPENAI_ORG_ID,
Expand All @@ -100,7 +101,10 @@ public static void main(String[] args) {
// Defining tablename and namespace...
postgresEndpoint =
new PostgresEndpoint(
"pg_vectors", "machine-learning", adaEmbedding, new ExponentialDelay(5, 5, 2, TimeUnit.SECONDS));
"pg_vectors",
"machine-learning",
adaEmbedding,
new ExponentialDelay(5, 5, 2, TimeUnit.SECONDS));

contextEndpoint = new PostgreSQLHistoryContextEndpoint(new FixedDelay(2, 3, TimeUnit.SECONDS));
}
Expand Down Expand Up @@ -159,12 +163,7 @@ public void upsert(ArkRequest arkRequest) throws IOException {

PostgresRetrieval retrieval =
new PostgresRetrieval(
arr,
postgresEndpoint,
1536,
filename,
PostgresLanguage.ENGLISH,
arkRequest);
arr, postgresEndpoint, 1536, filename, PostgresLanguage.ENGLISH, arkRequest);

// retrieval.setBatchSize(50); // Modifying batchSize....(Default is 30)

Expand All @@ -186,12 +185,7 @@ public ArkResponse query(ArkRequest arkRequest) {
EdgeChain<List<PostgresWordEmbeddings>> queryChain =
new EdgeChain<>(
postgresEndpoint.query(
List.of(query),
PostgresDistanceMetric.COSINE,
topK,
topK,
10,
arkRequest));
List.of(query), PostgresDistanceMetric.COSINE, topK, topK, 10, arkRequest));

// Chain 3 ===> Our queryFn passes takes list and passes each response with base prompt to
// OpenAI
Expand Down Expand Up @@ -227,15 +221,17 @@ public ArkResponse chat(ArkRequest arkRequest) {

EdgeChain<List<PostgresWordEmbeddings>> postgresChain =
new EdgeChain<>(
postgresEndpoint.query(List.of(query), PostgresDistanceMetric.COSINE, topK, topK, arkRequest));
postgresEndpoint.query(
List.of(query), PostgresDistanceMetric.COSINE, topK, topK, arkRequest));

// Chain 3 ===> Transform String of Queries into List<Queries>
// let's say topK=5; then we concatenate List into a string using String.join method
EdgeChain<String> queryChain =
new EdgeChain<>(postgresChain)
.transform(
postgresResponse -> {
List<PostgresWordEmbeddings> postgresWordEmbeddingsList = postgresResponse.get();
List<PostgresWordEmbeddings> postgresWordEmbeddingsList =
postgresResponse.get();
List<String> queryList = new ArrayList<>();
postgresWordEmbeddingsList.forEach(q -> queryList.add(q.getRawText()));
return String.join("\n", queryList);
Expand Down
1 change: 0 additions & 1 deletion Examples/react-chain/ReactChainApplication.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.edgechain;


import com.edgechain.lib.endpoint.impl.llm.OpenAiChatEndpoint;
import com.edgechain.lib.jsonnet.JsonnetArgs;
import com.edgechain.lib.jsonnet.JsonnetLoader;
Expand Down
33 changes: 17 additions & 16 deletions Examples/redis/RedisExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ public static void main(String[] args) {

// If you want to use PostgreSQL only; then just provide dbHost, dbUsername & dbPassword.
// If you haven't specified PostgreSQL, then logs won't be stored.
properties.setProperty(
"postgres.db.host", "");
properties.setProperty("postgres.db.host", "");
properties.setProperty("postgres.db.username", "postgres");
properties.setProperty("postgres.db.password", "");


// Redis Configuration
properties.setProperty("redis.url", "");
properties.setProperty("redis.port","12285");
properties.setProperty("redis.port", "12285");
properties.setProperty("redis.username", "default");
properties.setProperty("redis.password", "");
properties.setProperty("redis.ttl", "3600");
Expand Down Expand Up @@ -98,16 +96,19 @@ public static void main(String[] args) {
new ExponentialDelay(3, 5, 2, TimeUnit.SECONDS));

OpenAiEmbeddingEndpoint ada002Endpoint =
new OpenAiEmbeddingEndpoint(
OPENAI_EMBEDDINGS_API,
OPENAI_AUTH_KEY,
OPENAI_ORG_ID,
"text-embedding-ada-002",
new ExponentialDelay(3, 3, 2, TimeUnit.SECONDS));
new OpenAiEmbeddingEndpoint(
OPENAI_EMBEDDINGS_API,
OPENAI_AUTH_KEY,
OPENAI_ORG_ID,
"text-embedding-ada-002",
new ExponentialDelay(3, 3, 2, TimeUnit.SECONDS));

redisEndpoint =
new RedisEndpoint(
"vector_index", "machine-learning", ada002Endpoint, new ExponentialDelay(3, 3, 2, TimeUnit.SECONDS));
"vector_index",
"machine-learning",
ada002Endpoint,
new ExponentialDelay(3, 3, 2, TimeUnit.SECONDS));

contextEndpoint =
new RedisHistoryContextEndpoint(new ExponentialDelay(2, 2, 2, TimeUnit.SECONDS));
Expand Down Expand Up @@ -166,8 +167,7 @@ public void upsert(ArkRequest arkRequest) throws IOException {
* asynchronously...;
*/
RedisRetrieval retrieval =
new RedisRetrieval(
arr, redisEndpoint, 1536, RedisDistanceMetric.COSINE, arkRequest);
new RedisRetrieval(arr, redisEndpoint, 1536, RedisDistanceMetric.COSINE, arkRequest);
retrieval.upsert();
}

Expand All @@ -184,7 +184,8 @@ public ArkResponse similaritySearch(ArkRequest arkRequest) {
int topK = arkRequest.getIntQueryParam("topK");

// Chain 1 ==> Pass those embeddings to Redis & Return Score/values (Similarity search)
EdgeChain<List<WordEmbeddings>> redisQueries = new EdgeChain<>(redisEndpoint.query(query, topK, arkRequest));
EdgeChain<List<WordEmbeddings>> redisQueries =
new EdgeChain<>(redisEndpoint.query(query, topK, arkRequest));

return redisQueries.getArkResponse();
}
Expand All @@ -196,7 +197,8 @@ public ArkResponse queryRedis(ArkRequest arkRequest) {
int topK = arkRequest.getIntQueryParam("topK");

// Chain 1 ==> Query Embeddings from Redis
EdgeChain<List<WordEmbeddings>> queryChain = new EdgeChain<>(redisEndpoint.query(query, topK, arkRequest));
EdgeChain<List<WordEmbeddings>> queryChain =
new EdgeChain<>(redisEndpoint.query(query, topK, arkRequest));

// Chain 3 ===> Our queryFn passes takes list and passes each response with base prompt to
// OpenAI
Expand Down Expand Up @@ -227,7 +229,6 @@ public ArkResponse chatWithRedis(ArkRequest arkRequest) {
// Extract topK value from JsonnetLoader;
int topK = chatLoader.getInt("topK");


// Chain 1==> Query Embeddings from Redis & Then concatenate it (preparing for prompt)

EdgeChain<List<WordEmbeddings>> redisChain =
Expand Down
26 changes: 13 additions & 13 deletions Examples/supabase-miniLM/SupabaseMiniLMExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public class SupabaseMiniLMExample {
private static PostgreSQLHistoryContextEndpoint contextEndpoint;

private JsonnetLoader queryLoader =
new FileJsonnetLoader("./supabase-miniLM/postgres-query.jsonnet");
new FileJsonnetLoader("./supabase-miniLM/postgres-query.jsonnet");
private JsonnetLoader chatLoader =
new FileJsonnetLoader("./supabase-miniLM/postgres-chat.jsonnet");
new FileJsonnetLoader("./supabase-miniLM/postgres-chat.jsonnet");

public static void main(String[] args) {

Expand All @@ -77,7 +77,6 @@ public static void main(String[] args) {
properties.setProperty("postgres.db.username", "postgres");
properties.setProperty("postgres.db.password", "");


new SpringApplicationBuilder(SupabaseMiniLMExample.class).properties(properties).run(args);

gpt3Endpoint =
Expand Down Expand Up @@ -112,7 +111,10 @@ public static void main(String[] args) {
// vectors;
postgresEndpoint =
new PostgresEndpoint(
"minilm_vectors", "minilm-ns", miniLMEndpoint, new ExponentialDelay(2, 3, 2, TimeUnit.SECONDS));
"minilm_vectors",
"minilm-ns",
miniLMEndpoint,
new ExponentialDelay(2, 3, 2, TimeUnit.SECONDS));

contextEndpoint = new PostgreSQLHistoryContextEndpoint(new FixedDelay(2, 3, TimeUnit.SECONDS));
}
Expand Down Expand Up @@ -172,12 +174,7 @@ public void upsert(ArkRequest arkRequest) throws IOException {

PostgresRetrieval retrieval =
new PostgresRetrieval(
arr,
postgresEndpoint,
384,
filename,
PostgresLanguage.ENGLISH,
arkRequest);
arr, postgresEndpoint, 384, filename, PostgresLanguage.ENGLISH, arkRequest);

// retrieval.setBatchSize(50); // Modifying batchSize....

Expand All @@ -199,7 +196,8 @@ public ArkResponse queryPostgres(ArkRequest arkRequest) {
// Chain 2 ==> Query Embeddings from PostgreSQL
EdgeChain<List<PostgresWordEmbeddings>> queryChain =
new EdgeChain<>(
postgresEndpoint.query(List.of(query), PostgresDistanceMetric.L2, topK, topK,arkRequest));
postgresEndpoint.query(
List.of(query), PostgresDistanceMetric.L2, topK, topK, arkRequest));

// Chain 3 ===> Our queryFn passes takes list and passes each response with base prompt to
// OpenAI
Expand Down Expand Up @@ -237,14 +235,16 @@ public ArkResponse chatWithPostgres(ArkRequest arkRequest) {
// let's say topK=5; then we concatenate List into a string using String.join method
EdgeChain<List<PostgresWordEmbeddings>> postgresChain =
new EdgeChain<>(
postgresEndpoint.query(List.of(query), PostgresDistanceMetric.L2, topK, topK, arkRequest));
postgresEndpoint.query(
List.of(query), PostgresDistanceMetric.L2, topK, topK, arkRequest));

// Chain 3 ===> Transform String of Queries into List<Queries>
EdgeChain<String> queryChain =
new EdgeChain<>(postgresChain)
.transform(
postgresResponse -> {
List<PostgresWordEmbeddings> postgresWordEmbeddingsList = postgresResponse.get();
List<PostgresWordEmbeddings> postgresWordEmbeddingsList =
postgresResponse.get();
List<String> queryList = new ArrayList<>();
postgresWordEmbeddingsList.forEach(q -> queryList.add(q.getRawText()));
return String.join("\n", queryList);
Expand Down
Loading

0 comments on commit 4cdea9c

Please sign in to comment.