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

wordpress能建立大型站吗网络营销导向网站建设的基础

wordpress能建立大型站吗,网络营销导向网站建设的基础,湖北建设网官方网站,餐饮网站建设的模板SpringAI MCPServer MCPClient 快速入门编写大纲 源代码地址:https://download.csdn.net/download/user_admin_god/90926893 1. 介绍 本文通过使用免费的智普AI的glm-4-flash模型,设计并实现了一个智能问答系统。在该系统中,我们编写了一…

SpringAI + MCPServer + MCPClient 快速入门编写大纲

源代码地址:https://download.csdn.net/download/user_admin_god/90926893

1. 介绍

本文通过使用免费的智普AI的glm-4-flash模型,设计并实现了一个智能问答系统。在该系统中,我们编写了一个工具接口,专门处理那些大模型无法解答的复杂问题,并将其集成到MCPServer中。MCPClient的Web端接口能够智能地判断何时使用智普AI的glm-4-flash模型,何时调用MCPServer的工具接口,从而确保在大模型无法处理的情况下,系统通过MCP实现高效的协调与问题解决。这一方案不仅提升了AI问答的能力,还能更灵活地应对多样化的用户需求。

1.1 目标

本文的主要目标是帮助开发者了解如何结合 SpringAIMCPServerMCPClient 来创建一个高效的分布式应用程序。通过这个快速入门指南,开发者将能够:

  • 迅速掌握这些组件的基本用法及如何将它们集成到实际项目中;
  • 理解各个模块之间的架构设计和通信流程;
  • 学习如何通过SpringAI 提供的人工智能服务来增强应用功能;
  • 轻松实现一个客户端-服务器模型,并使用 SpringAI 实现智能化服务。
1.2 技术栈概述
(一)SpringAI

SpringAI 是一个基于 Spring 框架的人工智能服务构建工具,旨在帮助开发者通过简单的配置和接口集成AI功能。无论是自然语言处理、图像识别还是其他类型的智能服务,SpringAI 都提供了一套简洁的API接口,支持与流行的AI平台(如OpenAI)无缝对接。开发者可以通过它轻松实现复杂的AI任务。

SpringAI特点:

AI 模型集成与管理
Spring AI 提供对多种 AI 模型的支持,包括聊天模型、文本生成、图像生成、语音识别与合成等,支持同步和流式 API 选项。
统一的 API 接口
框架提供跨 AI 提供商的可移植 API,支持 OpenAI、Anthropic、Google、Microsoft、ZhiPu等主流平台,简化了不同模型间的切换和集成。
向量数据库支持
Spring AI 支持多种向量数据库,如 Chroma、Milvus、PostgreSQL/PGVector、Redis、Weaviate 等,提供类似 SQL 的元数据过滤 API,方便进行高效的相似性搜索和数据存储。
函数调用与工具集成
框架支持模型调用外部函数和工具,允许模型在推理过程中访问实时数据或执行特定操作,增强了模型的实用性和灵活性。
结构化输出与 POJO 映射
Spring AI 支持将 AI 模型的输出映射到 Java POJO(Plain Old Java Object),实现结构化数据处理,方便与其他系统的集成。
提示词模板与检索增强生成(RAG)
框架提供提示词模板功能,支持检索增强生成(RAG)策略,将外部知识库与 AI 模型结合,提高生成内容的准确性和相关性。
自动配置与 Spring Boot 集成
Spring AI 与 Spring Boot 无缝集成,支持自动配置和启动器,使得 AI 功能的集成过程更加简便和高效。

(二)MCPServer

MCPServer 是一个提供具体功能的服务端程序,类似于一个工具箱,里面包含了各种工具,例如文件读写、数据库查询、API 调用等。这些工具能够使大型语言模型(LLMs)以标准化的方式访问外部服务或数据源。

主要职责:

  1. 提供工具:Server 定义并实现具体的工具(Tool),这些工具构成了 MCP 的核心功能。例如,它可以是天气查询接口、数学运算功能、数据分析工具等。
  2. 处理请求:当 MCP Client 发送请求时,Server 负责解析请求内容,并根据需求执行相应的操作。
  3. 返回结果:完成操作后,Server 将处理结果返回给 Client。这可能包括从数据库获取信息、调用第三方 API,或进行其他数据处理任务。
(三)MCPClient

MCPClient 如同大型语言模型(LLM)的遥控器,负责向 Server 发送指令并接收结果。它的角色是将自然语言指令翻译成 Server 能理解的请求格式。

