Agents-Flex: 一个基于 Java 的 LLM 应用开发及编排框架。
经过近 1 年的开发和迭代,Agents-Flex 发布了 30+ 个版本,终于迎来了 v1.0.0 正式版本。
与此同时,基于 Agents-flex 开发的对标 Dify Coze 等产品的 AIFlowy 也正式对外开源,开源地址: https://gitee.com/aiflowy/aiflowy
Agents-Flex 的基本能力
- LLM 的访问能力
- Prompt、Prompt Template 定义加载的能力
- Function Calling 定义、调用和执行等能力
- 记忆的能力(Memory)
- Embedding
- Vector Store
- 文档处理
- 加载器(Loader)
- Http
- FileSystem
- 分割器(Splitter)
- 解析器(Parser)
- PoiParser
- PdfBoxParser
- 加载器(Loader)
- Chain 执行链
- SequentialChain 顺序执行链
- ParallelChain 并发(并行)执行链
- LoopChain 循环执行连
- ChainNode
简单对话
使用 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.chatStream(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.getFunctionResult(); System.out.println(result); //"北京的天气是阴转多云。 " }
Agents-Flex v1.1.9~1.2.7 更新记录:
- 新增:代码执行节点添加 “_context” 对象
- 新增:新增 Chain.toJSON() 和 Chain.fromJSON() 方法
- 新增:新增 ConfirmNode 用于支持用户手动确认的场景
- 新增: Chain 新增 getNodeExecuteResult 方法
- 新增:新增 Audio 多模态的支持
- 新增:新增 ReActMessageBuilder,允许用户构建自定义的消息
- 新增:在节点执行出错时,添加必要的错误日志输出
- 新增:大模型 Parameter 添加子 Parameter 的配置支持
- 新增:ReActAgent 添加 continueOnActionJsonParseError 和 continueOnActionInvokeError 配置
- 新增:节点添加循环执行的配置能力
- 新增:新增 starter 中 deepseek 的配置支持,openai 可以指定 chatpath 属性
- 新增:OpenAILlm 支持自定义 HttpClient
- 新增:新增 es 和 lucene 搜索引擎
- 新增:新增 "default" rerank 模型,用于对接多个不同的 rerank 服务
- 新增:新增 ReAct Agent
- 优化:挂起-恢复执行逻辑优化,每次执行节点移除挂起节点列表中该节点
- 优化:优化 bom 模块依赖冲突 close #ICG2TD
- 优化:优化 ReActAgent 代码,新增更多的监听支持
- 优化:优化 OkHttpClientUtil 的默认参数
- 优化:重命名 JavascriptStringCondition 为 JsCodeCondition
- 优化:feat: 修改 TextAndImageMessage 和 TextAndAudioMessage 为 HumanImageMessage 和 HumanAudioMessage
- 优化:优化重构 EdgeCondition 和 NodeCondition 方法
- 优化:优化 Chain.getParameterValues 方法
- 优化:移动 Chain 监听器的相关类到 listener 包里去
- 修复:DeepseekLlm 无法自动注入,配置 factories 文件
- 修复:修复 EmbeddingModel.dimensions() 错误信息不友好的问题
- 修复:function call第二次请求模型时缺少了tools信息 close #ICG584
- 修复:修复 Gitee 生成图片错误的问题
- 文档:更新 chain 的相关文档
- 文档:更新优化 LLM 示例代码
- 文档:优化 prompt 示例代码
- 文档:节点循环示例代码
源码下载
- Gitee:https://gitee.com/agents-flex/agents-flex
- Github:https://github.com/agents-flex/agents-flex
还没有评论,来说两句吧...