Skip to content

Commit

Permalink
Merge branch 'langchain4j:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
qing-wq authored Nov 20, 2024
2 parents aaedd48 + 405fdda commit dbbb337
Show file tree
Hide file tree
Showing 52 changed files with 952 additions and 875 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Please provide a relevant code snippets to reproduce this bug.
A clear and concise description of what you expected to happen.

**Please complete the following information:**
- LangChain4j version: e.g. 0.35.0
- LangChain4j version: e.g. 0.36.1
- Java version: e.g. 17
- Spring Boot version: e.g. 3.3.1

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
AZURE_SEARCH_ENDPOINT: ${{ secrets.AZURE_SEARCH_ENDPOINT }}
AZURE_SEARCH_KEY: ${{ secrets.AZURE_SEARCH_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
AZURE_OPENAI_KEY: ${{ secrets.AZURE_OPENAI_KEY }}
AZURE_SEARCH_ENDPOINT: ${{ secrets.AZURE_SEARCH_ENDPOINT }}
AZURE_SEARCH_KEY: ${{ secrets.AZURE_SEARCH_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Expand Down
5 changes: 3 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
2 changes: 1 addition & 1 deletion langchain4j-anthropic-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring</artifactId>
<version>0.36.0-SNAPSHOT</version>
<version>0.37.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion langchain4j-azure-ai-search-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring</artifactId>
<version>0.36.0-SNAPSHOT</version>
<version>0.37.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
9 changes: 1 addition & 8 deletions langchain4j-azure-open-ai-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring</artifactId>
<version>0.36.0-SNAPSHOT</version>
<version>0.37.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand All @@ -34,13 +34,6 @@
<optional>true</optional>
</dependency>

<!-- should be listed before spring-boot-configuration-processor -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>

<!-- needed to generate automatic metadata about available config properties -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import com.azure.core.http.ProxyOptions;
import com.azure.core.util.Configuration;
import dev.langchain4j.model.Tokenizer;
import dev.langchain4j.model.azure.AzureOpenAiChatModel;
import dev.langchain4j.model.azure.AzureOpenAiEmbeddingModel;
import dev.langchain4j.model.azure.AzureOpenAiImageModel;
import dev.langchain4j.model.azure.AzureOpenAiStreamingChatModel;
import dev.langchain4j.model.azure.AzureOpenAiTokenizer;
import dev.langchain4j.model.azure.*;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand All @@ -34,22 +30,30 @@ AzureOpenAiChatModel openAiChatModelByNonAzureApiKey(Properties properties) {
}

AzureOpenAiChatModel openAiChatModel(Properties properties) {
ChatModelProperties chatModelProperties = properties.getChatModel();
ChatModelProperties chatModelProperties = properties.chatModel();
AzureOpenAiChatModel.Builder builder = AzureOpenAiChatModel.builder()
.endpoint(chatModelProperties.getEndpoint())
.apiKey(chatModelProperties.getApiKey())
.deploymentName(chatModelProperties.getDeploymentName())
.temperature(chatModelProperties.getTemperature())
.topP(chatModelProperties.getTopP())
.maxTokens(chatModelProperties.getMaxTokens())
.presencePenalty(chatModelProperties.getPresencePenalty())
.frequencyPenalty(chatModelProperties.getFrequencyPenalty())
.timeout(Duration.ofSeconds(chatModelProperties.getTimeout() == null ? 0 : chatModelProperties.getTimeout()))
.maxRetries(chatModelProperties.getMaxRetries())
.endpoint(chatModelProperties.endpoint())
.serviceVersion(chatModelProperties.serviceVersion())
.apiKey(chatModelProperties.apiKey())
.deploymentName(chatModelProperties.deploymentName())
// TODO inject tokenizer?
.maxTokens(chatModelProperties.maxTokens())
.temperature(chatModelProperties.temperature())
.topP(chatModelProperties.topP())
.logitBias(chatModelProperties.logitBias())
.user(chatModelProperties.user())
.stop(chatModelProperties.stop())
.presencePenalty(chatModelProperties.presencePenalty())
.frequencyPenalty(chatModelProperties.frequencyPenalty())
.seed(chatModelProperties.seed())
.timeout(Duration.ofSeconds(chatModelProperties.timeout() == null ? 0 : chatModelProperties.timeout()))
.maxRetries(chatModelProperties.maxRetries())
.proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration()))
.logRequestsAndResponses(chatModelProperties.getLogRequestsAndResponses() != null && chatModelProperties.getLogRequestsAndResponses());
if (chatModelProperties.getNonAzureApiKey() != null) {
builder.nonAzureApiKey(chatModelProperties.getNonAzureApiKey());
.logRequestsAndResponses(chatModelProperties.logRequestsAndResponses() != null && chatModelProperties.logRequestsAndResponses())
.userAgentSuffix(chatModelProperties.userAgentSuffix())
.customHeaders(chatModelProperties.customHeaders());
if (chatModelProperties.nonAzureApiKey() != null) {
builder.nonAzureApiKey(chatModelProperties.nonAzureApiKey());
}
return builder.build();
}
Expand All @@ -66,24 +70,31 @@ AzureOpenAiStreamingChatModel openAiStreamingChatModelByNonAzureApiKey(Propertie
return openAiStreamingChatModel(properties);
}


AzureOpenAiStreamingChatModel openAiStreamingChatModel(Properties properties) {
ChatModelProperties chatModelProperties = properties.getStreamingChatModel();
ChatModelProperties chatModelProperties = properties.streamingChatModel();
AzureOpenAiStreamingChatModel.Builder builder = AzureOpenAiStreamingChatModel.builder()
.endpoint(chatModelProperties.getEndpoint())
.apiKey(chatModelProperties.getApiKey())
.deploymentName(chatModelProperties.getDeploymentName())
.temperature(chatModelProperties.getTemperature())
.topP(chatModelProperties.getTopP())
.stop(chatModelProperties.getStop())
.maxTokens(chatModelProperties.getMaxTokens())
.presencePenalty(chatModelProperties.getPresencePenalty())
.frequencyPenalty(chatModelProperties.getFrequencyPenalty())
.timeout(Duration.ofSeconds(chatModelProperties.getTimeout() == null ? 0 : chatModelProperties.getTimeout()))
.endpoint(chatModelProperties.endpoint())
.serviceVersion(chatModelProperties.serviceVersion())
.apiKey(chatModelProperties.apiKey())
.deploymentName(chatModelProperties.deploymentName())
// TODO inject tokenizer?
.maxTokens(chatModelProperties.maxTokens())
.temperature(chatModelProperties.temperature())
.topP(chatModelProperties.topP())
.logitBias(chatModelProperties.logitBias())
.user(chatModelProperties.user())
.stop(chatModelProperties.stop())
.presencePenalty(chatModelProperties.presencePenalty())
.frequencyPenalty(chatModelProperties.frequencyPenalty())
.seed(chatModelProperties.seed())
.timeout(Duration.ofSeconds(chatModelProperties.timeout() == null ? 0 : chatModelProperties.timeout()))
.maxRetries(chatModelProperties.maxRetries())
.proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration()))
.logRequestsAndResponses(chatModelProperties.getLogRequestsAndResponses() != null && chatModelProperties.getLogRequestsAndResponses());
if (chatModelProperties.getNonAzureApiKey() != null) {
builder.nonAzureApiKey(chatModelProperties.getNonAzureApiKey());
.logRequestsAndResponses(chatModelProperties.logRequestsAndResponses() != null && chatModelProperties.logRequestsAndResponses())
.userAgentSuffix(chatModelProperties.userAgentSuffix())
.customHeaders(chatModelProperties.customHeaders());
if (chatModelProperties.nonAzureApiKey() != null) {
builder.nonAzureApiKey(chatModelProperties.nonAzureApiKey());
}
return builder.build();
}
Expand All @@ -101,19 +112,22 @@ AzureOpenAiEmbeddingModel openAiEmbeddingModelByNonAzureApiKey(Properties proper
}

AzureOpenAiEmbeddingModel openAiEmbeddingModel(Properties properties, Tokenizer tokenizer) {
EmbeddingModelProperties embeddingModelProperties = properties.getEmbeddingModel();
EmbeddingModelProperties embeddingModelProperties = properties.embeddingModel();
AzureOpenAiEmbeddingModel.Builder builder = AzureOpenAiEmbeddingModel.builder()
.endpoint(embeddingModelProperties.getEndpoint())
.apiKey(embeddingModelProperties.getApiKey())
.deploymentName(embeddingModelProperties.getDeploymentName())
.maxRetries(embeddingModelProperties.getMaxRetries())
.endpoint(embeddingModelProperties.endpoint())
.serviceVersion(embeddingModelProperties.serviceVersion())
.apiKey(embeddingModelProperties.apiKey())
.deploymentName(embeddingModelProperties.deploymentName())
.tokenizer(tokenizer)
.timeout(Duration.ofSeconds(embeddingModelProperties.getTimeout() == null ? 0 : embeddingModelProperties.getTimeout()))
.timeout(Duration.ofSeconds(embeddingModelProperties.timeout() == null ? 0 : embeddingModelProperties.timeout()))
.maxRetries(embeddingModelProperties.maxRetries())
.proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration()))
.logRequestsAndResponses(embeddingModelProperties.getLogRequestsAndResponses() != null && embeddingModelProperties.getLogRequestsAndResponses());

if (embeddingModelProperties.getNonAzureApiKey() != null) {
builder.nonAzureApiKey(embeddingModelProperties.getNonAzureApiKey());
.logRequestsAndResponses(embeddingModelProperties.logRequestsAndResponses() != null && embeddingModelProperties.logRequestsAndResponses())
.userAgentSuffix(embeddingModelProperties.userAgentSuffix())
.dimensions(embeddingModelProperties.dimensions())
.customHeaders(embeddingModelProperties.customHeaders());
if (embeddingModelProperties.nonAzureApiKey() != null) {
builder.nonAzureApiKey(embeddingModelProperties.nonAzureApiKey());
}
return builder.build();
}
Expand All @@ -131,27 +145,29 @@ AzureOpenAiImageModel openAiImageModelByNonAzureApiKey(Properties properties) {
}

AzureOpenAiImageModel openAiImageModel(Properties properties) {
ImageModelProperties imageModelProperties = properties.getImageModel();
ImageModelProperties imageModelProperties = properties.imageModel();
AzureOpenAiImageModel.Builder builder = AzureOpenAiImageModel.builder()
.endpoint(imageModelProperties.getEndpoint())
.apiKey(imageModelProperties.getApiKey())
.deploymentName(imageModelProperties.getDeploymentName())
.size(imageModelProperties.getSize())
.quality(imageModelProperties.getQuality())
.style(imageModelProperties.getStyle())
.user(imageModelProperties.getUser())
.responseFormat(imageModelProperties.getResponseFormat())
.timeout(imageModelProperties.getTimeout() == null ? null : Duration.ofSeconds(imageModelProperties.getTimeout()))
.maxRetries(imageModelProperties.getMaxRetries())
.endpoint(imageModelProperties.endpoint())
.serviceVersion(imageModelProperties.serviceVersion())
.apiKey(imageModelProperties.apiKey())
.deploymentName(imageModelProperties.deploymentName())
.quality(imageModelProperties.quality())
.size(imageModelProperties.size())
.user(imageModelProperties.user())
.style(imageModelProperties.style())
.responseFormat(imageModelProperties.responseFormat())
.timeout(imageModelProperties.timeout() == null ? null : Duration.ofSeconds(imageModelProperties.timeout()))
.maxRetries(imageModelProperties.maxRetries())
.proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration()))
.logRequestsAndResponses(imageModelProperties.getLogRequestsAndResponses() != null && imageModelProperties.getLogRequestsAndResponses());
if (imageModelProperties.getNonAzureApiKey() != null) {
builder.nonAzureApiKey(imageModelProperties.getNonAzureApiKey());
.logRequestsAndResponses(imageModelProperties.logRequestsAndResponses() != null && imageModelProperties.logRequestsAndResponses())
.userAgentSuffix(imageModelProperties.userAgentSuffix())
.customHeaders(imageModelProperties.customHeaders());
if (imageModelProperties.nonAzureApiKey() != null) {
builder.nonAzureApiKey(imageModelProperties.nonAzureApiKey());
}
return builder.build();
}


