added ai-moderation image and text

This commit is contained in:
SlimusMinus
2026-07-29 00:56:32 +03:00
parent 7899ebcfb0
commit a6fb187212
34 changed files with 708 additions and 8 deletions

View File

@@ -0,0 +1,52 @@
package com.krylov.refound.ai.client;
import com.krylov.refound.ai.exception.AiBadRequestException;
import com.krylov.refound.ai.exception.AiServerException;
import com.krylov.refound.ai.exception.AiUnavailableException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
@Slf4j
@Component
@RequiredArgsConstructor
public class AiHttpClient {
private final WebClient aiWebClient;
public <T, R> R post(String uri, T request, Class<R> responseType) {
log.info("AI POST {}", uri);
try {
R response = aiWebClient.post()
.uri(uri)
.bodyValue(request)
.retrieve()
.onStatus(
HttpStatusCode::is4xxClientError,
resp -> resp.bodyToMono(String.class)
.map(AiBadRequestException::new)
)
.onStatus(
HttpStatusCode::is5xxServerError,
resp -> resp.bodyToMono(String.class)
.map(AiServerException::new)
)
.bodyToMono(responseType)
.block();
log.info("AI response received");
return response;
} catch (WebClientRequestException ex) {
log.error("AI connection failed", ex);
throw new AiUnavailableException(ex);
} catch (Exception ex) {
log.error("AI request failed", ex);
throw new AiUnavailableException(ex);
}
}
}