20250304 langchain high level模式

This commit is contained in:
liangjinglin 2025-03-04 20:09:16 +08:00
parent 17ba408806
commit f321c1c3e7
6 changed files with 33 additions and 4 deletions

View File

@ -24,6 +24,11 @@
<artifactId>langchain4j-core</artifactId> <artifactId>langchain4j-core</artifactId>
<version>1.0.0-beta1</version> <version>1.0.0-beta1</version>
</dependency> </dependency>
<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-spring-boot-starter</artifactId>
<version>1.0.0-beta1</version>
</dependency>
<dependency> <dependency>
<groupId>dev.langchain4j</groupId> <groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-community-bom</artifactId> <artifactId>langchain4j-community-bom</artifactId>

View File

@ -9,10 +9,10 @@ import org.springframework.context.annotation.Configuration;
@Configuration @Configuration
public class LanguageModelConfig { public class LanguageModelConfig {
@Value("${langchain4j.community.dashscope.api-key}") @Value("${langchain4j.community.dashscope.chat-model.api-key}")
private String apiKey; private String apiKey;
@Value("${langchain4j.community.dashscope.model-name}") @Value("${langchain4j.community.dashscope.chat-model.model-name}")
private String modelName; private String modelName;
@Bean @Bean

View File

@ -1,5 +1,6 @@
package com.ai.controller; package com.ai.controller;
import com.ai.service.Assist;
import com.ai.service.LangChainService; import com.ai.service.LangChainService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -14,6 +15,9 @@ public class LangChainController {
@Autowired @Autowired
private LangChainService langChainService; private LangChainService langChainService;
@Autowired
private Assist assist;
/** /**
* 处理用户输入并调用 LangChainService 获取响应 * 处理用户输入并调用 LangChainService 获取响应
* @param input 用户输入的内容 * @param input 用户输入的内容
@ -24,4 +28,10 @@ public class LangChainController {
System.out.println("start chat..."); System.out.println("start chat...");
return langChainService.getResponse(input); return langChainService.getResponse(input);
} }
@GetMapping("/high/chat")
public String highChat(@RequestParam("input") String input) {
System.out.println("start highlevel chat...");
return assist.chat(input);
}
} }

View File

@ -1,2 +1,5 @@
### 测试 LangChainController 的 chat 接口 ### 测试 LangChainController 的 chat 接口
GET http://localhost:8080/langchain/chat?input=今天天气如何 GET http://localhost:8080/langchain/chat?input=今天天气如何
### 测试 LangChainController 的 highlevel chat 接口
GET http://localhost:8080/langchain/high/chat?input=评价一下路飞

View File

@ -0,0 +1,11 @@
package com.ai.service;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.spring.AiService;
@AiService
public interface Assist {
@SystemMessage("假设你是唐吉坷德多佛朗明哥")
String chat(String userMessage);
}

View File

@ -1,4 +1,4 @@
server.port=8080 server.port=8080
langchain4j.community.dashscope.api-key=sk-2f703a41fff0488e9b6888013d2ee58a langchain4j.community.dashscope.chat-model.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
langchain4j.community.dashscope.model-name=deepseek-r1 langchain4j.community.dashscope.chat-model.model-name=deepseek-v3