Browse Source

阿里千问 call

tanlie 4 tháng trước cách đây
mục cha
commit
165925b773
30 tập tin đã thay đổi với 229 bổ sung792 xóa
  1. 1 0
      .gitignore
  2. 30 0
      alibaba-ai/pom.xml
  3. 8 4
      alibaba-ai/src/main/java/cn/qinys/ai/AlibabaAiApplication.java
  4. 9 0
      alibaba-ai/src/main/java/cn/qinys/ai/service/ChatService.java
  5. 13 0
      alibaba-ai/src/main/java/cn/qinys/ai/service/impl/ChatServiceImpl.java
  6. 13 0
      alibaba-ai/src/main/resources/application.yaml
  7. 29 0
      alibaba-ai/src/test/java/cn/qinys/ai/service/impl/ChatServiceImplTest.java
  8. 0 8
      chatgpt/chatgpt.iml
  9. 0 106
      chatgpt/pom.xml
  10. 0 38
      chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/MessageController.java
  11. 0 38
      chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/OllamaController.java
  12. 0 33
      chatgpt/src/main/java/cn/qinys/ai/chatgpt/envetlistner/ApplicationStartEventListener.java
  13. 0 17
      chatgpt/src/main/java/cn/qinys/ai/chatgpt/req/MsgReq.java
  14. 0 0
      chatgpt/src/main/resources/META-INF/spring.factories
  15. 0 21
      chatgpt/src/main/resources/application.yml
  16. 0 33
      chatgpt/src/test/java/cn/qinys/ai/chatgpt/controller/MessageControllerTest.java
  17. 0 2
      demo/.gitattributes
  18. 0 33
      demo/.gitignore
  19. 0 103
      demo/pom.xml
  20. 0 13
      demo/src/main/java/com/example/demo/DemoApplication.java
  21. 0 99
      demo/src/main/java/com/example/demo/config/redis/RedisConfig.java
  22. 0 54
      demo/src/main/java/com/example/demo/config/redis/RedisConfigCacheManager.java
  23. 0 25
      demo/src/main/java/com/example/demo/config/redis/RedisKeyEnum.java
  24. 0 31
      demo/src/main/java/com/example/demo/config/redis/RedisSubscribe.java
  25. 0 12
      demo/src/main/resources/application.yml
  26. 0 13
      demo/src/test/java/com/example/demo/DemoApplicationTests.java
  27. 0 109
      demo/src/test/java/com/example/demo/config/redis/RedisConfigTest.java
  28. 20 0
      ollamaai/pom.xml
  29. 20 0
      openai/pom.xml
  30. 86 0
      pom.xml

+ 1 - 0
.gitignore

@@ -1,2 +1,3 @@
 .idea/
 chatgpt/target/
+alibaba-ai/target/

+ 30 - 0
alibaba-ai/pom.xml

@@ -0,0 +1,30 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>cn.qinys.ai</groupId>
+        <artifactId>spring-ai</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>alibaba-ai</artifactId>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.cloud.ai</groupId>
+            <artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>

+ 8 - 4
chatgpt/src/main/java/cn/qinys/ai/ChatApplication.java → alibaba-ai/src/main/java/cn/qinys/ai/AlibabaAiApplication.java

@@ -1,14 +1,18 @@
 package cn.qinys.ai;
 
-
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
+/**
+ * @author lie tan
+ * @description
+ * @date 2025-11-16 16:37
+ **/
 @SpringBootApplication
-public class ChatApplication {
+public class AlibabaAiApplication {
 
     public static void main(String[] args) {
-        SpringApplication.run(ChatApplication.class, args);
-    }
 
+        SpringApplication.run(AlibabaAiApplication.class, args);
+    }
 }

+ 9 - 0
alibaba-ai/src/main/java/cn/qinys/ai/service/ChatService.java

@@ -0,0 +1,9 @@
+package cn.qinys.ai.service;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2025-11-16 16:37
+ **/
+public interface ChatService {
+}

+ 13 - 0
alibaba-ai/src/main/java/cn/qinys/ai/service/impl/ChatServiceImpl.java

@@ -0,0 +1,13 @@
+package cn.qinys.ai.service.impl;
+
+import cn.qinys.ai.service.ChatService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2025-11-16 16:38
+ **/
+@Service
+public class ChatServiceImpl implements ChatService {
+}

