代码提交

topo_dev
liu 10 months ago
parent 9e031a6dad
commit 5420ecabc7

@ -6,8 +6,11 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.client.support.RestClientAdapter; import org.springframework.web.client.support.RestClientAdapter;
import org.springframework.web.client.support.RestTemplateAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory; import org.springframework.web.service.invoker.HttpServiceProxyFactory;
import org.springframework.web.util.DefaultUriBuilderFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -21,13 +24,16 @@ public class LangChainChatConfig {
@Bean @Bean
public RestClient restClient() { public LangChainChatService langChainChatClient() {
return RestClient.builder().baseUrl(LangChainChatClientUrl).build();
} // RestClientAdapter adapter = RestClientAdapter.create(restClient);
@Bean // HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
public LangChainChatService langChainChatClient(RestClient restClient) { //
// return factory.createClient(LangChainChatService.class);
RestClientAdapter adapter = RestClientAdapter.create(restClient); RestTemplate restTemplate = new RestTemplate();
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(LangChainChatClientUrl));
RestTemplateAdapter adapter = RestTemplateAdapter.create(restTemplate);
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build(); HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build();
return factory.createClient(LangChainChatService.class); return factory.createClient(LangChainChatService.class);

@ -10,10 +10,8 @@ import org.springframework.web.service.annotation.PostExchange;
public interface LangChainChatService { public interface LangChainChatService {
@PostExchange(url = "create_knowledge_base", contentType = "application/json") @PostExchange(url = "create_knowledge_base", contentType = "application/json")
void chat(@RequestBody CreateBaseDTO createBaseDTO); LangChainChatRes chat(@RequestBody CreateBaseDTO createBaseDTO);
@PostExchange(url = "chat/test/testPost", contentType = "application/json")
LangChainChatRes test(@RequestBody CreateBaseDTO createBaseDTO);
} }

@ -23,12 +23,8 @@ public class TestController {
public void test(){ public void test(){
CreateBaseDTO createBaseDTO = new CreateBaseDTO(); CreateBaseDTO createBaseDTO = new CreateBaseDTO();
createBaseDTO.setKnowledge_base_name("11111111"); createBaseDTO.setKnowledge_base_name("11111111");
langChainChatClient.chat(createBaseDTO); LangChainChatRes chat = langChainChatClient.chat(createBaseDTO);
// log.info(JSONUtil.toJsonStr(chat)); log.info(JSONUtil.toJsonStr(chat));
} }
@PostMapping("testPost")
public void testPost(@RequestBody CreateBaseDTO createBaseDTO){
System.out.println(JSONUtil.toJsonStr(createBaseDTO));
}
} }

Loading…
Cancel
Save