介绍
本项目是一个Java版的LangChain开发框架,具有灵活编排和流式执行能力,旨在简化和加速各类大模型应用在Java平台的落地开发。它提供了一组实用的工具和类,使得开发人员能够更轻松地构建类似于LangChain的Java应用程序。
github: https://github.com/flower-trees/j-langchain
快速开始
Maven
<dependency>
<groupId>io.github.flower-trees</groupId>
<artifactId>j-langchain</artifactId>
<version>1.0.8-preview</version>
</dependency>
Gradle
implementation 'io.github.flower-trees:j-langchain:1.0.8-preview'
配置
@Import(JLangchainConfig.class)
public class YourApplication {
public static void main(String[] args) {
SpringApplication.run(YourApplication.class, args);
}
}
export CHATGPT_KEY=xxx-xxx-xxx-xxx
使用
@Component
public class ChainBuildDemo {
@Autowired
ChainActor chainActor;
public void SimpleDemo() {
BaseRunnable<StringPromptValue, ?> prompt = PromptTemplate.fromTemplate("tell me a joke about ${topic}");
ChatOpenAI chatOpenAI = ChatOpenAI.builder().model("gpt-4").build();
FlowInstance chain = chainActor.builder().next(prompt).next(oll).next(new StrOutputParser()).build();
ChatGeneration result = chainActor.invoke(chain, Map.of("topic", "bears"));
System.out.println(result);
}
}
💡 Notes:
- 系统基于salt-function-flow流程编排框架开发,具体语法可 参考:https://github.com/flower-trees/salt-function-flow。