+ 13 - 0
alibaba-ai/src/main/resources/application.yaml

@@ -0,0 +1,13 @@
+server:
+  port: 8080
+
+spring:
+  application:
+    name: alibaba-ai
+
+  ai:
+    dashscope:
+      api-key: sk-a52acbfc944e495ead45b1c54b5659fb
+      chat:
+        options:
+          model: qwen-plus

+ 29 - 0
alibaba-ai/src/test/java/cn/qinys/ai/service/impl/ChatServiceImplTest.java

@@ -0,0 +1,29 @@
+package cn.qinys.ai.service.impl;
+
+
+import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
+import jakarta.annotation.Resource;
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2025-11-16 16:38
+ **/
+@SpringBootTest
+class ChatServiceImplTest {
+
+    @Resource
+    DashScopeChatModel chatModel;
+
+
+    @Test
+    void stringCallTest() {
+        String call = chatModel.call("你是谁?");
+        System.out.println(call);
+
+    }
+
+
+}

+ 0 - 8
chatgpt/chatgpt.iml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module version="4">
-  <component name="FacetManager">
-    <facet type="Spring" name="Spring">
-      <configuration />
-    </facet>
-  </component>
-</module>

+ 0 - 106
chatgpt/pom.xml

@@ -1,106 +0,0 @@
-<?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.5</version>
-        <relativePath/> <!-- lookup parent from repository -->
-    </parent>
-    <groupId>cn.qinys.ai</groupId>
-    <artifactId>chatgpt</artifactId>
-    <version>0.0.1</version>
-    <name>chatgpt</name>
-    <description>Demo project for Spring Boot</description>
-    <properties>
-        <java.version>17</java.version>
-        <spring-ai.version>0.8.1</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.springframework.ai</groupId>
-            <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-devtools</artifactId>
-            <scope>runtime</scope>
-            <optional>true</optional>
-        </dependency>
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-test</artifactId>
-            <scope>test</scope>
-        </dependency>
-        <!--fastjson-->
-        <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>fastjson</artifactId>
-            <version>2.0.32</version>
-        </dependency>
-        <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
-        <dependency>
-            <groupId>cn.hutool</groupId>
-            <artifactId>hutool-all</artifactId>
-            <version>5.8.32</version>
-        </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.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-            <plugin>
-                <groupId>io.github.git-commit-id</groupId>
-                <artifactId>git-commit-id-maven-plugin</artifactId>
-                <version>9.0.0</version>
-                <configuration>
-                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
-                    <format>json</format>
-                    <commitIdGenerationMode>full</commitIdGenerationMode>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-    <repositories>
-        <repository>
-            <id>spring-milestones</id>
-            <name>Spring Milestones</name>
-            <url>https://repo.spring.io/milestone</url>
-            <snapshots>
-                <enabled>false</enabled>
-            </snapshots>
-        </repository>
-    </repositories>
-
-</project>

+ 0 - 38
chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/MessageController.java

@@ -1,38 +0,0 @@
-package cn.qinys.ai.chatgpt.controller;
-
-import cn.qinys.ai.chatgpt.req.MsgReq;
-import jakarta.annotation.Resource;
-import org.springframework.ai.chat.ChatResponse;
-import org.springframework.ai.chat.prompt.Prompt;
-import org.springframework.ai.ollama.api.OllamaOptions;
-import org.springframework.ai.openai.OpenAiChatClient;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * description:
- *
- * @author: tanlie
- * @date: 2024/5/12
- */
-@RestController
-@RequestMapping("/kimi")
-public class MessageController {
-
-    @Resource
-    private OpenAiChatClient openAiChatClient;
-
-    @PostMapping("/test")
-    public Object test(@RequestBody MsgReq req){
-        ChatResponse response = openAiChatClient.call(
-                new Prompt(
-                        req.getMsg(),
-                        OllamaOptions.create()
-                                .withTemperature(0.4F)
-                ));
-        System.out.println(response.getResult().getOutput());
-        return response.getResult().getOutput();
-    }
-}

+ 0 - 38
chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/OllamaController.java