主要职责:

  1. 构建请求:Client 根据用户输入或 LLM 的需求,构建符合 MCP 协议的请求。它需要理解用户的意图,并将其转化为 Server 可执行的具体命令。
  2. 与 Server 通信:一旦构建好请求,Client 会通过网络与 Server 建立连接并发送请求。通常,这一过程遵循 JSON-RPC 2.0 规范,以确保通信的标准化和一致性。
  3. 接收响应:在接收到 Server 的响应后,Client 负责解读这些信息,并将有用的结果反馈给用户或 LLM。
2. 环境准备
  • 3.1 软件要求

    • JDK 21+:建议使用 JDK 21 或更高版本,可以通过华为云镜像下载链接获取。
    • Spring Boot 3:推荐使用 Spring Boot 3.4.5 版本。Spring Boot 是一个非常流行的框架,能够简化 Java 后端应用的构建过程,自动配置和快速开发。
    • Maven 3.9.2:Maven 是一种强大的构建和项目管理工具,用于依赖管理、构建配置及项目生命周期管理。建议使用 Maven 3.9.2 版本。
    • IntelliJ IDEA 2024.3:这款IDE是目前最受开发者青睐的Java开发工具之一,具备强大的代码编辑与调试功能,能够极大地提高开发效率。
    • MySQL 8.0+:MySQL 是一个开源的关系型数据库管理系统,8.0 版本具有更高的性能和更强的特性支持。
    • Mybatis-Plus 3.5.12:这是 Mybatis 的增强工具,能够简化数据库操作,并提高代码的可维护性。3.5.12 版本是本项目所推荐的版本。
  • 3.2 安装步骤

    1. 安装 Java 开发环境
    • 首先,下载并安装 JDK 21+,确保系统的环境变量已经配置好,例如 JAVA_HOMEPATH,这样 Java 可以在命令行中直接调用。

    • 安装完成后,通过执行以下命令验证是否成功安装:

    java -version
    

    输出应该显示 JDK 的版本信息。

    1. 配置 Spring Boot 项目
    • 使用IntelliJ IDEA打开或创建一个新的 Spring Boot 项目。可以通过以下步骤快速创建 Spring Boot 项目:

      • 打开 IntelliJ IDEA,选择 File -> New Project
    • 在项目类型中选择 Spring Initializr,并根据项目需求配置相关的参数。

    • 完成项目初始化后,选择正确的 Spring Boot 版本(3.4.5 推荐版本)。

    1. 添加必要的依赖项

    pom.xml 文件中添加项目所需的依赖项,主要包括:

    • spring-boot-starter-web:提供构建 Web 应用的基础功能,支持 RESTful 风格的 Web 服务。
    • spring-retry:用于支持自动重试机制,可以帮助应用在失败时进行重试,确保应用的高可用性。
    • spring-cloud:提供 Spring Cloud 的相关组件,适合微服务架构的开发。
3. 项目创建结构
两个模块  mcp-client  和 mcp-server
├─mcp-client
│  ├─src
│  │  └─main
│  │      ├─java
│  │      │  └─com
│  │      │      └─gt
│  │      │          └─demo
│  │      │              └─mcpclient
│  │      │                  ├─ai
│  │      │                  ├─controller
│  │      │                  ├─domain
│  │      │                  ├─mapper
│  │      │                  ├─service
│  │      │                  │  └─impl
│  │      │                  └─utils
│  │      └─resources
└─mcp-server├─src│  └─main│      ├─java│      │  └─com│      │      └─gt│      │          └─demo│      │              └─mcpserver│      │                  ├─ai│      │                  ├─controller│      │                  ├─domain│      │                  ├─mapper│      │                  ├─proxy│      │                  ├─service│      │                  │  └─impl│      │                  └─utils│      └─resources
4. 工程核心代码
  • 4.1 MCPServer Pom依赖
        <properties><java.version>21</java.version><maven.compiler.source>21</maven.compiler.source><maven.compiler.target>21</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool-all.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-server-webmvc</artifactId><version>${spring-ai.version}</version></dependency><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>${mysql.version}</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>${mybatis-plus.version}</version></dependency></dependencies>```- 4.2 **MCPServer Properties配置**```properties# 服务名称spring.application.name=mcp-server# 服务运行使用端口server.port=8081# MySQL数据库配置spring.datasource.url=jdbc:mysql://localhost:3306/test_admin_123?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=truespring.datasource.driverClassName=com.mysql.cj.jdbc.Driverspring.datasource.username=guotongspring.datasource.password=123456spring.datasource.hikari.maximum-pool-size=5# MyBatis# mapper.xml 位置mybatis-plus.mapper-locations=classpath:mapper/*.xml# 实体类位置mybatis-plus.type-aliases-package=com.example.entity# mybatis-plus的sql日志mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl# 下划线转驼峰自动mybatis-plus.configuration.map-underscore-to-camel-case=true# 逻辑删除mybatis-plus.global-config.db-config.logic-not-delete-value=0mybatis-plus.global-config.db-config.logic-delete-field=isDelmybatis-plus.global-config.db-config.logic-delete-value=2-# thymeleaf 模板引擎-# 禁用缓存-开发的时候spring.thymeleaf.cache=false# sspring.thymeleaf.encoding=utf-8sys.conf.file.path=D:/confwindow.dev.file.path=D:/csp# mcp服务配置spring.ai.mcp.server.name=mcp-serverspring.ai.mcp.server.version=1.0.0spring.ai.mcp.server.description=AI服务spring.ai.mcp.server.type=asyncspring.ai.mcp.server.sse-message-endpoint=/mcp/messages```- 4.3 **MCPServer 模型工具接口**
