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

国外好看的网站设计关键词优化百家号

国外好看的网站设计,关键词优化百家号,seo图片优化的方法,电子商务网使用 Spring AI 与 DeepSeek 创建智能 AI 应用 随着人工智能技术的飞速发展,AI 已经成为现代软件应用中不可或缺的一部分。从智能对话系统到内容生成工具,AI 的应用场景日益丰富。Spring AI 是 Spring 官方推出的用于简化 AI 集成的框架,而 …

使用 Spring AI 与 DeepSeek 创建智能 AI 应用

随着人工智能技术的飞速发展,AI 已经成为现代软件应用中不可或缺的一部分。从智能对话系统到内容生成工具,AI 的应用场景日益丰富。Spring AI 是 Spring 官方推出的用于简化 AI 集成的框架,而 DeepSeek 是一个强大的 AI 平台,提供了高效、灵活的语言模型和 API 接口。通过将 Spring AI 与 DeepSeek 结合,开发者可以在 Spring Boot 应用中快速实现智能对话、文本生成等 AI 功能。

在本教程中,我们将详细介绍如何使用 Spring Boot 3.2.x、Spring AI 和 DeepSeek 创建一个智能 AI 应用。

一、环境准备

以下是实验环境的配置:

  • JDK 17.0.14
  • Spring Boot 3.2.0
  • IntelliJ IDEA 2022.2.5
  • Maven 3.8.1

Spring AI Starter 的版本要求

spring-ai-openai-spring-boot-starter 对 JDK 和 Spring Boot 的版本有以下要求:

  • JDK 要求
    • 最低要求:JDK 17。
    • 推荐版本:JDK 17 或更高版本。
  • Spring Boot 要求
    • 支持的版本范围:Spring Boot 3.2.x 和 3.3.x。
    • 最低版本:Spring Boot 3.2。

二、创建项目

使用 Spring Initializr 创建项目

  1. 访问 Spring Initializr:https://start.spring.io/
  2. 选择项目配置
    • Project:Maven
    • Language:Java
    • Spring Boot Version:3.2.0
    • Dependencies
      • Spring Web
      • Spring AI OpenAI Starter
      • Lombok
      • Spring Boot DevTools(可选,用于开发时的热部署)
  3. 生成项目:点击“Generate”按钮下载项目压缩包,并解压到本地。

也可以在idea里调用,然后生成项目
在这里插入图片描述
选择需要的依赖
在这里插入图片描述

Maven 配置文件

以下是生成的 pom.xml 文件内容:

<?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.2.0</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.example</groupId><artifactId>springboot-ai-demo</artifactId><version>0.0.1-SNAPSHOT</version><name>springboot-ai-demo</name><description>Demo project for Spring Boot</description><properties><java.version>17</java.version><spring-ai.version>1.0.0-M5</spring-ai.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-openai-spring-boot-starter</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>${spring-ai.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><annotationProcessorPaths><path><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></path></annotationProcessorPaths></configuration></plugin><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration></plugin></plugins></build>
</project>

三、选择 AI 模型

访问 SiliconFlow 模型列表,选择一个免费的 AI 模型。我们选择 DeepSeek 提供的 DeepSeek-R1-Distill-Llama-8B 模型。
在这里插入图片描述

获取 API 密钥

  1. 登录到 SiliconFlow 平台。
  2. 在平台中创建一个 API 密钥。
  3. 将密钥保存到本地,用于后续配置。
    在这里插入图片描述

配置文件

在项目根目录下创建 application.yml 文件,并添加以下配置内容:

spring:ai:openai:api-key: your-key  # 替换为你的 API 密钥base-url: https://api.siliconflow.cn  # DeepSeek API 地址chat:options:model: deepseek-ai/DeepSeek-R1-Distill-Llama-8B  # 选择的模型

四、编写测试类

创建 ChatController

com.example.ai.controller 包下创建一个名为 ChatController 的类,用于处理用户请求并调用 DeepSeek 模型。

package com.example.ai.controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;@RestController
@CrossOrigin(origins = "*")
@Slf4j
public class ChatController {private final ChatClient chatClient;public ChatController(ChatClient.Builder builder) {this.chatClient = builder.defaultSystem("你是一个AI智能应用").build();}@GetMapping(value = "/chat/{message}")public String chat(@PathVariable("message") String message) {return chatClient.prompt().user(message).call().content();}
}

测试接口

启动 Spring Boot 应用,并通过以下命令调用接口:

curl http://127.0.0.1:8080/chat/今天上海天气咋样

返回结果示例:

根据当前的天气数据,**今天上海的天气**大致为高温天气,温度范围在**19℃至25℃**之间,多云,偶尔有小阵雨,风力较小,东南风1级。建议根据天气情况适时调整出行穿着,注意防晒和保暖。

总结

通过以上步骤,我们成功地使用 Spring Boot 3.2.x、Spring AI 和 DeepSeek 创建了一个简单的智能对话应用。你可以根据需求进一步扩展功能,例如支持多语言、优化对话逻辑或集成到前端页面中。

如果你在实现过程中遇到任何问题,欢迎在评论区留言讨论。

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

相关文章:

  • 网站转化怎么做重庆高端网站seo
  • 惠州企业网站设计如何统计网站访问量
  • 做外贸网站公司哪家好大连做优化网站哪家好
  • 百度推广是给做网站吗seo网站优化报价
  • 无聊网站建设沈阳网站建设制作公司
  • 家政网站模板下载企业宣传册
  • 豆芽网站建设百度账号怎么注册
  • 宜昌建网站厦门seo排名优化
  • 中国供应网关键词优化seo费用
  • 搜索引擎优化的主要内容竞价关键词优化软件
  • 建立b2c网站网络营销有哪些手段
  • 如何做网站的页面唐山seo优化
  • 网站建设需要租赁服务器吗佛山做优化的公司
  • 免费b2b平台推广都有哪些长沙优化官网服务
  • 做软装平台网站优化营商环境心得体会2023
  • 网站建设 上海浦东东营百度推广公司
  • 企业产品网站模板页面设计
  • 现在网站后台有哪几种模板形式关键词代发包收录
  • 网站建设和网络优化网络培训机构排名前十
  • 我想创业做网站淘宝的前100个关键词排名
  • 定制型网站app推广方案策划
  • 注册网站时应注意什么百度极速版下载
  • 做门户网站私活多少钱2024免费网站推广大全
  • 做视频网站要多大的主机网站seo优化建议
  • 网站结构优化包括哪些网络营销的专业知识
  • 邯郸市网站建设多少钱沈阳cms建站模板
  • 做团购的网站有哪些百度地图推广怎么收费标准
  • 哪些网站需要备案推广引流吸引人的标题
  • dedecms医院网站wap模板(橙色)前端培训
  • 做网站接单渠道新站如何让百度快速收录