@@ -1,38 +0,0 @@
-package cn.qinys.ai.chatgpt.controller;
-
-import cn.qinys.ai.chatgpt.req.MsgReq;
-import jakarta.annotation.Resource;
-import org.springframework.ai.chat.ChatResponse;
-import org.springframework.ai.chat.prompt.Prompt;
-import org.springframework.ai.ollama.OllamaChatClient;
-import org.springframework.ai.ollama.api.OllamaOptions;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @description
- * @date 2025-03-11 15:40
- **/
-@RestController
-@RequestMapping("/ollama")
-public class OllamaController {
-
-    @Resource
-    private OllamaChatClient ollamaChatClient;
-
-
-    @PostMapping("/test")
-    public Object test(@RequestBody MsgReq req) {
-        ChatResponse response = ollamaChatClient.call(
-                new Prompt(
-                        req.getMsg(),
-                        OllamaOptions.create()
-                                .withTemperature(0.4F)
-                ));
-        System.out.println(response.getResult().getOutput());
-        return response.getResult().getOutput();
-    }
-
-}

+ 0 - 33
chatgpt/src/main/java/cn/qinys/ai/chatgpt/envetlistner/ApplicationStartEventListener.java

@@ -1,33 +0,0 @@
-package cn.qinys.ai.chatgpt.envetlistner;
-
-import lombok.val;
-import org.springframework.boot.context.event.ApplicationStartedEvent;
-import org.springframework.context.ApplicationListener;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Component;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-/**
- * description:
- *
- * @author: tanlie
- * @date: 2024/10/1
- */
-@Component
-public class ApplicationStartEventListener implements ApplicationListener<ApplicationStartedEvent> {
-    @Override
-    public void onApplicationEvent(ApplicationStartedEvent event) {
-        ConfigurableApplicationContext context = event.getApplicationContext();
-        try {
-            System.err.println(InetAddress.getLocalHost().getHostAddress());
-        } catch (UnknownHostException ignored) {
-        }
-        Environment env = context.getEnvironment();
-        System.err.println(env.getProperty("server.port"));
-        System.err.println(env.getProperty("spring.application.name"));
-        System.err.println(event.getTimeTaken().getSeconds());
-    }
-}

+ 0 - 17
chatgpt/src/main/java/cn/qinys/ai/chatgpt/req/MsgReq.java

@@ -1,17 +0,0 @@
-package cn.qinys.ai.chatgpt.req;
-
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * description:
- *
- * @author: tanlie
- * @date: 2024/5/12
- */
-@Data
-public class MsgReq implements Serializable {
-
-    private String msg;
-}

+ 0 - 0
chatgpt/src/main/resources/META-INF/spring.factories


+ 0 - 21
chatgpt/src/main/resources/application.yml

@@ -1,21 +0,0 @@
-server:
-  port: 3000
-spring:
-  application:
-    name: ai-application
-  ai:
-    openai:
-      api-key: sk-sq8MfPnD7Y7m0dVCUhLjQofGliKem1w2PMBYTEZ5GwieMp4b
-      base-url: http://192.168.1.10:3000
-      #api-key: sk-71RyBMlhwTDKC5jABYdYkN0e6QAiFGJ01RW5oAKBTrIKRQGd
-      #base-url: https://api.moonshot.cn
-      #api-key: sk-zCUZT5DJCnAubc10517470Ce06C544Bd8a7c3726608517Fe
-      #base-url: https://api.pumpkinaigc.online
-      chat:
-        options:
-          model: moonshot-v1-128k
-    ollama:
-      base-url: http://192.168.189.128:11434
-      chat:
-        options:
-          model: deepseek-r1

+ 0 - 33
chatgpt/src/test/java/cn/qinys/ai/chatgpt/controller/MessageControllerTest.java

@@ -1,33 +0,0 @@
-package cn.qinys.ai.chatgpt.controller;
-
-import cn.hutool.core.io.file.FileReader;
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
-import org.junit.jupiter.api.Test;
-
-import java.nio.charset.StandardCharsets;
-
-/**
- * description:
- *
- * @author: tanlie
- * @date: 2024/10/1
- */
-class MessageControllerTest {
-
-    @Test
-    void test1() {
-    }
-
-
-    @Test
-    void readGitProperties() {
-        FileReader fileReader = new FileReader("git.properties", StandardCharsets.UTF_8);
-        String result = fileReader.readString();
-        //JSONObject jsonObject = JSON.parseObject(result);
-        //中文好像不行。
-        System.err.println(result);
-
-
-    }
-}

