当前位置: 首页 > news >正文

优秀企业网站模板深圳搭建网站公司

优秀企业网站模板,深圳搭建网站公司,空间站建设,404源码网html如何使用LangChain4j框架创建和使用多种AI服务。它通过定义接口和注解#xff0c;将自然语言处理任务#xff08;如情感分析、数字提取、日期提取、POJO提取等#xff09;封装为服务#xff0c;并通过LangChain4j的AiServices动态生成这些服务的实现。 本章主要讲述基于Lan… 如何使用LangChain4j框架创建和使用多种AI服务。它通过定义接口和注解将自然语言处理任务如情感分析、数字提取、日期提取、POJO提取等封装为服务并通过LangChain4j的AiServices动态生成这些服务的实现。 本章主要讲述基于LangChain调用大模型如何进行结构化输出的真实示例一共列列举,本章主要介绍如何从自然语言中借助大模型提取特定的数字的例子 整体代码结果说明 代码定义了多个静态内部类每个类都展示了LangChain4j中不同类型的AI服务示例。这些服务通过接口和注解定义并通过AiServices.create()方法动态生成实现。每个类都包含一个main方法用于演示如何调用这些服务。 数字提取服务NumberExtractor 数字提取服务NumberExtractor是LangChain4j框架中另一个典型的AI服务实现它展示了如何从文本中提取不同类型的数字并将其转换为相应的数值类型。 1. 接口定义 数字提取服务通过定义一个接口NumberExtractor来封装数字提取功能。接口中包含多个方法每个方法对应一种数值类型 extractInt(String text)从文本中提取整数int。extractLong(String text)从文本中提取长整数long。extractBigInteger(String text)从文本中提取大整数BigInteger。extractFloat(String text)从文本中提取浮点数float。extractDouble(String text)从文本中提取双精度浮点数double。extractBigDecimal(String text)从文本中提取高精度浮点数BigDecimal。 interface NumberExtractor {UserMessage(Extract number from {{it}})int extractInt(String text);UserMessage(Extract number from {{it}})long extractLong(String text);UserMessage(Extract number from {{it}})BigInteger extractBigInteger(String text);UserMessage(Extract number from {{it}})float extractFloat(String text);UserMessage(Extract number from {{it}})double extractDouble(String text);UserMessage(Extract number from {{it}})BigDecimal extractBigDecimal(String text); }2. 注解的使用 UserMessage用于定义用户消息模板。模板中的{{it}}会被替换为方法参数即要提取数字的文本。这使得AI能够理解用户的意图并生成相应的响应。 3. 动态生成服务实现 通过AiServices.create()方法LangChain4j框架动态生成了NumberExtractor接口的实现。这意味着开发者不需要手动实现接口方法而是由框架根据接口定义和注解自动生成实现逻辑。 NumberExtractor extractor AiServices.create(NumberExtractor.class, chatLanguageModel);4. 调用服务 在main方法中通过调用NumberExtractor的各个方法展示了如何使用该服务 调用extractInt(String text)方法提取整数。调用extractLong(String text)方法提取长整数。调用extractBigInteger(String text)方法提取大整数。调用extractFloat(String text)方法提取浮点数。调用extractDouble(String text)方法提取双精度浮点数。调用extractBigDecimal(String text)方法提取高精度浮点数。 String text After countless millennia of computation, the supercomputer Deep Thought finally announced that the answer to the ultimate question of life, the universe, and everything was forty two.;int intNumber extractor.extractInt(text); System.out.println(intNumber); // 输出42long longNumber extractor.extractLong(text); System.out.println(longNumber); // 输出42BigInteger bigIntegerNumber extractor.extractBigInteger(text); System.out.println(bigIntegerNumber); // 输出42float floatNumber extractor.extractFloat(text); System.out.println(floatNumber); // 输出42.0double doubleNumber extractor.extractDouble(text); System.out.println(doubleNumber); // 输出42.0BigDecimal bigDecimalNumber extractor.extractBigDecimal(text); System.out.println(bigDecimalNumber); // 输出42.05. 技术优势 封装性通过接口和注解将数字提取功能封装为一个服务使得代码更加模块化易于维护和扩展。 动态性利用LangChain4j框架的动态生成能力自动实现接口方法减少了手动编码的工作量。 灵活性通过注解定义用户消息模板可以灵活地调整AI的输入和输出格式适应不同的业务需求。 可扩展性可以轻松添加更多类型的数字提取功能或扩展到其他自然语言处理任务。 类型安全支持多种数值类型确保提取的数字可以无缝地转换为所需的类型避免类型转换错误。 完整代码 public class OtherServiceExamples {// 使用OpenAI的API密钥初始化ChatLanguageModelstatic ChatLanguageModel chatLanguageModel OpenAiChatModel.withApiKey(ApiKeys.OPENAI_API_KEY);/*** 数字提取服务示例*/static class Number_Extracting_AI_Service_Example {// 定义数字提取接口interface NumberExtractor {// 提取整数UserMessage(Extract number from {{it}})int extractInt(String text);// 提取长整数UserMessage(Extract number from {{it}})long extractLong(String text);// 提取BigIntegerUserMessage(Extract number from {{it}})BigInteger extractBigInteger(String text);// 提取浮点数UserMessage(Extract number from {{it}})float extractFloat(String text);// 提取双精度浮点数UserMessage(Extract number from {{it}})double extractDouble(String text);// 提取BigDecimalUserMessage(Extract number from {{it}})BigDecimal extractBigDecimal(String text);}public static void main(String[] args) {// 动态生成数字提取服务的实现NumberExtractor extractor AiServices.create(NumberExtractor.class, chatLanguageModel);// 测试文本String text After countless millennia of computation, the supercomputer Deep Thought finally announced that the answer to the ultimate question of life, the universe, and everything was forty two.;// 提取不同类型的数字int intNumber extractor.extractInt(text);System.out.println(intNumber); // 输出42long longNumber extractor.extractLong(text);System.out.println(longNumber); // 输出42BigInteger bigIntegerNumber extractor.extractBigInteger(text);System.out.println(bigIntegerNumber); // 输出42float floatNumber extractor.extractFloat(text);System.out.println(floatNumber); // 输出42.0double doubleNumber extractor.extractDouble(text);System.out.println(doubleNumber); // 输出42.0BigDecimal bigDecimalNumber extractor.extractBigDecimal(text);System.out.println(bigDecimalNumber); // 输出42.0}}} 代码解读 功能 从文本中提取数字并将其转换为不同类型的数值int、long、BigInteger、float、double、BigDecimal。 实现 定义了一个NumberExtractor接口包含多个方法每个方法对应一种数值类型。 使用UserMessage注解定义了用户消息模板。通过AiServices.create()动态生成NumberExtractor的实现。 调用 从文本中提取数字42并将其转换为不同类型的数值。 总结 数字提取服务NumberExtractor通过定义接口、使用注解和动态生成服务实现展示了LangChain4j框架的强大功能。这种实现方式不仅简化了开发流程还提高了代码的可维护性和可扩展性。通过UserMessage注解AI能够理解用户意图并生成相应的响应而动态生成的服务实现则避免了手动编写复杂的逻辑。这种模式可以广泛应用于其他自然语言处理任务为开发者提供了一种高效、灵活的解决方案。
http://www.w-s-a.com/news/163236/

