build most modules with jdk 8 (#295)

Since we target java 8, CI build was updated to run most modules using
java 8, then modules requiring java 11 separately with java 11
This commit is contained in:
LangChain4j 2023-11-18 15:07:11 +01:00 committed by GitHub
parent 61e6a4bef0
commit ff998ac82d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 48 deletions

View File

@ -7,14 +7,24 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Set up JDK
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: 'maven'
- name: Build with JDK 8 (excluding modules requiring JDK 11)
run: mvn --batch-mode install -DskipITs -pl !langchain4j-opensearch
- name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v3
with: with:
java-version: '11' java-version: '11'
distribution: 'adopt' distribution: 'temurin'
- name: Test cache: 'maven'
run: mvn --batch-mode test - name: Build modules requiring JDK 11
run: mvn --batch-mode install -DskipITs -pl langchain4j-opensearch
# For checking some compliance things (require a recent JDK due to plugins so in a separate step) # For checking some compliance things (require a recent JDK due to plugins so in a separate step)
compliance: compliance:
@ -26,6 +36,7 @@ jobs:
with: with:
java-version: '17' java-version: '17'
distribution: 'temurin' distribution: 'temurin'
cache: 'maven'
# Check we only rely on permissive licenses in the main parts of the library: # Check we only rely on permissive licenses in the main parts of the library:
- name: License Compliance - name: License Compliance
run: mvn -P compliance org.honton.chas:license-maven-plugin:compliance run: mvn -P compliance org.honton.chas:license-maven-plugin:compliance

View File

@ -1,34 +1,5 @@
package dev.langchain4j.store.embedding.elasticsearch; package dev.langchain4j.store.embedding.elasticsearch;
import static dev.langchain4j.internal.Utils.isCollectionEmpty;
import static dev.langchain4j.internal.Utils.isNullOrBlank;
import static dev.langchain4j.internal.Utils.randomUUID;
import static dev.langchain4j.internal.ValidationUtils.ensureNotNull;
import static dev.langchain4j.internal.ValidationUtils.ensureTrue;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import co.elastic.clients.elasticsearch.ElasticsearchClient; import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.InlineScript; import co.elastic.clients.elasticsearch._types.InlineScript;
import co.elastic.clients.elasticsearch._types.mapping.DenseVectorProperty; import co.elastic.clients.elasticsearch._types.mapping.DenseVectorProperty;
@ -48,11 +19,36 @@ import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.endpoints.BooleanResponse; import co.elastic.clients.transport.endpoints.BooleanResponse;
import co.elastic.clients.transport.rest_client.RestClientTransport; import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import dev.langchain4j.data.document.Metadata; import dev.langchain4j.data.document.Metadata;
import dev.langchain4j.data.embedding.Embedding; import dev.langchain4j.data.embedding.Embedding;
import dev.langchain4j.data.segment.TextSegment; import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingMatch; import dev.langchain4j.store.embedding.EmbeddingMatch;
import dev.langchain4j.store.embedding.EmbeddingStore; import dev.langchain4j.store.embedding.EmbeddingStore;
import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.message.BasicHeader;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static dev.langchain4j.internal.Utils.*;
import static dev.langchain4j.internal.ValidationUtils.ensureNotNull;
import static dev.langchain4j.internal.ValidationUtils.ensureTrue;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
/** /**
* Represents an <a href="https://www.elastic.co/">Elasticsearch</a> index as an embedding store. * Represents an <a href="https://www.elastic.co/">Elasticsearch</a> index as an embedding store.
@ -103,9 +99,9 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore<TextSegment>
this.objectMapper = new ObjectMapper(); this.objectMapper = new ObjectMapper();
} }
public ElasticsearchEmbeddingStore(RestClient client, String indexName) { public ElasticsearchEmbeddingStore(RestClient restClient, String indexName) {
JsonpMapper mapper = new JacksonJsonpMapper(); JsonpMapper mapper = new JacksonJsonpMapper();
ElasticsearchTransport transport = new RestClientTransport(client, mapper); ElasticsearchTransport transport = new RestClientTransport(restClient, mapper);
this.client = new ElasticsearchClient(transport); this.client = new ElasticsearchClient(transport);
this.indexName = ensureNotNull(indexName, "indexName"); this.indexName = ensureNotNull(indexName, "indexName");
@ -122,11 +118,12 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore<TextSegment>
private String apiKey; private String apiKey;
private String userName; private String userName;
private String password; private String password;
private RestClient client; private RestClient restClient;
private String indexName = "default"; private String indexName = "default";
/** /**
* @param serverUrl Elasticsearch Server URL * @param serverUrl Elasticsearch Server URL
* @return builder
*/ */
public Builder serverUrl(String serverUrl) { public Builder serverUrl(String serverUrl) {
this.serverUrl = serverUrl; this.serverUrl = serverUrl;
@ -162,16 +159,18 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore<TextSegment>
/** /**
* @param restClient Elasticsearch RestClient (optional). * @param restClient Elasticsearch RestClient (optional).
* Effectively overrides all other connection parameters serverUrl, etc. * Effectively overrides all other connection parameters like serverUrl, etc.
* @return builder
*/ */
public Builder restClient(RestClient client) { public Builder restClient(RestClient restClient) {
this.client = client; this.restClient = restClient;
return this; return this;
} }
/** /**
* @param indexName Elasticsearch index name (optional). * @param indexName Elasticsearch index name (optional).
* Default value: "default". * Default value: "default".
* @return builder
*/ */
public Builder indexName(String indexName) { public Builder indexName(String indexName) {
this.indexName = indexName; this.indexName = indexName;
@ -179,8 +178,8 @@ public class ElasticsearchEmbeddingStore implements EmbeddingStore<TextSegment>
} }
public ElasticsearchEmbeddingStore build() { public ElasticsearchEmbeddingStore build() {
if (client != null) { if (restClient != null) {
return new ElasticsearchEmbeddingStore(client, indexName); return new ElasticsearchEmbeddingStore(restClient, indexName);
} else { } else {
return new ElasticsearchEmbeddingStore(serverUrl, apiKey, userName, password, indexName); return new ElasticsearchEmbeddingStore(serverUrl, apiKey, userName, password, indexName);
} }

View File

@ -200,12 +200,6 @@
<version>${spring-boot.version}</version> <version>${spring-boot.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents.client5</groupId> <groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId> <artifactId>httpclient5</artifactId>