+ 0 - 2
demo/.gitattributes

@@ -1,2 +0,0 @@
-/mvnw text eol=lf
-*.cmd text eol=crlf

+ 0 - 33
demo/.gitignore

@@ -1,33 +0,0 @@
-HELP.md
-target/
-!.mvn/wrapper/maven-wrapper.jar
-!**/src/main/**/target/
-!**/src/test/**/target/
-
-### STS ###
-.apt_generated
-.classpath
-.factorypath
-.project
-.settings
-.springBeans
-.sts4-cache
-
-### IntelliJ IDEA ###
-.idea
-*.iws
-*.iml
-*.ipr
-
-### NetBeans ###
-/nbproject/private/
-/nbbuild/
-/dist/
-/nbdist/
-/.nb-gradle/
-build/
-!**/src/main/**/build/
-!**/src/test/**/build/
-
-### VS Code ###
-.vscode/

+ 0 - 103
demo/pom.xml

@@ -1,103 +0,0 @@
-<?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.4.3</version>
-		<relativePath/> <!-- lookup parent from repository -->
-	</parent>
-	<groupId>com.digital</groupId>
-	<artifactId>demo</artifactId>
-	<version>0.0.1-SNAPSHOT</version>
-	<name>demo</name>
-	<description>demo</description>
-	<url/>
-	<licenses>
-		<license/>
-	</licenses>
-	<developers>
-		<developer/>
-	</developers>
-	<scm>
-		<connection/>
-		<developerConnection/>
-		<tag/>
-		<url/>
-	</scm>
-	<properties>
-		<java.version>17</java.version>
-	</properties>
-	<dependencies>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-data-redis</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-starter-web</artifactId>
-		</dependency>
-		<dependency>
-			<groupId>org.springframework.boot</groupId>
-			<artifactId>spring-boot-configuration-processor</artifactId>
-			<optional>true</optional>
-		</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>
-		<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
-		<dependency>
-			<groupId>org.apache.commons</groupId>
-			<artifactId>commons-lang3</artifactId>
-			<version>3.17.0</version>
-		</dependency>
-		<dependency>
-			<groupId>com.alibaba.fastjson2</groupId>
-			<artifactId>fastjson2</artifactId>
-			<version>2.0.53</version>
-		</dependency>
-
-	</dependencies>
-
-	<build>
-		<plugins>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-compiler-plugin</artifactId>
-				<configuration>
-					<annotationProcessorPaths>
-						<path>
-							<groupId>org.springframework.boot</groupId>
-							<artifactId>spring-boot-configuration-processor</artifactId>
-						</path>
-						<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>

+ 0 - 13
demo/src/main/java/com/example/demo/DemoApplication.java

@@ -1,13 +0,0 @@
-package com.example.demo;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-
-@SpringBootApplication
-public class DemoApplication {
-
-	public static void main(String[] args) {
-		SpringApplication.run(DemoApplication.class, args);
-	}
-
-}

+ 0 - 99
demo/src/main/java/com/example/demo/config/redis/RedisConfig.java

