✨Feat: 完成 LLM 接入
This commit is contained in:
@@ -18,6 +18,18 @@
|
|||||||
<version>3.2.2</version>
|
<version>3.2.2</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.ai</groupId>
|
||||||
|
<artifactId>spring-ai-bom</artifactId>
|
||||||
|
<version>1.0.3</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -26,8 +38,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.ai</groupId>
|
<groupId>org.springframework.ai</groupId>
|
||||||
<artifactId>spring-ai-client-chat</artifactId>
|
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||||
<version>1.0.3</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -36,6 +47,11 @@
|
|||||||
<version>4.4.0</version>
|
<version>4.4.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.wonderland.stardewvalley.ai;
|
||||||
|
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import org.springframework.ai.chat.client.ChatClient;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ChatUtil {
|
||||||
|
|
||||||
|
private final ChatClient chatClient;
|
||||||
|
|
||||||
|
public ChatUtil(ChatClient.Builder chatClientBuilder) {
|
||||||
|
this.chatClient = chatClientBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String doChat(String background, String input) {
|
||||||
|
String content = chatClient
|
||||||
|
.prompt()
|
||||||
|
.system("你是一个AI助手,请根据背景和输入生成回复")
|
||||||
|
.user("[BackGround]: " + background + "\n[Input]: " + input)
|
||||||
|
.call()
|
||||||
|
.content();
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.wonderland.stardewvalley.constant;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class BackGroundConstant {
|
||||||
|
|
||||||
|
private static final String BACKGROUND_SPRING = "春天";
|
||||||
|
private static final String BACKGROUND_SUMMER = "夏天";
|
||||||
|
private static final String BACKGROUND_AUTUMN = "秋天";
|
||||||
|
private static final String BACKGROUND_WINTER = "冬天";
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.wonderland.stardewvalley.controller;
|
||||||
|
|
||||||
|
import com.wonderland.stardewvalley.ai.ChatUtil;
|
||||||
|
import com.wonderland.stardewvalley.entity.AIChatRequest;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("chat")
|
||||||
|
public class ChatController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ChatUtil chatUtil;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public String chat(@RequestBody AIChatRequest aiChatRequest) {
|
||||||
|
return chatUtil.doChat(aiChatRequest.getBackGround(), aiChatRequest.getContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.wonderland.stardewvalley.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AIChatRequest {
|
||||||
|
private String backGround;
|
||||||
|
private String content;
|
||||||
|
}
|
||||||
@@ -16,8 +16,15 @@ knife4j:
|
|||||||
setting:
|
setting:
|
||||||
language: zh_cn
|
language: zh_cn
|
||||||
|
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
mvc:
|
mvc:
|
||||||
servlet:
|
servlet:
|
||||||
path: /api
|
path: /api
|
||||||
|
ai:
|
||||||
|
openai:
|
||||||
|
api-key: sk-ciqpxjuhasowxqpmlqizsfoioyhllcscbtjfczmoeddcbdxy
|
||||||
|
base-url: https://api.siliconflow.cn
|
||||||
|
chat:
|
||||||
|
options:
|
||||||
|
model: Pro/Qwen/Qwen2.5-7B-Instruct
|
||||||
|
temperature: 0.7
|
||||||
Reference in New Issue
Block a user