最新消息:首页公告!

Java 的 LLM 框架,Agents-Flex v1.3.4 发布

浏览 共有条评论 关键词:Java
新搜索营销

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
  • 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.2.8~1.3.4 更新记录:

  • 新增:Parameter 新增 formPlaceholder 属性
  • 新增: ReActAgent 添加 ChatOptions 的设置能力
  • 新增: ConfirmParameter 添加更多的配置参数支持
  • 新增:ChatOptions 新增 extra 配置,用于自定义大模型的参数内容
  • 优化:优化合并 ConfirmParameter 到 Parameter,以支持更多的场景
  • 优化:优化 AiMessageResponse.getFunctionCallers 方法
  • 优化:优化 getParameterValues 的错误信息
  • 优化:移除 chain 非必要的 error 日志
  • 优化:优化 Chain.getParameterValues
  • 优化:优化 getNodeContext 方法,只需要传入 id 值
  • 优化:移除 Moonshot ,使用 openai 替代
  • 优化:优化 parent 和 children 的过度设计,使之逻辑更加简洁
  • 修复:修复 Node 包含子的 chain 时,会导致 json 解析错误的问题
  • 修复:多轮 function call 时,获取最后一条 HumanMessage 错误的问题
  • 修复:Chain 的 Parameter 类型为 Array 时,内容固定值无法解析的问题
  • 修复:节点异步执行的情况下,可能出现 check 不正确的问题
  • 修复:jsExecNode 无法转换结果为 JsonObject 的问题

源码下载

转载请注明:可思数据 » Java 的 LLM 框架,Agents-Flex v1.3.4 发布

免责声明:本站来源的信息均由网友自主投稿和发布、编辑整理上传,或转载于第三方平台,对此类作品本站仅提供交流平台,不为其版权负责。本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本站联系,我们将及时更正、删除,谢谢。联系邮箱:elon368@sina.com

人工智能数据标注服务
留言与评论(共有 条评论)
昵称:
匿名发表 登录账号
                 
   
验证码:
后台-系统设置-扩展变量-手机广告位-手机广告位-内容广告位三