@@ -1,99 +0,0 @@
-package com.example.demo.config.redis;
-
-import com.fasterxml.jackson.annotation.JsonAutoDetect;
-import com.fasterxml.jackson.annotation.PropertyAccessor;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.springframework.cache.annotation.EnableCaching;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.data.redis.cache.RedisCacheConfiguration;
-import org.springframework.data.redis.cache.RedisCacheManager;
-import org.springframework.data.redis.cache.RedisCacheWriter;
-import org.springframework.data.redis.connection.RedisConnectionFactory;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.data.redis.listener.PatternTopic;
-import org.springframework.data.redis.listener.RedisMessageListenerContainer;
-import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.RedisSerializationContext;
-import org.springframework.data.redis.serializer.RedisSerializer;
-import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-import java.net.UnknownHostException;
-import java.time.Duration;
-
-/**
- * Description:
- *
- * @author tanlie
- * Date: 2024/1/9 9:07
- */
-@EnableCaching
-@Configuration
-public class RedisConfig {
-    /**
-     * 缓存管理器
-     *
-     * @param factory
-     * @return
-     */
-    @Bean
-    @SuppressWarnings("all")
-    public RedisCacheManager cacheManager(RedisConnectionFactory factory) {
-        ObjectMapper om = new ObjectMapper();
-        RedisSerializer<String> redisSerializer = new StringRedisSerializer();
-        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
-        // 解决查询缓存转换异常的问题
-        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
-        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
-        jackson2JsonRedisSerializer.setObjectMapper(om);
-        // 配置序列化(解决乱码的问题)
-        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
-                .entryTtl(Duration.ofMillis(-1))
-                .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(redisSerializer))
-                .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(jackson2JsonRedisSerializer))
-                .disableCachingNullValues();
-        RedisCacheWriter cacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(factory);
-
-        return new RedisConfigCacheManager(cacheWriter, config);
-    }
-
-    //重写template配置累
-    @Bean
-    @SuppressWarnings("all")
-    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) throws UnknownHostException {
-
-        RedisTemplate<String, Object> template = new RedisTemplate();
-        template.setConnectionFactory(factory);
-        //json序列化
-        Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
-        ObjectMapper om = new ObjectMapper();
-        om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
-        om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
-        jackson2JsonRedisSerializer.setObjectMapper(om);
-        //String 序列化
-        StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
-        //key 采用string序列化
-        template.setKeySerializer(stringRedisSerializer);
-        template.setHashKeySerializer(stringRedisSerializer);  //hash key也采用string
-        //value 采用json
-        template.setValueSerializer(jackson2JsonRedisSerializer);
-        template.setHashValueSerializer(jackson2JsonRedisSerializer);
-
-        template.afterPropertiesSet();
-        return template;
-    }
-
-
-    @Bean
-    public RedisMessageListenerContainer container(RedisConnectionFactory factory){
-        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
-        container.setConnectionFactory(factory);
-
-        //订阅频道,通配符*表示任意多个占位符
-        container.addMessageListener(new RedisSubscribe(), new PatternTopic(RedisKeyEnum.ACCESS_LOGS.getKey()));
-
-        return container;
-
-    }
-
-}

+ 0 - 54
demo/src/main/java/com/example/demo/config/redis/RedisConfigCacheManager.java

@@ -1,54 +0,0 @@
-package com.example.demo.config.redis;
-
-
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.data.redis.cache.*;
-import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
-import org.springframework.data.redis.serializer.RedisSerializationContext;
-
-import java.time.Duration;
-
-/**
- * Description:
- *
- * @author tanlie
- * Date: 2024/9/5 11:01
- */
-public class RedisConfigCacheManager extends RedisCacheManager {
-
-    private static final CacheKeyPrefix DEFAULT_CACHE_KEY_PREFIX = cacheName -> cacheName + ":";
-
-    public RedisConfigCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
-        super(cacheWriter, defaultCacheConfiguration);
-    }
-
-    private static final RedisSerializationContext.SerializationPair<Object> DEFAULT_PAIR = RedisSerializationContext.SerializationPair
-            .fromSerializer(new GenericJackson2JsonRedisSerializer());
-
-    /**
-     * @param name
-     * @param cacheConfig
-     * @return
-     */
-    @Override
-    protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
-        final int lastIndexOf = StringUtils.lastIndexOf(name, '#');
-        if (lastIndexOf > -1) {
-            final String ttl = StringUtils.substring(name, lastIndexOf + 1);
-            final Duration duration = Duration.ofSeconds(Long.parseLong(ttl));
-            cacheConfig = cacheConfig.entryTtl(duration);
-            //修改缓存key和value值的序列化方式
-            cacheConfig = cacheConfig.computePrefixWith(DEFAULT_CACHE_KEY_PREFIX)
-                    .serializeValuesWith(DEFAULT_PAIR);
-            final String cacheName = StringUtils.substring(name, 0, lastIndexOf);
-            return super.createRedisCache(cacheName, cacheConfig);
-        } else {
-            //修改缓存key和value值的序列化方式
-            cacheConfig = cacheConfig.computePrefixWith(DEFAULT_CACHE_KEY_PREFIX)
-                    .serializeValuesWith(DEFAULT_PAIR);
-            return super.createRedisCache(name, cacheConfig);
-        }
-    }
-
-
-}

+ 0 - 25
demo/src/main/java/com/example/demo/config/redis/RedisKeyEnum.java

@@ -1,25 +0,0 @@
-package com.example.demo.config.redis;
-
-import lombok.Getter;
-
-/**
- * Description:
- *
- * @author tanlie
- * Date: 2024/1/9 9:12
- */
-@Getter
-public enum RedisKeyEnum {
-
-    ACCESS_LOGS("ACCESS_LOGS", "请求记录", 7200);
-
-    RedisKeyEnum(String key, String msg, Integer expireTime) {
-        this.key = key;
-        this.msg = msg;
-        this.expireTime = expireTime;
-    }
-
-    private final String key;
-    private final String msg;
-    private final Integer expireTime;
-}

+ 0 - 31
demo/src/main/java/com/example/demo/config/redis/RedisSubscribe.java

@@ -1,31 +0,0 @@
-package com.example.demo.config.redis;
-
-
-import com.alibaba.fastjson2.JSON;
-import com.alibaba.fastjson2.JSONObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.data.redis.connection.Message;
-import org.springframework.data.redis.connection.MessageListener;
-
-/**
- * Description:
- * Auth: tanlie
- * Date: 2023/8/30 16:06
- */
-public class RedisSubscribe implements MessageListener {
-    Logger logger = LoggerFactory.getLogger(this.getClass());
-
-    /**
-     * 发布订阅多个客户端并行时,可能会产生重复消费,所以要注意加锁
-     *
-     * @param message message must not be {@literal null}.
-     * @param bytes   pattern matching the channel (if specified) - can be {@literal null}.
-     */
-    @Override
-    public void onMessage(Message message, byte[] bytes) {
-        String msg = new String(message.getBody());
-        JSONObject json = JSON.parseObject(msg);
-        logger.info("收到订阅发布信息={}", json);
-    }
-}

+ 0 - 12
demo/src/main/resources/application.yml

@@ -1,12 +0,0 @@
-server:
-  port: 8080
-spring:
-  application:
-    name: demo-application
-
-  data:
-    redis:
-      host: 116.8.109.23
-      port: 40071
-      password: "XinchanR@2022###"
-      database: 8

+ 0 - 13
demo/src/test/java/com/example/demo/DemoApplicationTests.java

@@ -1,13 +0,0 @@
-package com.example.demo;
-
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-@SpringBootTest
-class DemoApplicationTests {
-
-	@Test
-	void contextLoads() {
-	}
-
-}

+ 0 - 109
demo/src/test/java/com/example/demo/config/redis/RedisConfigTest.java