```java@Component@Slf4jpublic class McpToolService {@Resourceprivate SysUserMapper sysUserMapper;@Tool(description = "根据传入用户名称获取AiGodLike系统用户信息接口")public String getAiGodLikeUserInfoByName(@ToolParam(description = "隔壁老郭系统的用户名称(mack,jay,hans)") String userName) {log.info("隔壁老郭系统用户名称:{}", userName);List<SysUser> sysUserList = sysUserMapper.selectList(Wrappers.lambdaQuery(SysUser.class).like(SysUser::getUserName, userName));log.info("隔壁老郭系统用户信息:{}", sysUserList);return "隔壁老郭系统用户-王八蛋" + sysUserList;}}
  • 4.4MCPServer 注册工具接口
    /*** @author makejava*/@SpringBootApplication@MapperScan("com.gt.demo.mcpserver.mapper")public class McpServerApplication {public static void main(String[] args) {SpringApplication.run(McpServerApplication.class, args);}@Beanpublic ToolCallbackProvider aiGodLikeUserInfoByNameTools(McpToolService mcpToolService) {return MethodToolCallbackProvider.builder().toolObjects(mcpToolService).build();}}```- 4.5 **MCPClient Pom配置**```xml<dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><!--糊涂万能工具箱--><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool-all.version}</version></dependency><!--流式响应式--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-client-webflux</artifactId><version>${spring-ai.version}</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--MCP客户端--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-mcp-client</artifactId><version>${spring-ai.version}</version></dependency><!--智普AI--><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-zhipuai</artifactId><version>${spring-ai.version}</version></dependency><!--Mysql数据库--><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>${mysql.version}</version></dependency><!--lombok--><!----><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework.retry/spring-retry --><dependency><groupId>org.springframework.retry</groupId><artifactId>spring-retry</artifactId><version>2.0.12</version></dependency><!--mybatis-plus--><!----><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-spring-boot3-starter</artifactId><version>${mybatis-plus.version}</version></dependency></dependencies>
  • 4.5 MCPClient application.properties
# 服务名称
spring.application.name=mcp-client# 服务运行使用端口
server.port=8082# MySQL数据库配置
spring.datasource.url=jdbc:mysql://localhost:3306/test_admin_123?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.username=guotong
spring.datasource.password=123456
spring.datasource.hikari.maximum-pool-size=5# MyBatis# mapper.xml 位置
mybatis-plus.mapper-locations=classpath:mapper/*.xml
# 实体类位置
mybatis-plus.type-aliases-package=com.example.entity
# mybatis-plus的sql日志
mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.slf4j.Slf4jImpl
# 下划线转驼峰自动
mybatis-plus.configuration.map-underscore-to-camel-case=true
# 逻辑删除
mybatis-plus.global-config.db-config.logic-not-delete-value=0
mybatis-plus.global-config.db-config.logic-delete-field=isDel
mybatis-plus.global-config.db-config.logic-delete-value=2# thymeleaf 模板引擎
# 禁用缓存-开发的时候
spring.thymeleaf.cache=false
# s
spring.thymeleaf.encoding=utf-8
sys.conf.file.path=D:/conf
window.dev.file.path=D:/cspspring.ai.mcp.client.enabled=true
spring.ai.mcp.client.name=my-mcp-client
spring.ai.mcp.client.version=1.0.0
spring.ai.mcp.client.request-timeout=30s
spring.ai.mcp.client.type=SYNC
spring.ai.mcp.client.sse.connections.server1.url=http://localhost:8081spring.ai.zhipuai.api-key=0baf0413c6c0c6b0d011ae8489a2c9c0.ejfhVbF6Z653Cy1I
spring.ai.zhipuai.base-url=https://open.bigmodel.cn/api/paas
spring.ai.zhipuai.embedding.options.model=glm-4-flash
spring.ai.zhipuai.chat.options.model=glm-4-flash
spring.ai.zhipuai.chat.options.temperature=0.7
  • 4.5 MCPClient 调用AI模型问答
         /*** AI---式调用问答*/@RequestMapping(value = "/jsonToSay", method = RequestMethod.GET)public String jsonToSay(@RequestParam String question) {var chatClient = chatClientBuilder.defaultTools(toolCallbackProvider).build();System.out.println("=== 聊天模式已启动(=====");// 调用 AI 并打印回复String content = chatClient.prompt(question).call().content();System.out.println("\n>>> AI 回复: " + content);return content;}
5. 运行与测试
  • 5.1 启动Spring Boot应用
    • 运行MCPServer和MCPClient应用程序。
      在这里插入图片描述关键会打印:MCPClient 注册到MCPServer上了

2025-05-28T14:41:46.290+08:00 INFO 1828 — [mcp-server] [nio-8081-exec-5] i.m.server.McpAsyncServer : Client initialize request - Protocol: 2024-11-05, Capabilities: ClientCapabilities[experimental=null, roots=null, sampling=null], Info: Implementation[name=my-mcp-client - server1, version=1.0.0]

  • 5.2 测试API调用
    • 使用Postman或类似工具向MCPClient发送请求,验证服务器和AI服务是否正常工作。
    • 问一个不会协调去掉MCPServer工具的问题,全都是走大模型完成回答在这里插入图片描述
    • 问一个大模型完成回答不了的,满足MCPServer工具的语义的问题,走MCPServer工具
    • 在这里插入图片描述

NICE JAVA的 MCP+AI全线路打通


文章转载自:

http://KLgV4fOD.rnfwx.cn
http://ZOKuXXdC.rnfwx.cn
http://jD5Vk4WK.rnfwx.cn
http://2511vQpx.rnfwx.cn
http://wT880iGe.rnfwx.cn
http://QURnOBGT.rnfwx.cn
http://cUW3S13U.rnfwx.cn
http://mhiGw1Wu.rnfwx.cn
http://QF9H777Y.rnfwx.cn
http://wQdi8mgl.rnfwx.cn
http://8oewOOZp.rnfwx.cn
http://Oa6ngzWo.rnfwx.cn
http://h93X1n5h.rnfwx.cn
http://3yZ0OxSI.rnfwx.cn
http://BaQDlVAk.rnfwx.cn
http://0rcd4RAu.rnfwx.cn
http://aswfbe0h.rnfwx.cn
http://HW9Xl4Vu.rnfwx.cn
http://49RJwMaW.rnfwx.cn
http://dV4DGGKf.rnfwx.cn
http://o65BTH74.rnfwx.cn
http://wRY5FHSy.rnfwx.cn
http://o1b8PswV.rnfwx.cn
http://MzIzkVsh.rnfwx.cn
http://YpCXy09E.rnfwx.cn
http://eqiRWZQS.rnfwx.cn
http://LqE4b3RV.rnfwx.cn
http://22EopgE8.rnfwx.cn
http://CX4TvT3k.rnfwx.cn
http://XgQmJVep.rnfwx.cn
http://www.dtcms.com/wzjs/755634.html

相关文章:

  • 深圳手机医疗网站建设蒲城做网站
  • 兰山网站建设婚恋网站建设
  • 南京做网站的公司网站建设丶金手指花总13
  • 长沙建网站要多少钱建筑行业网
  • 上海市城市建设管理局网站做设计参考的网站
  • 西部数码网站管理控制面板直通车关键词怎么优化
  • 企业网站做留言板有什么优势南充网站建设略奥
  • 响应式网站开发网络营销整合营销
  • 领优惠券的网站怎么做电商设计和ui设计哪个前景比较好
  • 便利的聊城网站建设中山网站制作套餐
  • 下载安装百度地图导航湛江百度seo公司
  • 全新正版营销网站如何用网站做cpa
  • 怎么样做深网的网站山东诚祥建设集团公司网站
  • 做美食有哪些网站零基础学建网站
  • 网站建设需要的东西建邺html5响应式网站
  • 网站建设工资怎么样合肥企业网站建设专家
  • 网站建设维护公司地址永定路网站建设
  • 织梦网站采集如何做济南腾飞网络科技有限公司
  • 手机网站打开微信登录wordpress无法发送
  • 公司网站改版方案管理咨询公司服务口碑好
  • 百度网站名称网页与网站设计说明
  • 自己建网站做代理商顺德微信网站建设
  • 二级网站怎么建做网站服务器系统
  • 英文公司网站建设上海人才网
  • 导航网站前端模板延吉做网站
  • 烟台网站建设找企汇互联专业广告网站留电话
  • 给别人做网站挣钱么wordpress友情链接图像地址
  • seo关键词排名优化要多少钱seo排名规则
  • 网站定制开发怎么写免费做ppt的网站有哪些
  • 凡科免费网站能用吗网站建设前期准备方案