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

宝鸡网站制作英文seo是什么意思

宝鸡网站制作,英文seo是什么意思,邢台口碑好的网站建设,许昌市建设投资有限公司 网站原文链接:(增强)基于sqlite、mysql、redis的消息存储 教程说明 说明:本教程将采用2025年5月20日正式的GA版,给出如下内容 核心功能模块的快速上手教程核心功能模块的源码级解读Spring ai alibaba增强的快速上手教程…

原文链接:(增强)基于sqlite、mysql、redis的消息存储

教程说明

说明:本教程将采用2025年5月20日正式的GA版,给出如下内容

  1. 核心功能模块的快速上手教程
  2. 核心功能模块的源码级解读
  3. Spring ai alibaba增强的快速上手教程 + 源码级解读

版本:JDK21 + SpringBoot3.4.5 + SpringAI 1.0.0 + SpringAI Alibaba最新

将陆续完成如下章节教程。本章是第二章(advisor)快速上手—sqlite、mysql、redis消息存储

代码开源如下:https://github.com/GTyingzi/spring-ai-tutorial

(增强)基于 sqlite、mysql、redis 的消息存储

[!TIP]
实现了基于 sqlite、mysql、redis 的消息存储

实战代码可见:https://github.com/GTyingzi/spring-ai-tutorial 下的 advisor/advisor-memory-sqlite、advisor-memory-mysql、advisor-memory-redis

代码已贡献至:https://github.com/springaialibaba/spring-ai-alibaba-examples/pull/238

pom 文件

<properties><sqlite.verson>3.49.1.0</sqlite.verson><mysql.version>8.0.32</mysql.version><jedis.version>5.2.0</jedis.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-autoconfigure-model-openai</artifactId></dependency><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-autoconfigure-model-chat-client</artifactId></dependency><dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter-memory</artifactId></dependency><dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter-memory-jdbc</artifactId></dependency><dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter-memory-redis</artifactId></dependency><dependency><groupId>org.xerial</groupId><artifactId>sqlite-jdbc</artifactId><version>${sqlite.verson}</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>${mysql.version}</version></dependency><dependency><groupId>redis.clients</groupId><artifactId>jedis</artifactId><version>${jedis.version}</version></dependency></dependencies>

application.yml

server:port: 8080spring:application:name: advisor-memory-mysqlai:openai:api-key: ${DASHSCOPE_API_KEY}base-url: https://dashscope.aliyuncs.com/compatible-modechat:options:model: qwen-maxchat:memory:repository:jdbc:mysql:jdbc-url: jdbc:mysql://localhost:3306/spring_ai_alibaba_mysql?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true&tinyInt1isBit=false&allowLoadLocalInfile=true&allowLocalInfile=true&allowUrlusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driverenabled: truememory:redis:host: localhostport: 6379timeout:  5000password:

Sqllite

SqliteMemoryConfig
package com.spring.ai.tutorial.advisor.memory.config;import com.alibaba.cloud.ai.memory.jdbc.SQLiteChatMemoryRepository;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;@Configuration
public class SqliteMemoryConfig {@Beanpublic SQLiteChatMemoryRepository sqliteChatMemoryRepository() {DriverManagerDataSource dataSource = new DriverManagerDataSource();dataSource.setDriverClassName("org.sqlite.JDBC");dataSource.setUrl("jdbc:sqlite:advisor/advisor-memory-sqlite/src/main/resources/chat-memory.db");JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);return SQLiteChatMemoryRepository._sqliteBuilder_().jdbcTemplate(jdbcTemplate).build();}
}
SqliteMemoryController
package com.spring.ai.tutorial.advisor.memory.controller;import com.alibaba.cloud.ai.memory.jdbc.SQLiteChatMemoryRepository;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.List;import static org.springframework.ai.chat.memory.ChatMemory._CONVERSATION_ID_;@RestController
@RequestMapping("/advisor/memory/sqlite")
public class SqliteMemoryController {private final ChatClient chatClient;private final int MAX_MESSAGES = 100;private final MessageWindowChatMemory messageWindowChatMemory;public SqliteMemoryController(ChatClient.Builder builder, SQLiteChatMemoryRepository sqliteChatMemoryRepository) {this.messageWindowChatMemory = MessageWindowChatMemory._builder_().chatMemoryRepository(sqliteChatMemoryRepository).maxMessages(MAX_MESSAGES).build();this.chatClient = builder.defaultAdvisors(MessageChatMemoryAdvisor._builder_(messageWindowChatMemory).build()).build();}@GetMapping("/call")public String call(@RequestParam(value = "query", defaultValue = "你好,我的外号是影子,请记住呀") String query,@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return chatClient.prompt(query).advisors(a -> a.param(_CONVERSATION_ID_, conversationId)).call().content();}@GetMapping("/messages")public List<Message> messages(@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return messageWindowChatMemory.get(conversationId);}
}
效果

