s3 bucket integration for image storage
This commit is contained in:
@@ -3,12 +3,10 @@ package com.aiteacher.document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Generates a clinical text description for an extracted figure image
|
||||
* using the OpenAI vision model via Spring AI ChatClient.
|
||||
@@ -32,17 +30,16 @@ public class VisionDescriptionService {
|
||||
/**
|
||||
* Returns a description string. Falls back to the provided caption if vision fails.
|
||||
*/
|
||||
public String describe(Path imagePath, String captionFallback) {
|
||||
public String describe(byte[] imageBytes, String captionFallback) {
|
||||
try {
|
||||
return chatClient.prompt()
|
||||
.user(u -> u
|
||||
.text(PROMPT)
|
||||
.media(MimeTypeUtils.IMAGE_PNG, new FileSystemResource(imagePath.toFile())))
|
||||
.media(MimeTypeUtils.IMAGE_PNG, new ByteArrayResource(imageBytes)))
|
||||
.call()
|
||||
.content();
|
||||
} catch (Exception ex) {
|
||||
log.warn("Vision description failed for {}: {} — using caption as fallback",
|
||||
imagePath.getFileName(), ex.getMessage());
|
||||
log.warn("Vision description failed: {} — using caption as fallback", ex.getMessage());
|
||||
return captionFallback != null ? captionFallback : "Figure";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user