41 lines
1014 B
Java
41 lines
1014 B
Java
package com.krylov.refound.ai.client;
|
|
|
|
import com.krylov.refound.ai.dto.ImageModerationResponse;
|
|
import com.krylov.refound.ai.exception.AiServerException;
|
|
import com.krylov.refound.ai.exception.AiUnavailableException;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.retry.annotation.Backoff;
|
|
import org.springframework.retry.annotation.Retryable;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class ImageModerationClient {
|
|
private final AiMultipartHttpClient client;
|
|
|
|
@Retryable(
|
|
retryFor = {
|
|
AiUnavailableException.class,
|
|
AiServerException.class
|
|
},
|
|
maxAttempts = 3,
|
|
backoff = @Backoff(
|
|
delay = 500,
|
|
multiplier = 2
|
|
)
|
|
)
|
|
public ImageModerationResponse moderate(
|
|
MultipartFile file
|
|
) {
|
|
|
|
return client.post(
|
|
"/api/v1/moderation/image",
|
|
file,
|
|
ImageModerationResponse.class
|
|
);
|
|
|
|
}
|
|
}
|