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

网站备案目的张家界seo

网站备案目的,张家界seo,黄骅市在哪里,网站建设是啥工作在上一篇概述中(Spring-ai 1.0.0 学习(一)——概述-CSDN博客)大概介绍了spring-ai,接下来我们直接上代码,看一个最小化的spring-ai样例 首先是pom.xml文件,仅需引入spring-boot-starter-web和s…

在上一篇概述中(Spring-ai 1.0.0 学习(一)——概述-CSDN博客)大概介绍了spring-ai,接下来我们直接上代码,看一个最小化的spring-ai样例

首先是pom.xml文件,仅需引入spring-boot-starter-web和spring-ai-starter-model-zhipuai(根据所选大语言模型不同)即可

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.5.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>spring-ai</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-ai</name><description>Demo project for Spring AI</description><properties><java.version>24</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-zhipuai</artifactId><version>1.0.0</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

然后是application.properties,仅需配置大语言模型对应的api-key和model即可,your key为在对应大模型网站申请的key

spring.ai.zhipuai.api-key=<your key>
spring.ai.zhipuai.chat.options.model=glm-4-air

然后是启动类SpringAiApplication

package com.example.spring_ai;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class SpringAiApplication {public static void main(String[] args) {SpringApplication.run(SpringAiApplication.class, args);}}

最后是大语言模型调用类SpringAiExample01

package com.example.spring_ai.controller;import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.Map;@RestController
public class SpringAiExample01
{private final ZhiPuAiChatModel chatModel;@Autowiredpublic SpringAiExample01(ZhiPuAiChatModel chatModel){this.chatModel = chatModel;}/*** 简单调用* @param message* @return*/@GetMapping("/ai/generate")public Map generate(@RequestParam(value = "message", defaultValue = "给我讲个笑话") String message){return Map.of("generation", this.chatModel.call(message));}}

spring会根据我们配置在application.properties中的属性帮我们自动生成ZhiPuAiChatModel

然后我们将程序启动,在浏览器中访问http://localhost:8080/ai/generate​​​​​​?message=介绍下成都​​​​​​,即可观察到大模型返回的结果

这里我使用的智谱的ZhipuAiChatModel,生产中更推荐封装了大语言模型的ChatClient

package com.example.spring_ai.controller;import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class SpringAiExample02ChatClient
{private final ChatClient chatClient;public SpringAiExample02ChatClient(ChatClient.Builder chatClientBuilder){//ChatClient封装了ChatModel,屏蔽了不同底层模型的差异this.chatClient = chatClientBuilder.build();}@GetMapping("/ai")String generation(String userInput){return this.chatClient.prompt().user(userInput).call().content();}}

ChatClient会自动匹配可用的ChatModel,它封装了ChatModel,屏蔽了不同底层模型的差异,方便一键切换底层大模型

http://www.dtcms.com/wzjs/134277.html

相关文章:

  • 山东济宁做网站的公司有哪些网站推广的基本方法有哪些
  • 汕头企业网站建设公司百度电话查询
  • 网站建设的架构百度学术官网登录入口
  • 自适应型网站建设服务电话seo网站优化工具
  • 动态网站成品百度指数app下载
  • dedecms模板 中医院网站全套模板网站引流推广软件
  • 南京营销型网站建设合肥做网站的公司有哪些
  • 天津网站建设制作免费入驻的电商平台
  • 郑州专业做网站企业徐州网站设计
  • 做网站放博彩广告腾讯企点是干嘛的
  • 大型网站快速排名百度seo搜索引擎优化厂家
  • 旅游政务网站建设方案seo的基本步骤是什么
  • 企业网站不备案会怎么样软文模板
  • 网上做论文的网站有哪些一键优化表格
  • 网站设计协议app推广拉新接单平台
  • 安徽池州做网站的公司长沙seo优化公司
  • 重庆网站建设设计江苏seo平台
  • 做网站就上房山华网天下传统营销和网络营销的区别
  • 做团建活动网站百度文库个人登录
  • dw做网站背景图片设置铺平热词搜索排行榜
  • 找做课件的网站小熊猫seo博客
  • 网站推广专家兰州seo推广
  • 个人做网站创业长沙seo外包
  • 广告网站设计公司 作用国内十大软件培训机构
  • 长春网站建设网站网络营销策划与创意
  • 网站技术方案说明淘宝的关键词排名怎么查
  • 网站域名注册流程商务软文写作300字
  • 跟甜蜜定制一样的app刷排名seo
  • 宿迁手机网站开发公司电话企业文化设计
  • wordpress网站搜不到什么是网络整合营销