fi.evolver.ai.spring.util.SseUtils Maven / Gradle / Ivy
package fi.evolver.ai.spring.util;
import java.util.function.Consumer;
import com.fasterxml.jackson.core.JsonProcessingException;
public class SseUtils {
private SseUtils() {
}
public static void handleStreamContent(String rawResponse, Consumer chunkConsumer, Class chunkClass) throws JsonProcessingException {
for (String line : rawResponse.split("\n")) {
if (line.startsWith("data: [DONE]"))
continue;
if (line.startsWith("data:"))
chunkConsumer.accept(Json.OBJECT_MAPPER.readValue(line.substring("data:".length()), chunkClass));
}
}
public static boolean isStreamResponse(String response) {
return response != null && (response.startsWith("data:") || response.startsWith("event: message_start"));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy