This commit is contained in:
huangge1199 2025-07-12 10:45:14 +08:00
parent 8f8ab67b5d
commit 1ef2872ebf
3 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package com.huangge1199.ai.config;
import com.huangge1199.ai.service.LangChainService;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* LangChainConfig
*
* @author huangge1199
* @since 2025/7/12 10:32:01
*/
@Configuration
public class LangChainConfig {
@Resource
private ChatModel qwenChatModel;
@Bean
public LangChainService langChainService() {
return AiServices.create(LangChainService.class, qwenChatModel);
}
}

View File

@ -0,0 +1,35 @@
package com.huangge1199.ai.controller;
import com.huangge1199.ai.common.R;
import com.huangge1199.ai.service.LangChainService;
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;
/**
* langChain的AI服务
*
* @author huangge1199
* @since 2025/7/12 10:36:40
*/
@RestController
@RequestMapping("/langChain")
public class LangChainController {
@Resource
private LangChainService langChainService;
/**
* AI对话
*
* @param message 输入信息
* @return ai返回结果
*/
@PostMapping("/chat")
public R<String> chat(@RequestBody String message) {
String result = langChainService.chat(message);
return R.ok(result);
}
}

View File

@ -0,0 +1,15 @@
package com.huangge1199.ai.service;
import dev.langchain4j.service.SystemMessage;
/**
* LangChainService
*
* @author huangge1199
* @since 2025/7/12 10:25:27
*/
public interface LangChainService {
@SystemMessage(fromResource = "system-prompt.txt")
String chat(String message);
}