public static String formatPromptBookAnalysis()

in sessions/fall24/books-genai-vertex-langchain4j/src/main/java/services/utility/PromptUtility.java [78:104]


    public static String formatPromptBookAnalysis(BookRequest bookRequest, List<Map<String, Object>> bookPages, List<String> keywords) {
        String promptBookAnalysis = "Provide an analysis of the book %s by %s " +
                "with the skills of a literary critic." +
                "What factor do the following %s " +
                "play in the narrative of the book. " +
                "Please use these paragraphs delimited by triple backquotes from the book :\n" +
                "```%s```";

        // Check for an empty topics list
        List<String> params = keywords.stream()
                .filter(Objects::nonNull)  // Filters out null values
                .filter(k -> k instanceof String && !((String) k).isEmpty()) // Filters out empty strings
                .collect(Collectors.toList());

        if ( (params==null || params.isEmpty()) && bookPages.isEmpty()) {
            return ""; // Or other default message
        }

        logger.info(params+"");

        String context = "";
        for(Map<String, Object> page: bookPages) {
            context += page.get("page")+" ";
        }

        return String.format(promptBookAnalysis, bookRequest.book(), bookRequest.author(), String.join(", ", params), context);
    }