Qianfan
Maven Dependency
You can use DashScope with LangChain4j in plain Java or Spring Boot applications.
Plain Java
note
Since 1.0.0-alpha1, langchain4j-qianfan has migrated to langchain4j-community and is renamed to langchain4j-community-qianfan.
Before 1.0.0-alpha1:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-qianfan</artifactId>
<version>${previous version here}</version>
</dependency>
1.0.0-alpha1 and later:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-qianfan</artifactId>
<version>${latest version here}</version>
</dependency>
Spring Boot
note
Since 1.0.0-alpha1, langchain4j-qianfan-spring-boot-starter has migrated to langchain4j-community and is renamed
to langchain4j-community-qianfan-spring-boot-starter.
Before 1.0.0-alpha1:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-qianfan-spring-boot-starter</artifactId>
<version>${previous version here}</version>
</dependency>
1.0.0-alpha1 and later:
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-qianfan-spring-boot-starter</artifactId>
<version>${latest version here}</version>
</dependency>
Or, you can use BOM to manage dependencies consistently:
<dependencyManagement>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-bom</artifactId>
<version>${latest version here}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>
QianfanChatModel
QianfanChatModel model = QianfanChatModel.builder()
.apiKey("apiKey")
.secretKey("secretKey")
.modelName("Yi-34B-Chat") // 一个免费的模型名称
.build();
String answer = model.chat("雷军");
System.out.println(answer);
Customizing
QianfanChatModel model = QianfanChatModel.builder()
.baseUrl(...)
.apiKey(...)
.secretKey(...)
.temperature(...)
.maxRetries(...)
.topP(...)
.modelName(...)
.endpoint(...)
.responseFormat(...)
.penaltyScore(...)
.logRequests(...)
.logResponses()
.build();
See the description of some of the parameters above here.
functions
IAiService(重点)
public interface IAiService {
/**
* Ai Services 提供了一种更简单、更灵活的替代方案。 您可以定义自己的 API(具有一个或多个方法的 Java 接口), 并将为其提供实现。
* @param userMessage
* @return String
*/
String chat(String userMessage);
}