以会话“yingzi”发送消息,此时消息存储至 sqllite

从 sqllite 获取会话“yingzi”对应的消息

Mysql

MysqlMemoryConfig
package com.spring.ai.tutorial.advisor.memory.config;import com.alibaba.cloud.ai.memory.jdbc.MysqlChatMemoryRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;@Configuration
public class MysqlMemoryConfig {@Value("${spring.ai.chat.memory.repository.jdbc.mysql.jdbc-url}")private String mysqlJdbcUrl;@Value("${spring.ai.chat.memory.repository.jdbc.mysql.username}")private String mysqlUsername;@Value("${spring.ai.chat.memory.repository.jdbc.mysql.password}")private String mysqlPassword;@Value("${spring.ai.chat.memory.repository.jdbc.mysql.driver-class-name}")private String mysqlDriverClassName;@Beanpublic MysqlChatMemoryRepository mysqlChatMemoryRepository() {DriverManagerDataSource dataSource = new DriverManagerDataSource();dataSource.setDriverClassName(mysqlDriverClassName);dataSource.setUrl(mysqlJdbcUrl);dataSource.setUsername(mysqlUsername);dataSource.setPassword(mysqlPassword);JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);return MysqlChatMemoryRepository._mysqlBuilder_().jdbcTemplate(jdbcTemplate).build();}
}
MysqlMemoryController
package com.spring.ai.tutorial.advisor.memory.controller;import com.alibaba.cloud.ai.memory.jdbc.MysqlChatMemoryRepository;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.List;import static org.springframework.ai.chat.memory.ChatMemory._CONVERSATION_ID_;@RestController
@RequestMapping("/advisor/memory/mysql")
public class MysqlMemoryController {private final ChatClient chatClient;private final int MAX_MESSAGES = 100;private final MessageWindowChatMemory messageWindowChatMemory;public MysqlMemoryController(ChatClient.Builder builder, MysqlChatMemoryRepository mysqlChatMemoryRepository) {this.messageWindowChatMemory = MessageWindowChatMemory._builder_().chatMemoryRepository(mysqlChatMemoryRepository).maxMessages(MAX_MESSAGES).build();this.chatClient = builder.defaultAdvisors(MessageChatMemoryAdvisor._builder_(messageWindowChatMemory).build()).build();}@GetMapping("/call")public String call(@RequestParam(value = "query", defaultValue = "你好,我的外号是影子,请记住呀") String query,@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return chatClient.prompt(query).advisors(a -> a.param(_CONVERSATION_ID_, conversationId)).call().content();}@GetMapping("/messages")public List<Message> messages(@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return messageWindowChatMemory.get(conversationId);}
}
效果

以会话“yingzi”发送消息,此时消息存储至 mysql

消息被存储至 mysql 中

从 mysql 获取会话“yingzi”对应的消息

Redis

