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

网站留言板制作资讯型电商网站优缺点

网站留言板制作,资讯型电商网站优缺点,小程序游戏源码,网站生成静态页面工具Spring AI Alibaba 实现了与阿里云通义模型的完整适配#xff0c;接下来#xff0c;我们将学习如何使用 spring ai alibaba 开发一个基于通义模型服务的智能聊天应用。 一、快速体验示例 注意#xff1a;因为 Spring AI Alibaba 基于 Spring Boot 3.x 开发#xff0c;因此…Spring AI Alibaba 实现了与阿里云通义模型的完整适配接下来我们将学习如何使用 spring ai alibaba 开发一个基于通义模型服务的智能聊天应用。 一、快速体验示例 注意因为 Spring AI Alibaba 基于 Spring Boot 3.x 开发因此本地 JDK 版本要求为 17 及以上。 下载项目 运行以下命令下载源码进入 helloworld 示例目录 git clone --depth1 https://github.com/alibaba/spring-ai-alibaba.git cd spring-ai-alibaba/spring-ai-alibaba-examples/helloworld-example 运行项目 首先需要获取一个合法的 API-KEY 并设置 AI_DASHSCOPE_API_KEY 环境变量可跳转 阿里云百炼平台 了解如何获取 API-KEY。 export AI_DASHSCOPE_API_KEY${REPLACE-WITH-VALID-API-KEY} 启动示例应用 ./mvnw compile exec:java -Dexec.mainClasscom.alibaba.cloud.ai.example.helloworld.HelloWorldExampleApplication 访问 http://localhost:8080/ai/chat?input给我讲一个笑话吧向通义模型提问并得到回答。 二、示例开发指南 以上示例本质上就是一个普通的 Spring Boot 应用我们来通过源码解析看一下具体的开发流程。 添加依赖 首先需要在项目中添加 spring-ai-alibaba-starter 依赖它将通过 Spring Boot 自动装配机制初始化与阿里云通义大模型通信的 ChatClient、ChatModel 相关实例。 dependencygroupIdcom.alibaba.cloud.ai/groupIdartifactIdspring-ai-alibaba-starter/artifactIdversion1.0.0-M2.1/version/dependency 注意由于 spring-ai 相关依赖包还没有发布到中央仓库如出现 spring-ai-core 等相关依赖解析问题请在您项目的 pom.xml 依赖中加入如下仓库配置。 repositories repository idspring-milestones/id nameSpring Milestones/name urlhttps://repo.spring.io/milestone/url snapshots enabledfalse/enabled /snapshots /repository /repositories 注入 ChatClient 接下来在普通 Controller Bean 中注入 ChatClient 实例这样你的 Bean 就具备与 AI 大模型智能对话的能力了。 RestControllerRequestMapping(/ai)public class ChatController {private final ChatClient chatClient;public ChatController(ChatClient.Builder builder) {this.chatClient builder.build();}GetMapping(/chat)public String chat(String input) {return this.chatClient.prompt().user(input).call().content();}} 以上示例中ChatClient 调用大模型使用的是默认参数Spring AI Alibaba 还支持通过 DashScopeChatOptions 调整与模型对话时的参数DashScopeChatOptions 支持两种不同维度的配置方式 全局默认值即 ChatClient 实例初始化参数 可以在 application.yaml 文件中指定 spring.ai.dashscope.chat.options.* 或调用构造函数 ChatClient.Builder.defaultOptions(options)、DashScopeChatModel(api, options) 完成配置初始化。 每次 Prompt 调用前动态指定 ChatResponse response chatModel.call(new Prompt(Generate the names of 5 famous pirates.,DashScopeChatOptions.builder().withModel(qwen-plus).withTemperature(0.4F).build())); 关于 DashScopeChatOptions 配置项的详细说明请查看参考手册。 三、开发实例RAG介绍 检索增强生成 (RAG) 是一种使用来自私有或专有数据源的信息来辅助文本生成的技术。它将检索模型设计用于搜索大型数据集或知识库和生成模型例如大型语言模型 (LLM)此类模型会使用检索到的信息生成可供阅读的文本回复结合在一起。 通过从更多数据源添加背景信息以及通过训练来补充 LLM 的原始知识库检索增强生成能够提高搜索体验的相关性。这能够改善大型语言模型的输出但又无需重新训练模型。额外信息源的范围很广从训练 LLM 时并未用到的互联网上的新信息到专有商业背景信息或者属于企业的机密内部文档都会包含在内。 RAG 对于诸如回答问题和内容生成等任务具有极大价值因为它能支持生成式 AI 系统使用外部信息源生成更准确且更符合语境的回答。它会实施搜索检索方法通常是语义搜索或混合搜索来回应用户的意图并提供更相关的结果。 下图是一个RAG链路的两个阶段包括Indexing pipeline阶段和RAG的阶段。 从上图可以看到, indexing pipeline的阶段主要是将结构化或者非结构化的数据或文档进行加载和解析、chunk切分、文本向量化并保存到向量数据库。 RAG的阶段主要包括将prompt文本内容转为向量、从向量数据库检索内容、对检索后的文档chunk进行重排和prompt重写、最后调用大模型进行结果的生成。 1、RAG调用 引入依赖 ?xml version1.0 encodingUTF-8?!--Copyright 2023-2024 the original author or authors.Licensed under the Apache License, Version 2.0 (the License);you may not use this file except in compliance with the License.You may obtain a copy of the License athttps://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an AS IS BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License. --project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion3.3.3/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.alibaba.cloud.ai/groupIdartifactIdrag-example/artifactIdversion0.0.1-SNAPSHOT/versionnamerag-example/namedescriptionDemo project for Spring AI Alibaba/descriptionpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingmaven.compiler.source17/maven.compiler.sourcemaven.compiler.target17/maven.compiler.targetmaven-deploy-plugin.version3.1.1/maven-deploy-plugin.version!-- Spring AI --spring-ai-alibaba.version1.0.0-M3.2/spring-ai-alibaba.versionspring-ai.version1.0.0-M3/spring-ai.version!-- utils --commons-lang3.version3.14.0/commons-lang3.version/propertiesdependenciesdependencygroupIdcom.alibaba.cloud.ai/groupIdartifactIdspring-ai-alibaba-starter/artifactIdversion${spring-ai-alibaba.version}/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.apache.commons/groupIdartifactIdcommons-lang3/artifactId/dependencydependencygroupIdorg.springframework.ai/groupIdartifactIdspring-ai-pdf-document-reader/artifactIdversion${spring-ai.version}/version/dependencydependencygroupIdorg.springframework.ai/groupIdartifactIdspring-ai-elasticsearch-store-spring-boot-starter/artifactIdversion${spring-ai.version}/version/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactId/pluginplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-deploy-plugin/artifactIdversion${maven-deploy-plugin.version}/versionconfigurationskiptrue/skip/configuration/plugin/plugins/buildrepositoriesrepositoryidspring-milestones/idnameSpring Milestones/nameurlhttps://repo.spring.io/milestone/urlsnapshotsenabledfalse/enabled/snapshots/repository/repositories/project 知识库内容导入 下边是将pdf文档导入到知识库的代码 DashScopeApi dashscopeApi ...;// 1. 解析文档和chunk切分 String filePath 新能源产业有哪些-36氪.pdf; DashScopeDocumentCloudReader reader new DashScopeDocumentCloudReader(filePath, dashscopeApi, null); ListDocument documentList reader.get(); DashScopeDocumentTransformer transformer new DashScopeDocumentTransformer(dashscopeApi); ListDocument transformerList transformer.apply(documentList); System.out.println(transformerList.size());// 2. 文档向量化 DashScopeEmbeddingModel embeddingModel new DashScopeEmbeddingModel(dashscopeApi); Document document new Document(你好阿里云); float[] vectorList embeddingModel.embed(document);// 3. 导入文档内容到向量存储 DashScopeCloudStore cloudStore new DashScopeCloudStore(dashscopeApi, new DashScopeStoreOptions(bailian-knowledge)); cloudStore.add(Arrays.asList(document));// 4. 删除文档 cloudStore.delete(Arrays.asList(document.getId())); 知识问答 下边代码将根据之前创建的知识库进行知识问答的代码: DocumentRetriever retriever new DashScopeDocumentRetriever(dashscopeApi, DashScopeDocumentRetrieverOptions.builder().withIndexName(bailian-knowledge).build());ChatClient chatClient ChatClient.builder(dashscopeChatModel).defaultAdvisors(new DocumentRetrievalAdvisor(retriever)).build();ChatResponse response chatClient.prompt().user(如何快速开始百炼?).call().chatResponse(); String content response.getResult().getOutput().getContent(); Assertions.assertNotNull(content);logger.info(content: {}, content); 如果需要返回检索召回后模型采纳和引用的文档内容, 可以通过以下代码实现: DocumentRetriever retriever new DashScopeDocumentRetriever(dashscopeApi,DashScopeDocumentRetrieverOptions.builder().withIndexName(spring-ai知识库).build());ChatClient chatClient ChatClient.builder(dashscopeChatModel).defaultAdvisors(new DashScopeDocumentRetrievalAdvisor(retriever, true)).build();ChatResponse response chatClient.prompt().user(如何快速开始百炼?).call().chatResponse();String content response.getResult().getOutput().getContent(); Assertions.assertNotNull(content); logger.info(content: {}, content);//获取引用的内容 ListDocument documents (ListDocument) response.getMetadata().get(DashScopeDocumentRetrievalAdvisor.RETRIEVED_DOCUMENTS); Assertions.assertNotNull(documents);for (Document document : documents) {logger.info(referenced doc name: {}, title: {}, score: {}, document.getMetadata().get(doc_name),document.getMetadata().get(title), document.getMetadata().get(_score));}
http://www.hkea.cn/news/14505076/

相关文章:

  • 济南网站制作策划兰州网新公司
  • 营销网站建设评估及分析贵阳网站开发多少钱
  • 各个做网站的有什么区别系统集成项目管理
  • 可以直接打开网站的网页百度竞价有点击无转化
  • wordpress上传图片权限大连知名的seo外包
  • 网站策划方案案例360免费做网站
  • 做ps网页设计的网站有哪些海阳市城建设局网站
  • 如何查看网站做没做竞价开发公司采购招聘
  • 德州seo整站优化如何寻找做网站的客户
  • 临漳seo整站排名免费自助建站软件
  • 西凤酒网站建设的基本情况怀远做网站电话
  • 网站开发需要学习什么技术wordpress修复缩略图
  • 淄博网站的优化微平台是什么
  • 爱站seo排名可以做哪些网站开发一个app软件的开发费用
  • 湖北省建设厅乡镇污水官方网站推广平台有哪些
  • 中卫网站定制开发价格深圳电子商务平台设计
  • 重庆排名优化整站优化北京做网站制作的公司哪家好
  • 网站建设银行转账三水网站制作
  • 人工智能设计网站设计师的网站
  • 杭州微网站开发公司泾阳县建设局网站
  • 武进区城乡建设局网站网站原型怎么做
  • 电力网站怎么做2狠狠做网站
  • 朋友圈海报用什么网站做的网站建设需要些什么资料
  • 涂料网站建设wordpress+one+page
  • 建立什么样的网站好joomla 2.5:你的网站建设_使用与管理 下载
  • 做网站平台多少钱青岛开发网站
  • 新手学做免费网站软件湖北建筑网
  • 著名的个人网站网页加速器插件
  • 网站进入之前动态效果泉州网
  • 做衣服招临工在什么网站找查看网站cms