您现在的位置是:首页 > 文章详情

🔥 基于 Java 的 LLM 开发框架,Agents-Flex rc.7 发布

日期:2025-03-12点击:73

Agents-Flex: 一个基于 Java 的 LLM 应用开发及编排框架。


经过近 1 年的开发和迭代,Agents-Flex 终于迎来了 RC,也就意味着 API 基本稳定,接下来的主要工作和完善文档和细节优化,进化在几个 RC 版本后,推出正式的版本。

目前,我们也基于 Agents-Flex 开发了许多有趣的应用,如下图所示:

工作流编排等:

Agents-Flex 的基本能力

  • LLM 的访问能力
  • Prompt、Prompt Template 定义加载的能力
  • Function Calling 定义、调用和执行等能力
  • 记忆的能力(Memory)
  • Embedding
  • Vector Store
  • 文档处理
    • 加载器(Loader)
      • Http
      • FileSystem
    • 分割器(Splitter)
    • 解析器(Parser)
      • PoiParser
      • PdfBoxParser
  • 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 rc.7 更新记录:

  • 新增:添加在在返回消息中增加推理内容的功能,支持 deepseek 的推理返回,感谢 @rirch
  • 新增:添加 vectorexdb 内嵌版本支持,无需额外部署数据库,感谢 @javpower
  • 新增:添加接入腾讯大模型语言、文生图模型与向量化接口的支持,感谢 @sunchanghuilinqing
  • 新增:对接豆包 doubao-1-5-vision-pro-32k 多模态模型以及文生图的支持,感谢 @wang110wyy
  • 新增:新增阿里百炼平台的文生图模型,感谢 @sunchanghuilinqing
  • 新增:新增基于 VLLM 部署大模型接入,感谢 @sunchanghuilinqing
  • 新增:新增 LogUtil 用于输出日志
  • 优化:优化 DnjsonClient 的相关代码逻辑
  • 修复:星火大模型的 uid 太长的问题,感谢 @wu-zhihao
  • 修复:Ollama Llm 的 chatStream 主动关闭流时发生错误的问题
  • 修复:修复默认情况下 OllamaProperties 的 endpoint 配置错误的问题

源码下载

原文链接:https://www.oschina.net/news/338334/agents-flex-rc7
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章