diff --git a/embabel-modules/embabel-quiz-generator/pom.xml b/embabel-modules/embabel-quiz-generator/pom.xml new file mode 100644 index 000000000000..b6a49c31e40b --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + + com.baeldung + embabel-modules + 0.0.1 + ../pom.xml + + + com.baeldung + embabel-quiz-generator + 0.0.1 + embabel-quiz-generator + Agent capable of generating quizzes from blogs. + + + + com.embabel.agent + embabel-agent-starter + ${embabel-agent.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + 21 + 0.1.0-SNAPSHOT + + + + + embabel-snapshots + https://repo.embabel.com/artifactory/libs-snapshot + + true + + + + + \ No newline at end of file diff --git a/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Application.java b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Application.java new file mode 100644 index 000000000000..c636bb018cd4 --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Application.java @@ -0,0 +1,20 @@ +package com.baeldung.quizzard; + +import com.embabel.agent.config.annotation.EnableAgentShell; +import com.embabel.agent.config.annotation.EnableAgents; +import com.embabel.agent.config.annotation.McpServers; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@EnableAgentShell +@SpringBootApplication +@EnableAgents(mcpServers = { + McpServers.DOCKER_DESKTOP +}) +class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Quiz.java b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Quiz.java new file mode 100644 index 000000000000..6f6c02a44573 --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/Quiz.java @@ -0,0 +1,14 @@ +package com.baeldung.quizzard; + +import java.util.List; + +record Quiz(List questions) { + + record QuizQuestion( + String question, + List options, + String correctAnswer + ) { + } + +} \ No newline at end of file diff --git a/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/QuizGeneratorAgent.java b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/QuizGeneratorAgent.java new file mode 100644 index 000000000000..c047f7026c05 --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/src/main/java/com/baeldung/quizzard/QuizGeneratorAgent.java @@ -0,0 +1,55 @@ +package com.baeldung.quizzard; + +import com.embabel.agent.api.annotation.AchievesGoal; +import com.embabel.agent.api.annotation.Action; +import com.embabel.agent.api.annotation.Agent; +import com.embabel.agent.api.common.PromptRunner; +import com.embabel.agent.core.CoreToolGroups; +import com.embabel.agent.domain.io.UserInput; +import com.embabel.agent.domain.library.Blog; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.Resource; + +import java.io.IOException; +import java.nio.charset.Charset; + +@Agent( + name = "quizzard", + description = "Generate multiple choice quizzes from blogs" +) +class QuizGeneratorAgent { + + private final Resource promptTemplate; + + QuizGeneratorAgent(@Value("classpath:prompt-templates/quiz-generation.txt") Resource promptTemplate) { + this.promptTemplate = promptTemplate; + } + + @Action(toolGroups = CoreToolGroups.WEB) + Blog fetchBlogContent(UserInput userInput) { + return PromptRunner + .usingLlm() + .createObject( + "Fetch the blog content from the URL given in the following request: '%s'".formatted(userInput), + Blog.class + ); + } + + @Action + @AchievesGoal(description = "Quiz has been generated") + Quiz generateQuiz(Blog blog) throws IOException { + String prompt = promptTemplate + .getContentAsString(Charset.defaultCharset()) + .formatted( + blog.getTitle(), + blog.getContent() + ); + return PromptRunner + .usingLlm() + .createObject( + prompt, + Quiz.class + ); + } + +} diff --git a/embabel-modules/embabel-quiz-generator/src/main/resources/application.yaml b/embabel-modules/embabel-quiz-generator/src/main/resources/application.yaml new file mode 100644 index 000000000000..10049ee57845 --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +embabel: + models: + default-llm: claude-opus-4-20250514 \ No newline at end of file diff --git a/embabel-modules/embabel-quiz-generator/src/main/resources/prompt-templates/quiz-generation.txt b/embabel-modules/embabel-quiz-generator/src/main/resources/prompt-templates/quiz-generation.txt new file mode 100644 index 000000000000..1ca0c78ddd0f --- /dev/null +++ b/embabel-modules/embabel-quiz-generator/src/main/resources/prompt-templates/quiz-generation.txt @@ -0,0 +1,13 @@ +Generate multiple choice questions based on the following blog content: + +Blog title: %s +Blog content: %s + +Requirements: +- Create exactly 5 questions +- Each question must have exactly 4 options +- Each question must have only one correct answer +- The difficulty level of the questions should be intermediate +- Questions should test understanding of key concepts from the blog +- Make the incorrect options plausible but clearly wrong +- Questions should be clear and unambiguous diff --git a/embabel-modules/pom.xml b/embabel-modules/pom.xml new file mode 100644 index 000000000000..8b0b11bec684 --- /dev/null +++ b/embabel-modules/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + embabel-modules + 0.0.1 + pom + embabel-modules + + + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../parent-boot-3 + + + + embabel-quiz-generator + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f3ec488d4933..cf6f3622e51d 100644 --- a/pom.xml +++ b/pom.xml @@ -649,6 +649,7 @@ disruptor docker-modules drools + embabel-modules feign gcp-firebase geotools @@ -1085,6 +1086,7 @@ disruptor docker-modules drools + embabel-modules feign gcp-firebase geotools