diff --git a/pom.xml b/pom.xml index 808ddc4..462eee0 100644 --- a/pom.xml +++ b/pom.xml @@ -6,28 +6,15 @@ org.springframework.boot spring-boot-starter-parent 3.5.6 - com.hanserwei ai-robot 0.0.1-SNAPSHOT han-ai-robot-springboot han-ai-robot-springboot - - - - - - - - - - - - - 21 + 1.0.3 @@ -35,12 +22,35 @@ spring-boot-starter-web + + com.github.ulisesbocchio + jasypt-spring-boot-starter + 3.0.5 + + + + + org.springframework.ai + spring-ai-starter-model-deepseek + + org.springframework.boot spring-boot-starter-test test + + + + org.springframework.ai + spring-ai-bom + ${spring-ai.version} + pom + import + + + diff --git a/src/main/java/com/hanserwei/airobot/controller/DeepSeekChatController.java b/src/main/java/com/hanserwei/airobot/controller/DeepSeekChatController.java new file mode 100644 index 0000000..12b66fb --- /dev/null +++ b/src/main/java/com/hanserwei/airobot/controller/DeepSeekChatController.java @@ -0,0 +1,28 @@ +package com.hanserwei.airobot.controller; + +import jakarta.annotation.Resource; +import org.springframework.ai.deepseek.DeepSeekChatModel; +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; + +@RestController +@RequestMapping("/ai") +public class DeepSeekChatController { + + @Resource + private DeepSeekChatModel chatModel; + + /** + * 普通对话 + * @param message 对话输入内容 + * @return 对话结果 + */ + @GetMapping("/generate") + public String generate(@RequestParam(value = "message", defaultValue = "你是谁?") String message) { + // 一次性返回结果 + return chatModel.call(message); + } + +} \ No newline at end of file diff --git a/src/main/java/com/hanserwei/airobot/utils/EncryptorUtil.java b/src/main/java/com/hanserwei/airobot/utils/EncryptorUtil.java new file mode 100644 index 0000000..7bf6b8d --- /dev/null +++ b/src/main/java/com/hanserwei/airobot/utils/EncryptorUtil.java @@ -0,0 +1,11 @@ +package com.hanserwei.airobot.utils; + +import org.jasypt.util.text.AES256TextEncryptor; + +public class EncryptorUtil { + public static void main(String[] args) { + AES256TextEncryptor textEncryptor = new AES256TextEncryptor(); + textEncryptor.setPassword("password"); + System.out.println(textEncryptor.encrypt("sk-xxxxxxxxxxxxxx")); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 964398d..04a8fe6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,17 @@ +#file: noinspection SpringBootConfigYamlInspection spring: application: - name: han-ai-robot-springboot \ No newline at end of file + name: han-ai-robot-springboot + ai: + deepseek: + api-key: ENC(MROXdiEHmWk08koE63bTzFqW52MaXLpMkM9Cyl40Ubj+Lw1yKeZuHLEcs6jTFY8ditY4gJ1365LMAY8Z9G1uwfYFYaYdb3NyijplX7GuDZA=) # 填写 DeepSeek Api Key, 改成你自己的 + base-url: https://api.deepseek.com # DeepSeek 的请求 URL, 可不填,默认值为 api.deepseek.com + chat: + options: + model: deepseek-chat # 使用哪个模型 + temperature: 0.8 # 温度值 +jasypt: + encryptor: + password: ${jasypt.encryptor.password} + algorithm: PBEWithHMACSHA512AndAES_256 + iv-generator-classname: org.jasypt.iv.RandomIvGenerator \ No newline at end of file