-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
897 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>dev.langchain4j</groupId> | ||
<artifactId>langchain4j-spring</artifactId> | ||
<version>0.32.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>langchain4j-qianfan-spring-boot-starter</artifactId> | ||
<name>LangChain4j Spring Boot starter for Qianfan</name> | ||
<dependencies> | ||
<dependency> | ||
<groupId>dev.langchain4j</groupId> | ||
<artifactId>langchain4j-qianfan</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure-processor</artifactId> | ||
<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> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<licenses> | ||
<license> | ||
<name>Apache-2.0</name> | ||
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
<comments>A business-friendly OSS license</comments> | ||
</license> | ||
</licenses> | ||
</project> |
110 changes: 110 additions & 0 deletions
110
...-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/AutoConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package dev.langchain4j.qianfan.spring; | ||
|
||
import dev.langchain4j.model.qianfan.*; | ||
import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
import static dev.langchain4j.qianfan.spring.Properties.PREFIX; | ||
|
||
@AutoConfiguration | ||
@EnableConfigurationProperties(Properties.class) | ||
public class AutoConfig { | ||
|
||
@Bean | ||
@ConditionalOnProperty(PREFIX + ".chat-model.api-key") | ||
QianfanChatModel qianfanChatModel(Properties properties) { | ||
ChatModelProperties chatModelProperties = properties.getChatModel(); | ||
return QianfanChatModel.builder() | ||
.baseUrl(chatModelProperties.getBaseUrl()) | ||
.apiKey(chatModelProperties.getApiKey()) | ||
.secretKey(chatModelProperties.getSecretKey()) | ||
.endpoint(chatModelProperties.getEndpoint()) | ||
.penaltyScore(chatModelProperties.getPenaltyScore()) | ||
.modelName(chatModelProperties.getModelName()) | ||
.temperature(chatModelProperties.getTemperature()) | ||
.topP(chatModelProperties.getTopP()) | ||
.responseFormat(chatModelProperties.getResponseFormat()) | ||
.maxRetries(chatModelProperties.getMaxRetries()) | ||
.logRequests(chatModelProperties.getLogRequests()) | ||
.logResponses(chatModelProperties.getLogResponses()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(PREFIX + ".streaming-chat-model.api-key") | ||
QianfanStreamingChatModel qianfanStreamingChatModel(Properties properties) { | ||
ChatModelProperties chatModelProperties = properties.getStreamingChatModel(); | ||
return QianfanStreamingChatModel.builder() | ||
.endpoint(chatModelProperties.getEndpoint()) | ||
.penaltyScore(chatModelProperties.getPenaltyScore()) | ||
.temperature(chatModelProperties.getTemperature()) | ||
.topP(chatModelProperties.getTopP()) | ||
.baseUrl(chatModelProperties.getBaseUrl()) | ||
.apiKey(chatModelProperties.getApiKey()) | ||
.secretKey(chatModelProperties.getSecretKey()) | ||
.modelName(chatModelProperties.getModelName()) | ||
.responseFormat(chatModelProperties.getResponseFormat()) | ||
.logRequests(chatModelProperties.getLogRequests()) | ||
.logResponses(chatModelProperties.getLogResponses()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(PREFIX + ".language-model.api-key") | ||
QianfanLanguageModel qianfanLanguageModel(Properties properties) { | ||
LanguageModelProperties languageModelProperties = properties.getLanguageModel(); | ||
return QianfanLanguageModel.builder() | ||
.endpoint(languageModelProperties.getEndpoint()) | ||
.penaltyScore(languageModelProperties.getPenaltyScore()) | ||
.topK(languageModelProperties.getTopK()) | ||
.topP(languageModelProperties.getTopP()) | ||
.baseUrl(languageModelProperties.getBaseUrl()) | ||
.apiKey(languageModelProperties.getApiKey()) | ||
.secretKey(languageModelProperties.getSecretKey()) | ||
.modelName(languageModelProperties.getModelName()) | ||
.temperature(languageModelProperties.getTemperature()) | ||
.maxRetries(languageModelProperties.getMaxRetries()) | ||
.logRequests(languageModelProperties.getLogRequests()) | ||
.logResponses(languageModelProperties.getLogResponses()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(PREFIX + ".streaming-language-model.api-key") | ||
QianfanStreamingLanguageModel openAiStreamingLanguageModel(Properties properties) { | ||
LanguageModelProperties languageModelProperties = properties.getStreamingLanguageModel(); | ||
return QianfanStreamingLanguageModel.builder() | ||
.endpoint(languageModelProperties.getEndpoint()) | ||
.penaltyScore(languageModelProperties.getPenaltyScore()) | ||
.topK(languageModelProperties.getTopK()) | ||
.topP(languageModelProperties.getTopP()) | ||
.baseUrl(languageModelProperties.getBaseUrl()) | ||
.apiKey(languageModelProperties.getApiKey()) | ||
.secretKey(languageModelProperties.getSecretKey()) | ||
.modelName(languageModelProperties.getModelName()) | ||
.temperature(languageModelProperties.getTemperature()) | ||
.maxRetries(languageModelProperties.getMaxRetries()) | ||
.logRequests(languageModelProperties.getLogRequests()) | ||
.logResponses(languageModelProperties.getLogResponses()) | ||
.build(); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnProperty(PREFIX + ".embedding-model.api-key") | ||
QianfanEmbeddingModel qianfanEmbeddingModel(Properties properties) { | ||
EmbeddingModelProperties embeddingModelProperties = properties.getEmbeddingModel(); | ||
return QianfanEmbeddingModel.builder() | ||
.baseUrl(embeddingModelProperties.getBaseUrl()) | ||
.endpoint(embeddingModelProperties.getEndpoint()) | ||
.apiKey(embeddingModelProperties.getApiKey()) | ||
.secretKey(embeddingModelProperties.getSecretKey()) | ||
.modelName(embeddingModelProperties.getModelName()) | ||
.user(embeddingModelProperties.getUser()) | ||
.maxRetries(embeddingModelProperties.getMaxRetries()) | ||
.logRequests(embeddingModelProperties.getLogRequests()) | ||
.logResponses(embeddingModelProperties.getLogResponses()) | ||
.build(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/ChatModelProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package dev.langchain4j.qianfan.spring; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@Setter | ||
class ChatModelProperties { | ||
String baseUrl; | ||
String apiKey; | ||
String secretKey; | ||
Double temperature; | ||
Integer maxRetries; | ||
Double topP; | ||
String modelName; | ||
String endpoint; | ||
String responseFormat; | ||
Double penaltyScore; | ||
Boolean logRequests; | ||
Boolean logResponses; | ||
} |
22 changes: 22 additions & 0 deletions
22
...g-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/EmbeddingModelProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package dev.langchain4j.qianfan.spring; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
|
||
import java.time.Duration; | ||
|
||
@Getter | ||
@Setter | ||
class EmbeddingModelProperties { | ||
|
||
String baseUrl; | ||
String apiKey; | ||
String secretKey; | ||
Integer maxRetries; | ||
String modelName; | ||
String endpoint; | ||
String user; | ||
Boolean logRequests; | ||
Boolean logResponses; | ||
} |
25 changes: 25 additions & 0 deletions
25
...ng-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/LanguageModelProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package dev.langchain4j.qianfan.spring; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
|
||
import java.time.Duration; | ||
|
||
@Getter | ||
@Setter | ||
class LanguageModelProperties { | ||
|
||
String baseUrl; | ||
String apiKey; | ||
String secretKey; | ||
Double temperature; | ||
Integer maxRetries; | ||
Integer topK; | ||
Double topP; | ||
String modelName; | ||
String endpoint; | ||
Double penaltyScore; | ||
Boolean logRequests; | ||
Boolean logResponses; | ||
} |
29 changes: 29 additions & 0 deletions
29
...-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/Properties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dev.langchain4j.qianfan.spring; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
|
||
@Getter | ||
@Setter | ||
@ConfigurationProperties(prefix = Properties.PREFIX) | ||
public class Properties { | ||
|
||
static final String PREFIX = "langchain4j.qianfan"; | ||
|
||
@NestedConfigurationProperty | ||
ChatModelProperties chatModel; | ||
|
||
@NestedConfigurationProperty | ||
ChatModelProperties streamingChatModel; | ||
|
||
@NestedConfigurationProperty | ||
LanguageModelProperties languageModel; | ||
|
||
@NestedConfigurationProperty | ||
LanguageModelProperties streamingLanguageModel; | ||
|
||
@NestedConfigurationProperty | ||
EmbeddingModelProperties embeddingModel; | ||
} |
1 change: 1 addition & 0 deletions
1
...esources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dev.langchain4j.qianfan.spring.AutoConfig |
Oops, something went wrong.