本项目是基于 Spring AI 集成 腾讯云 HunYuan 大模型 API 的 Java SDK,提供了对 HunYuan Pro、Embedding 模型的封装调用支持,并通过自动配置简化集成过程。
当前已支持功能:
- ✅ Chat ( 流式回答、图片理解 )
- ✅ Embedding
确保你已安装以下工具:
- ✅ JDK 17+
- ✅ Maven 3.8+
- ✅ 腾讯云账号 + HunYuan 秘钥(Secret ID / Secret Key)
在你的 Spring Boot 项目中添加如下依赖(以 pom.xml 为例):
<dependency>
<groupId>io.github.studiousxiaoyu</groupId>
<artifactId>spring-ai-starter-model-hunyuan</artifactId>
<version>1.0.0</version>
</dependency>
在 application.properties
或 application.yml
中添加 HunYuan 认证信息和模型配置:
spring.ai.hunyuan.secret-id=你的-secret-id
spring.ai.hunyuan.secret-key=你的-secret-key
spring.ai.hunyuan.chat.options.model=hunyuan-pro
spring.ai.hunyuan.embedding.options.model=hunyuan-embedding
spring.ai.hunyuan.embedding.options.dimensions=1024
@Service
public class HunYuanService {
private final ChatClient chatClient;
public HunYuanService(ChatModel chatModel) {
this.chatClient = ChatClient.builder(chatModel).build();
}
public String askQuestion(String question) {
return chatClient.prompt()
.user(question)
.call()
.content();
}
}
@RestController
@RequestMapping("/chat")
public class ChatController {
private final HunYuanService hunYuanService;
public ChatController(HunYuanService hunYuanService) {
this.hunYuanService = hunYuanService;
}
@GetMapping("/q")
public String chat(@RequestParam("text") String text) {
return hunYuanService.askQuestion(text);
}
}
启动 Spring Boot 应用,访问:
http://localhost:8080/chat/q?text=你好
你应该能收到来自 HunYuan Pro 模型的回复。
该项目为 Spring Boot 开发者提供了一个轻量级、易集成的 HunYuan 大模型调用方案,适用于构建智能问答、文档检索、多模态对话等 AI 应用场景。
🎉 Happy Coding! 如有疑问或建议,请提交 Issues 或 PR!