相关文章:

  • 丰都网站建设价格镇江网站制作费用
  • app手机网站建设黄网站建设定制开发服务
  • 百度网盘app下载徐州优化网站建设
  • 附近网站电脑培训班展台设计方案介绍
  • 河南便宜网站建设价格低上海高端室内设计
  • 保险网站有哪些平台wordpress会员vip购买扩展
  • 网站怎么做图片转换广州车陂网站建设公司
  • 下载flash网站网站设计书的结构
  • 水利建设公共服务平台网站放心网络营销定制
  • 设计网站过程wordpress+分页静态
  • 临海网站制作好了如何上线如果安装wordpress
  • 长沙 学校网站建设网站制作价格上海
  • 九江网站推广徽hyhyk1国家住房部和城乡建设部 网站首页
  • 阿克苏网站建设咨询动漫设计与制作属于什么大类
  • 网站编辑做多久可以升职wordpress版权修改
  • 网站开发维护成本计算国外外贸平台
  • 简单的招聘网站怎么做购物网站功能报价
  • 哪个网站做中高端衣服建设自己网站的流程
  • 网站建设概况做网站的是怎么赚钱的
  • 网站发布信息的基本流程现在都不用dw做网站了吗
  • 赣州热门网站深圳龙岗做网站的公司
  • 中国最大的建站平台广告传媒公司取名
  • 深圳网站设计公司专业吗学动漫设计后悔死了
  • 企业网站形象建设网站开发入职转正申请书
  • 网站设计步骤济南建设网中标公告
  • 石佛营网站建设wordpress关健词
  • 您的网站空间即将过期建站 discuz
  • 上海简站商贸有限公司福州哪家专业网站设计制作最好
  • 博客网站开发流程苏州专业做网站的公司哪家好
  • 四川手机网站建设西安 网站 高端 公司