[KC-108] ai api 실행
This commit is contained in:
@@ -14,17 +14,18 @@ public class ExternalHttpClient {
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
|
||||
public ResponseEntity<String> exchange(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers) {
|
||||
public <T> ResponseEntity<T> exchange(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
HttpEntity<Object> entity = new HttpEntity<>(body, headers);
|
||||
return restTemplate.exchange(url, method, entity, String.class);
|
||||
return restTemplate.exchange(url, method, entity, responseType);
|
||||
}
|
||||
|
||||
public ExternalCallResult call(String url, HttpMethod method, Object body, HttpHeaders headers) {
|
||||
ResponseEntity<String> res = exchange(url, method, body, headers);
|
||||
public <T> ExternalCallResult<T> call(
|
||||
String url, HttpMethod method, Object body, HttpHeaders headers, Class<T> responseType) {
|
||||
ResponseEntity<T> res = exchange(url, method, body, headers, responseType);
|
||||
int code = res.getStatusCodeValue();
|
||||
return new ExternalCallResult(code, code >= 200 && code < 300, res.getBody());
|
||||
return new ExternalCallResult<>(code, code >= 200 && code < 300, res.getBody());
|
||||
}
|
||||
|
||||
public record ExternalCallResult(int statusCode, boolean success, String body) {}
|
||||
public record ExternalCallResult<T>(int statusCode, boolean success, T body) {}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.kamco.cd.kamcoback.inference.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.kamco.cd.kamcoback.common.exception.CustomApiException;
|
||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient;
|
||||
import com.kamco.cd.kamcoback.config.resttemplate.ExternalHttpClient.ExternalCallResult;
|
||||
import com.kamco.cd.kamcoback.inference.dto.InferenceDetailDto;
|
||||
@@ -34,7 +33,6 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -53,6 +51,9 @@ public class InferenceResultService {
|
||||
@Value("${inference.url}")
|
||||
private String inferenceUrl;
|
||||
|
||||
@Value("${spring.profiles.active}")
|
||||
private String profile;
|
||||
|
||||
/**
|
||||
* 추론관리 목록
|
||||
*
|
||||
@@ -205,9 +206,7 @@ public class InferenceResultService {
|
||||
private void ensureAccepted(InferenceSendDto dto) {
|
||||
log.info("dto null? {}", dto == null);
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
String json = "";
|
||||
try {
|
||||
json = om.writeValueAsString(dto);
|
||||
log.info("dto json={}", om.writeValueAsString(dto));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
@@ -217,12 +216,17 @@ public class InferenceResultService {
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.setAccept(List.of(MediaType.APPLICATION_JSON));
|
||||
|
||||
ExternalCallResult result =
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers);
|
||||
|
||||
if (!result.success()) {
|
||||
throw new CustomApiException("BAD_GATEWAY", HttpStatus.BAD_GATEWAY);
|
||||
// TODO 추후 삭제
|
||||
if ("local".equals(profile)) {
|
||||
dto.getPred_requests_areas().setInput1_scene_path("/kamco-nfs/requests/2023_local.geojson");
|
||||
dto.getPred_requests_areas().setInput2_scene_path("/kamco-nfs/requests/2024_local.geojson");
|
||||
}
|
||||
|
||||
ExternalCallResult<String> result =
|
||||
externalHttpClient.call(inferenceUrl, HttpMethod.POST, dto, headers, String.class);
|
||||
|
||||
int status = result.statusCode();
|
||||
String body = result.body();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -110,9 +110,12 @@ public class ModelMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
queryFactory
|
||||
.select(modelMngEntity.modelUid.count())
|
||||
.from(modelMngEntity)
|
||||
.innerJoin(modelResultMetricEntity)
|
||||
.on(modelMngEntity.modelUid.eq(modelResultMetricEntity.modelUid))
|
||||
.where(
|
||||
eventEndedAtBetween(startDate, endDate, property),
|
||||
searchModelVersion(modelType, searchVal))
|
||||
searchModelVersion(modelType, searchVal),
|
||||
modelMngEntity.deleted.isFalse().or(modelMngEntity.deleted.isNull()))
|
||||
.fetchOne();
|
||||
|
||||
return new PageImpl<>(foundContent, pageable, countQuery);
|
||||
|
||||
Reference in New Issue
Block a user