AI服务
This commit is contained in:
parent
8f8ab67b5d
commit
1ef2872ebf
26
src/main/java/com/huangge1199/ai/config/LangChainConfig.java
Normal file
26
src/main/java/com/huangge1199/ai/config/LangChainConfig.java
Normal 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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user