RedisMemoryConfig
package com.spring.ai.tutorial.advisor.memory.config;import com.alibaba.cloud.ai.memory.redis.RedisChatMemoryRepository;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class RedisMemoryConfig {@Value("${spring.ai.memory.redis.host}")private String redisHost;@Value("${spring.ai.memory.redis.port}")private int redisPort;@Value("${spring.ai.memory.redis.password}")private String redisPassword;@Value("${spring.ai.memory.redis.timeout}")private int redisTimeout;@Beanpublic RedisChatMemoryRepository redisChatMemoryRepository() {return RedisChatMemoryRepository._builder_().host(redisHost).port(redisPort)// 若没有设置密码则注释该项
//           .password(redisPassword).timeout(redisTimeout).build();}
}
RedisMemoryController
package com.spring.ai.tutorial.advisor.memory.controller;import com.alibaba.cloud.ai.memory.redis.RedisChatMemoryRepository;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.List;import static org.springframework.ai.chat.memory.ChatMemory._CONVERSATION_ID_;@RestController
@RequestMapping("/advisor/memory/redis")
public class RedisMemoryController {private final ChatClient chatClient;private final int MAX_MESSAGES = 100;private final MessageWindowChatMemory messageWindowChatMemory;public RedisMemoryController(ChatClient.Builder builder, RedisChatMemoryRepository redisChatMemoryRepository) {this.messageWindowChatMemory = MessageWindowChatMemory._builder_().chatMemoryRepository(redisChatMemoryRepository).maxMessages(MAX_MESSAGES).build();this.chatClient = builder.defaultAdvisors(MessageChatMemoryAdvisor._builder_(messageWindowChatMemory).build()).build();}@GetMapping("/call")public String call(@RequestParam(value = "query", defaultValue = "你好,我的外号是影子,请记住呀") String query,@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return chatClient.prompt(query).advisors(a -> a.param(_CONVERSATION_ID_, conversationId)).call().content();}@GetMapping("/messages")public List<Message> messages(@RequestParam(value = "conversation_id", defaultValue = "yingzi") String conversationId) {return messageWindowChatMemory.get(conversationId);}
}
效果

以会话“yingzi”发送消息,此时消息存储至 redis

消息被存储至 redis 中

从 redis 获取会话“yingzi”对应的消息

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

相关文章:

  • 景县有专业做网站人员吗班级优化大师app
  • 网站建设与管理收获网站怎样被百度收录
  • 商丘手机网站制作北京网站建设东轩seo
  • 深圳专业网站建设公司好吗企业查询软件
  • 婚纱摄影的网站怎么做人力资源培训机构
  • 网站建设一般的费用绍兴seo排名外包
  • 武汉营销型网站建设公司哪家专业温州企业网站排名优化
  • 哪个网站可以做视频外链百度指数查询手机版
  • wordpress用户自定义密码百度seo优化系统
  • 做网站赚钱交税百度投诉电话24小时
  • 网站ip如何做跳转平台做推广的技巧
  • Html5做旅游网站的设计思路模板建站网页
  • 建设银行手机网站关键词挖掘机爱站网
  • wordpress issetseo是一种利用搜索引擎的
  • 成都直销系统网站开发网络服务合同纠纷
  • 手机个人简历模板下载网站模板驻马店百度seo
  • 毕设可以是仿照其他网站做吗百度客服人工
  • 电子商务网站开发流程seo教学
  • 沈阳网站建设syfzkj网站运营与维护
  • 为什么要建设双端网站推广联盟
  • 邯郸做wap网站找谁的网站建设
  • 番禺做网站报价看网站时的关键词
  • 网站开发制做seo工程师
  • .net 电子商务网站源码app香港账号
  • 济南网络策划seo如何提高排名
  • 黑客网站手机版外贸网站建设平台
  • 设计公司网站页面设计国家市场监督管理总局
  • 大品牌设计公司免费推广seo
  • 菏泽科技网站建设网站建设公司大全
  • 南昌哪里做网站比较好公司网站设计需要多少钱