20250304 langchain high level模式
This commit is contained in:
parent
17ba408806
commit
f321c1c3e7
5
pom.xml
5
pom.xml
@ -24,6 +24,11 @@
|
||||
<artifactId>langchain4j-core</artifactId>
|
||||
<version>1.0.0-beta1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-spring-boot-starter</artifactId>
|
||||
<version>1.0.0-beta1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.langchain4j</groupId>
|
||||
<artifactId>langchain4j-community-bom</artifactId>
|
||||
|
@ -9,10 +9,10 @@ import org.springframework.context.annotation.Configuration;
|
||||
@Configuration
|
||||
public class LanguageModelConfig {
|
||||
|
||||
@Value("${langchain4j.community.dashscope.api-key}")
|
||||
@Value("${langchain4j.community.dashscope.chat-model.api-key}")
|
||||
private String apiKey;
|
||||
|
||||
@Value("${langchain4j.community.dashscope.model-name}")
|
||||
@Value("${langchain4j.community.dashscope.chat-model.model-name}")
|
||||
private String modelName;
|
||||
|
||||
@Bean
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.ai.controller;
|
||||
|
||||
import com.ai.service.Assist;
|
||||
import com.ai.service.LangChainService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -14,6 +15,9 @@ public class LangChainController {
|
||||
@Autowired
|
||||
private LangChainService langChainService;
|
||||
|
||||
@Autowired
|
||||
private Assist assist;
|
||||
|
||||
/**
|
||||
* 处理用户输入并调用 LangChainService 获取响应
|
||||
* @param input 用户输入的内容
|
||||
@ -24,4 +28,10 @@ public class LangChainController {
|
||||
System.out.println("start chat...");
|
||||
return langChainService.getResponse(input);
|
||||
}
|
||||
|
||||
@GetMapping("/high/chat")
|
||||
public String highChat(@RequestParam("input") String input) {
|
||||
System.out.println("start highlevel chat...");
|
||||
return assist.chat(input);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,5 @@
|
||||
### 测试 LangChainController 的 chat 接口
|
||||
GET http://localhost:8080/langchain/chat?input=今天天气如何
|
||||
|
||||
### 测试 LangChainController 的 highlevel chat 接口
|
||||
GET http://localhost:8080/langchain/high/chat?input=评价一下路飞
|
||||
|
11
src/main/java/com/ai/service/Assist.java
Normal file
11
src/main/java/com/ai/service/Assist.java
Normal 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);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
server.port=8080
|
||||
|
||||
langchain4j.community.dashscope.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
|
||||
langchain4j.community.dashscope.model-name=deepseek-r1
|
||||
langchain4j.community.dashscope.chat-model.api-key=sk-2f703a41fff0488e9b6888013d2ee58a
|
||||
langchain4j.community.dashscope.chat-model.model-name=deepseek-v3
|
||||
|
Loading…
Reference in New Issue
Block a user