“ 基于 Java 的大语言模型应用开发框架,Agents-Flex alpha.4 发布 ”
Agents-Flex 一个基于 Java 的 LLM大语言模型应用开发框架。
基本能力
- LLM 的访问能力
- Prompt、Prompt Template 定义加载的能力
- Function Calling 定义、调用和执行等能力
- 记忆的能力Memory
- Embedding
- Vector Storage
- 文档处理
加载器Loader
Http FileSystem
分割器Splitter 解析器Parser
PoiParser PdfBoxParser - 加载器Loader
Http FileSystem - Http - FileSystem - 分割器Splitter - 解析器Parser
PoiParser PdfBoxParser - PoiParser - PdfBoxParser - LLM Chain - Agents Chain
简单对话
使用 OpenAi 大语言模型:
@Test
public void testChat() {
OpenAiLlmConfig config = new OpenAiLlmConfig();
config.setApiKey("sk-rts5NF6n*******");
Llm llm = new OpenAiLlm(config);
String response = llm.chat("请问你叫什么名字");
System.out.println(response);
}
使用 “通义千问” 大语言模型:
@Test
public void testChat() {
QwenLlmConfig config = new QwenLlmConfig();
config.setApiKey("sk-28a6be3236****");
config.setModel("qwen-turbo");
Llm llm = new QwenLlm(config);
String response = llm.chat("请问你叫什么名字");
System.out.println(response);
}
使用 “讯飞星火” 大语言模型:
@Test
public void testChat() {
SparkLlmConfig config = new SparkLlmConfig();
config.setAppId("****");
config.setApiKey("****");
config.setApiSecret("****");
Llm llm = new SparkLlm(config);
String response = llm.chat("请问你叫什么名字");
System.out.println(response);
}
历史对话示例
public static void main(String[] args) {
SparkLlmConfig config = new SparkLlmConfig();
config.setAppId("****");
config.setApiKey("****");
config.setApiSecret("****");
Llm llm = new SparkLlm(config);
HistoriesPrompt prompt = new HistoriesPrompt();
System.out.println("您想问什么?");
Scanner scanner = new Scanner(System.in);
String userInput = scanner.nextLine();
while (userInput != null) {
prompt.addMessage(new HumanMessage(userInput));
llm.chatAsync(prompt, (context, response) -> {
System.out.println(">>>> " + response.getMessage().getContent());
});
userInput = scanner.nextLine();
}
}
Function Calling
第一步通过注解定义本地方法
public class WeatherUtil { @FunctionDef(name = "get_the_weather_info", description = "get the weather info") public static String getWeatherInfo( @FunctionParam(name = "city", description = "the city name") String name ) { //在这里,我们应该通过第三方接口调用 api 信息 return name + "的天气是阴转多云。 "; } }
第二步通过 Prompt、Functions 传入给大模型,然后得到结果
public static void main(String[] args) { OpenAiLlmConfig config = new OpenAiLlmConfig(); config.setApiKey("sk-rts5NF6n*******"); OpenAiLlm llm = new OpenAiLlm(config); FunctionPrompt prompt = new FunctionPrompt("今天北京的天气怎么样", WeatherUtil.class); FunctionResultResponse response = llm.chat(prompt); Object result = response.invoke(); System.out.println(result); //"北京的天气是阴转多云。 " }
模块构成
注意当前版本为 v1.0.0-alpha.4 ,还在开发中,请暂时勿使用于正式的商业产品中。
开源地址
每日一言
"<!doctype html> <html lang="Zh-cn"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="robots" content="noindex,nofollow"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <meta name="renderer" content="webkit"> <title>您请求的文件不存在!</title> <link type="text/css" rel="stylesheet" href="https://www.oick.cn/css/404.css" /> <link rel="shortcut icon" href="http://www.oick.cn/favicon.ico" type="image/x-icon" /> </head> <body> <div id="wrap"> <div> <img src="https://www.oick.cn/imgs/404.png" alt="404" /> </div> <div id="text"> <strong> <span></span> <a href="javascript:history.back()">返回上一页</a> </strong> </div> </div> <div class="animate below"></div> <div class="animate above"></div> </body> </html>"