一个使用 Java 开发的 LLM 应用开发框架,Agents-Flex alpha.2 发布
Agents-Flex: 一个使用 Java 开发的 LLM(大语言模型) 应用开发框架
基本能力
- LLM 的访问能力
- Prompt、Prompt Template 定义加载的能力
- Function Calling 定义、调用和执行等能力
- 记忆的能力(Memory)
- Embedding
- Vector Storage
- 文档处理
- 加载器(Loader)
- Http
- FileSystem
- 分割器(Splitter)
- 解析器(Parser)
- PoiParser
- PdfBoxParser
- 加载器(Loader)
- LLM Chain
- Agents Chain
功能列表
简单对话示例
使用 OpenAi 大语言模型:
public static void main(String[] args) throws InterruptedException { OpenAiConfig config = new OpenAiConfig(); config.setApiKey("sk-rts5NF6n*******"); Llm llm = new OpenAiLlm(config); Prompt prompt = new SimplePrompt("请写一个关于小兔子战胜大灰狼的故事。"); llm.chat(prompt, (llmInstance, message) -> { System.out.println("--->" + message.getContent()); }); Thread.sleep(10000); }
使用 “通义千问” 大语言模型:
public static void main(String[] args) throws InterruptedException { QwenLlmConfig config = new QwenLlmConfig(); config.setApiKey("sk-28a6be3236****"); config.setModel("qwen-turbo"); Llm llm = new QwenLlm(config); Prompt prompt = new SimplePrompt("请写一个关于小兔子战胜大灰狼的故事。"); llm.chat(prompt, (llmInstance, message) -> { System.out.println("--->" + message.getContent()); }); Thread.sleep(10000); }
使用 “讯飞星火” 大语言模型:
public static void main(String[] args) throws InterruptedException { SparkLlmConfig config = new SparkLlmConfig(); config.setAppId("****"); config.setApiKey("****"); config.setApiSecret("****"); Llm llm = new SparkLlm(config); Prompt prompt = new SimplePrompt("请写一个关于小兔子战胜大灰狼的故事。"); llm.chat(prompt, (llmInstance, message) -> { System.out.println("--->" + message.getContent()); }); Thread.sleep(10000); }
历史对话示例
public static void main(String[] args) throws InterruptedException { SparkLlmConfig config = new SparkLlmConfig(); config.setAppId("****"); config.setApiKey("****"); config.setApiSecret("****"); // 创建一个大模型 Llm llm = new SparkLlm(config); //创建一个历史对话的 prompt 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.chat(prompt, (instance, message) -> { System.out.println(">>>> " + message.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 ) { //这里应该是通过接口去调用获得天气信息 return name + "的天气是阴转多云。 "; } }
- 第二步:通过 Prompt、Functions 传入给大模型,然后得到结果
public static void main(String[] args) throws InterruptedException { OpenAiLlmConfig config = new OpenAiLlmConfig(); config.setApiKey("sk-rts5NF6n*******"); OpenAiLlm llm = new OpenAiLlm(config); Functions<String> functions = Functions.from(WeatherUtil.class, String.class); String result = llm.call(new SimplePrompt("今天的天气如何"), functions); System.out.println(result); // "北京的天气是阴转多云。 "; Thread.sleep(10000); }
注意:当前版本为 v1.0.0-alpha.2 ,还在开发中,请暂时勿使用于正式的商业产品中。
开源地址:

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
EmbedXrpc V5.0.0 已经发布,用于单片机场景的“gRPC”
EmbedXrpc V5.0.0 已经发布,用于单片机场景的“gRPC” 此版本更新内容包括大版本,重大变更: 1.移植Free RTOS的message buffer/queue到WIN32 和裸机 2.重构RunTime配置,减小很多无用内存 详情查看:https://gitee.com/snikeguo/EmbedXrpc/releases/V5.0.0
- 下一篇
野火IM 1.2.3 已经发布,即时通讯系统
野火IM 1.2.3 已经发布,即时通讯系统 此版本更新内容包括: Release note 1.2.3: 同步专业版IM服务server SDK。 添加对鸿蒙平台的支持。 解决server端音视频SDK信令支持问题。 升级部分依赖,解决漏洞问题 附件的版本有3种格式,分别是Java通用版本、Deb格式安装包和Rpm格式安装包包,可以根据平台或者自己的习惯下载其中一种软件包。另外在Github也可以下载。也可以下载我们网站上的最新版本,通用Java包,deb格式安装包和rpm格式安装包。 *** 0.42 版本增加了群成员数限制,默认为2000。如果您想修改默认值,可以在升级版本之后,修改t_setting表,把默认的大小改为您期望的。另外修改t_group表,把已经存在的群组max_member_count改成您期望的,然后重启。*** *** 0.46和0.47版本升级到0.48及以后版本时,可能会提示flyway migrate 38错误,请执行 修复脚本 进行修复。0.46和0.47版本之外的版本不会出现此问题。*** *** 0.50版本添加了是否允许客户端发送群操作通知的配...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS7,8上快速安装Gitea,搭建Git服务器
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- Docker快速安装Oracle11G,搭建oracle11g学习环境
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池