@Bean
@ConditionalOnMissingBean
AzureOpenAiTokenizer azureOpenAiTokenizer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package dev.langchain4j.azure.openai.spring;

import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;

@Getter
@Setter
class ChatModelProperties {
record ChatModelProperties(

String endpoint;
String apiKey;
String nonAzureApiKey;
String organizationId;
String deploymentName;
Double temperature;
Double topP;
Integer maxTokens;
Double presencePenalty;
Double frequencyPenalty;
String responseFormat;
Integer seed;
List<String> stop;
Integer timeout;
Integer maxRetries;
Boolean logRequestsAndResponses;
String endpoint,
String serviceVersion,
String apiKey,
String deploymentName,
Integer maxTokens,
Double temperature,
Double topP,
Map<String, Integer> logitBias,
String user,
List<String> stop,
Double presencePenalty,
Double frequencyPenalty,
Long seed,
String responseFormat,
Integer timeout, // TODO use Duration instead
Integer maxRetries,
Boolean logRequestsAndResponses,
String userAgentSuffix,
Map<String, String> customHeaders,
String nonAzureApiKey
) {
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package dev.langchain4j.azure.openai.spring;

import lombok.Getter;
import lombok.Setter;
import java.util.Map;

@Getter
@Setter
class EmbeddingModelProperties {
record EmbeddingModelProperties(

String endpoint;
String apiKey;
String nonAzureApiKey;
String deploymentName;
Integer dimensions;
Integer timeout;
Integer maxRetries;
Boolean logRequestsAndResponses;
String endpoint,
String serviceVersion,
String apiKey,
String deploymentName,
Integer timeout, // TODO use duration instead
Integer maxRetries,
Boolean logRequestsAndResponses,
String userAgentSuffix,
Integer dimensions,
Map<String, String> customHeaders,
String nonAzureApiKey
) {
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package dev.langchain4j.azure.openai.spring;

import lombok.Getter;
import lombok.Setter;
import java.util.Map;

@Getter
@Setter
class ImageModelProperties {
record ImageModelProperties(

String endpoint;
String apiKey;
String nonAzureApiKey;
String deploymentName;
String size;
String quality;
String style;
String responseFormat;
String user;
Integer timeout;
Integer maxRetries;
Boolean logRequestsAndResponses;
String endpoint,
String serviceVersion,
String apiKey,
String deploymentName,
String quality,
String size,
String user,
String style,
String responseFormat,
Integer timeout,
Integer maxRetries,
Boolean logRequestsAndResponses,
String userAgentSuffix,
Map<String, String> customHeaders,
String nonAzureApiKey
){
}
Loading

0 comments on commit dbbb337

Please sign in to comment.