init
This commit is contained in:
23
backend/ai-client/pom.xml
Normal file
23
backend/ai-client/pom.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.k12study</groupId>
|
||||
<artifactId>k12study-backend</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>ai-client</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.k12study</groupId>
|
||||
<artifactId>api-ai</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.k12study.aiclient.client;
|
||||
|
||||
import com.k12study.api.ai.dto.AiHealthDto;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
public class HttpPythonAiClient implements PythonAiClient {
|
||||
private final RestClient restClient;
|
||||
|
||||
public HttpPythonAiClient(RestClient restClient) {
|
||||
this.restClient = restClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AiHealthDto health() {
|
||||
try {
|
||||
AiHealthDto response = restClient.get()
|
||||
.uri("/health")
|
||||
.retrieve()
|
||||
.body(AiHealthDto.class);
|
||||
return response == null ? new AiHealthDto("python-ai", "UNKNOWN", "0.1.0") : response;
|
||||
} catch (Exception exception) {
|
||||
return new AiHealthDto("python-ai", "UNREACHABLE", "0.1.0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.k12study.aiclient.client;
|
||||
|
||||
import com.k12study.api.ai.dto.AiHealthDto;
|
||||
|
||||
public interface PythonAiClient {
|
||||
AiHealthDto health();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.k12study.aiclient.config;
|
||||
|
||||
import com.k12study.aiclient.client.HttpPythonAiClient;
|
||||
import com.k12study.aiclient.client.PythonAiClient;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(AiClientProperties.class)
|
||||
public class AiClientAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public RestClient aiRestClient(AiClientProperties properties) {
|
||||
return RestClient.builder().baseUrl(properties.getBaseUrl()).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public PythonAiClient pythonAiClient(RestClient aiRestClient) {
|
||||
return new HttpPythonAiClient(aiRestClient);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.k12study.aiclient.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "ai.client")
|
||||
public class AiClientProperties {
|
||||
private String baseUrl = "http://localhost:9000";
|
||||
|
||||
public String getBaseUrl() {
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
public void setBaseUrl(String baseUrl) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user