tanlie vor 4 Monaten
Ursprung
Commit
df3e32a960

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 .idea/
 chatgpt/target/
 alibaba-ai/target/
+chat-client/target/

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

@@ -10,8 +10,6 @@ import org.springframework.ai.image.ImagePrompt;
 import org.springframework.ai.image.ImageResponse;
 import org.springframework.boot.test.context.SpringBootTest;
 
-import java.io.InputStream;
-
 /**
  * @author lie tan
  * @description

+ 29 - 0
chat-client/pom.xml

@@ -0,0 +1,29 @@
+<?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>chat-client</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>

+ 17 - 0
chat-client/src/main/java/cn/qinys/ai/ChatClientApplication.java

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

+ 9 - 0
chat-client/src/main/java/cn/qinys/ai/service/ChatClientService.java

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

+ 13 - 0
chat-client/src/main/java/cn/qinys/ai/service/impl/ChatClientServiceImpl.java

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

+ 13 - 0
chat-client/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

+ 38 - 0
chat-client/src/test/java/cn/qinys/ai/service/impl/ChatClientServiceImplTest.java

@@ -0,0 +1,38 @@
+package cn.qinys.ai.service.impl;
+
+import jakarta.annotation.Resource;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.springframework.ai.chat.client.ChatClient;
+import org.springframework.ai.chat.client.DefaultChatClientBuilder;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * @author lie tan
+ * @description
+ * @date 2025-11-16 21:47
+ **/
+@SpringBootTest
+class ChatClientServiceImplTest {
+
+    @Resource
+    ChatClient.Builder clientBuilder;
+
+    private ChatClient chatClient;
+
+    @BeforeEach
+    void setUp() {
+        chatClient = clientBuilder.build();
+    }
+
+    @Test
+    void callTest() {
+        String content = chatClient.prompt()
+                .user("你好")
+                .call()
+                .content();
+        System.err.println(content);
+    }
+}

+ 1 - 0
pom.xml

@@ -13,6 +13,7 @@
         <module>openai</module>
         <module>alibaba-ai</module>
         <module>ollamaai</module>
+        <module>chat-client</module>
     </modules>
 
     <properties>