@@ -1,109 +0,0 @@
-package com.example.demo.config.redis;
-
-import com.alibaba.fastjson2.JSON;
-import jakarta.annotation.Resource;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.data.redis.connection.RedisStringCommands;
-import org.springframework.data.redis.core.RedisCallback;
-import org.springframework.data.redis.core.RedisTemplate;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @description
- * @date 2025-03-12 17:03
- **/
-
-@SpringBootTest
-class RedisConfigTest {
-    @Resource
-    RedisTemplate<String, Object> redisTemplate;
-
-    @Test
-    void stringTest() {
-        redisTemplate.opsForValue().set("hello", "world", 20, TimeUnit.SECONDS);
-        System.out.println(redisTemplate.opsForValue().get("hello"));
-        redisTemplate.opsForValue().setIfAbsent("step", 1, 30, TimeUnit.SECONDS);
-        redisTemplate.opsForValue().increment("increment", 1);
-        redisTemplate.opsForValue().increment("increment", 2);
-        redisTemplate.opsForValue().append("test", "1");
-        redisTemplate.opsForValue().append("test", ",2");
-
-        Map<String, String> map = new HashMap<>();
-        map.put("key1", "value1");
-        map.put("key2", "value2");
-        map.put("key3", "value3");
-        map.put("key4", "value4");
-        redisTemplate.opsForValue().multiSet(map);
-        Set<String> keys = redisTemplate.keys("key*");
-        assert keys != null;
-        redisTemplate.delete(keys);
-    }
-
-
-    @Test
-    void hashTest() {
-        redisTemplate.opsForHash().put("hash1", "key1", "value1");
-        redisTemplate.opsForHash().put("hash1", "key2", "value2");
-        redisTemplate.opsForHash().put("hash1", "key3", "value3");
-        System.out.println(redisTemplate.opsForHash().get("hash1", "key1"));
-        redisTemplate.expire("hash1", 60, TimeUnit.SECONDS);
-    }
-
-
-    @Test
-    void listTest(){
-        redisTemplate.opsForList().leftPush("list1", "value1");
-        redisTemplate.opsForList().leftPush("list1", "value2");
-        redisTemplate.opsForList().leftPush("list1", "value3");
-        redisTemplate.opsForList().rightPush("list1", "value4");
-        redisTemplate.opsForList().leftPop("list1");
-        System.out.println(redisTemplate.opsForList().index("list1",2));
-    }
-
-    @Test
-    void setTest(){
-        redisTemplate.opsForSet().add("set1", "value1");
-        redisTemplate.opsForSet().add("set1", "value2");
-        redisTemplate.opsForSet().add("set1", "value1");
-    }
-
-    @Test
-    void sortedSetTest(){
-        redisTemplate.opsForZSet().add("zset1","zset1",0);
-        redisTemplate.opsForZSet().add("zset1","zset2",1);
-    }
-
-
-    @Test
-    void executeTest() {
-        String key = "hello";
-        redisTemplate.opsForValue().set("hello", "world", 20, TimeUnit.SECONDS);
-        redisTemplate.execute((RedisCallback<Object>) connection -> {
-            RedisStringCommands commands = connection.stringCommands();
-            Long size = commands.strLen("hello".getBytes());
-            System.out.println(size);
-            return null;
-        });
-
-    }
-
-    //发布订阅
-    // 发布订阅多个客户端并行时,可能会产生重复消费
-    @Test
-    void convertAndSendTest(){
-        Map<String, String> map = new HashMap<>();
-        map.put("key1", "value1");
-        map.put("key2", "value2");
-        map.put("key3", "value3");
-        redisTemplate.convertAndSend(RedisKeyEnum.ACCESS_LOGS.getKey(), JSON.toJSONString(map));
-    }
-
-
-
-
-}

+ 20 - 0
ollamaai/pom.xml

@@ -0,0 +1,20 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>cn.qinys.ai</groupId>
+        <artifactId>spring-ai</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>ollamaai</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+</project>

+ 20 - 0
openai/pom.xml

@@ -0,0 +1,20 @@
+<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>cn.qinys.ai</groupId>
+        <artifactId>spring-ai</artifactId>
+        <version>1.0.0</version>
+    </parent>
+
+    <artifactId>openai</artifactId>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+</project>

+ 86 - 0
pom.xml

@@ -0,0 +1,86 @@
+<?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>
+    <groupId>cn.qinys.ai</groupId>
+    <artifactId>spring-ai</artifactId>
+    <name>spring-ai</name>
+    <version>1.0.0</version>
+    <packaging>pom</packaging>
+    <description>Demo project for Spring Boot</description>
+
+    <modules>
+        <module>openai</module>
+        <module>alibaba-ai</module>
+        <module>ollamaai</module>
+    </modules>
+
+    <properties>
+        <maven.compiler.source>17</maven.compiler.source>
+        <maven.compiler.target>17</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+        <spring-boot.version>3.5.7</spring-boot.version>
+        <spring-cloud.version>2025.0.0</spring-cloud.version>
+        <spring-alibaba-ai.version>1.0.0.4</spring-alibaba-ai.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <!--spring cloud 版本管理-->
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <!--spring boot 版本管理-->
+            <dependency>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-starter-parent</artifactId>
+                <version>${spring-boot.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+            <dependency>
+                <groupId>com.alibaba.cloud.ai</groupId>
+                <artifactId>spring-ai-alibaba-bom</artifactId>
+                <version>${spring-alibaba-ai.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>com.alibaba</groupId>
+                <artifactId>fastjson</artifactId>
+                <version>2.0.32</version>
+            </dependency>
+            <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
+            <dependency>
+                <groupId>cn.hutool</groupId>
+                <artifactId>hutool-all</artifactId>
+                <version>5.8.32</version>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <!--<build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>io.github.git-commit-id</groupId>
+                <artifactId>git-commit-id-maven-plugin</artifactId>
+                <version>9.0.0</version>
+                <configuration>
+                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
+                    <format>json</format>
+                    <commitIdGenerationMode>full</commitIdGenerationMode>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>-->
+</project>