代码提交
parent
c6369e0eb4
commit
9e031a6dad
@ -0,0 +1,37 @@
|
||||
package com.supervision.chat.client;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import org.checkerframework.checker.units.qual.C;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestClient;
|
||||
import org.springframework.web.client.support.RestClientAdapter;
|
||||
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Configuration
|
||||
public class LangChainChatConfig {
|
||||
|
||||
@Value("${langChain-chat.url}")
|
||||
private String LangChainChatClientUrl;
|
||||
|
||||
|
||||
@Bean
|
||||
public RestClient restClient() {
|
||||
return RestClient.builder().baseUrl(LangChainChatClientUrl).build();
|
||||
}
|
||||
@Bean
|
||||
public LangChainChatService langChainChatClient(RestClient restClient) {
|
||||
|
||||
RestClientAdapter adapter = RestClientAdapter.create(restClient);
|
||||
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
|
||||
|
||||
return factory.createClient(LangChainChatService.class);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.supervision.chat.client;
|
||||
|
||||
import com.supervision.chat.client.dto.CreateBaseDTO;
|
||||
import com.supervision.chat.client.dto.LangChainChatRes;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.service.annotation.HttpExchange;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
@HttpExchange
|
||||
public interface LangChainChatService {
|
||||
|
||||
@PostExchange(url = "create_knowledge_base", contentType = "application/json")
|
||||
void chat(@RequestBody CreateBaseDTO createBaseDTO);
|
||||
|
||||
@PostExchange(url = "chat/test/testPost", contentType = "application/json")
|
||||
LangChainChatRes test(@RequestBody CreateBaseDTO createBaseDTO);
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.supervision.chat.client;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.supervision.chat.client.dto.CreateBaseDTO;
|
||||
import com.supervision.chat.client.dto.LangChainChatRes;
|
||||
import org.apache.hc.client5.http.classic.HttpClient;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpResponse;
|
||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||
import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
public class LangChainChatServiceImpl{
|
||||
|
||||
@Value("${langChain-chat.url}")
|
||||
private String LangChainChatClientUrl;
|
||||
|
||||
|
||||
public LangChainChatRes chat(CreateBaseDTO createBaseDTO) {
|
||||
String post = HttpUtil.post(LangChainChatClientUrl + "create_knowledge_base", JSONUtil.toJsonStr(createBaseDTO));
|
||||
if (JSONUtil.isTypeJSON(post)) {
|
||||
return JSONUtil.toBean(post, LangChainChatRes.class);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.chat.client.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CreateBaseDTO {
|
||||
|
||||
private String knowledge_base_name;
|
||||
|
||||
private String vector_store_type = "faiss";
|
||||
|
||||
private String embed_model = "bge-large-zh";
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.supervision.chat.client.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LangChainChatRes {
|
||||
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private String data;
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.supervision.chat.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.supervision.chat.client.LangChainChatService;
|
||||
import com.supervision.chat.client.dto.CreateBaseDTO;
|
||||
import com.supervision.chat.client.dto.LangChainChatRes;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.service.annotation.PostExchange;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
@RequestMapping("chat/test/")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class TestController {
|
||||
|
||||
private final LangChainChatService langChainChatClient;
|
||||
|
||||
@GetMapping("test")
|
||||
public void test(){
|
||||
CreateBaseDTO createBaseDTO = new CreateBaseDTO();
|
||||
createBaseDTO.setKnowledge_base_name("11111111");
|
||||
langChainChatClient.chat(createBaseDTO);
|
||||
// log.info(JSONUtil.toJsonStr(chat));
|
||||
}
|
||||
|
||||
@PostMapping("testPost")
|
||||
public void testPost(@RequestBody CreateBaseDTO createBaseDTO){
|
||||
System.out.println(JSONUtil.toJsonStr(createBaseDTO));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue