这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions embabel-modules/embabel-quiz-generator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>embabel-modules</artifactId>
<version>0.0.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>com.baeldung</groupId>
<artifactId>embabel-quiz-generator</artifactId>
<version>0.0.1</version>
<name>embabel-quiz-generator</name>
<description>Agent capable of generating quizzes from blogs.</description>

<dependencies>
<dependency>
<groupId>com.embabel.agent</groupId>
<artifactId>embabel-agent-starter</artifactId>
<version>${embabel-agent.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

<properties>
<java.version>21</java.version>
<embabel-agent.version>0.1.0-SNAPSHOT</embabel-agent.version>
</properties>

<repositories>
<repository>
<id>embabel-snapshots</id>
<url>https://repo.embabel.com/artifactory/libs-snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

</project>
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.baeldung.quizzard;

import java.util.List;

record Quiz(List<QuizQuestion> questions) {

record QuizQuestion(
String question,
List<String> options,
String correctAnswer
) {
}

}
Original file line number Diff line number Diff line change
@@ -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
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
embabel:
models:
default-llm: claude-opus-4-20250514
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 I can see what you were inspired by

Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions embabel-modules/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>embabel-modules</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>embabel-modules</name>

<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-3</relativePath>
</parent>

<modules>
<module>embabel-quiz-generator</module>
</modules>

</project>
2 changes: 2 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@
<module>disruptor</module>
<module>docker-modules</module>
<module>drools</module>
<module>embabel-modules</module>
<module>feign</module>
<module>gcp-firebase</module>
<module>geotools</module>
Expand Down Expand Up @@ -1085,6 +1086,7 @@
<module>disruptor</module>
<module>docker-modules</module>
<module>drools</module>
<module>embabel-modules</module>
<module>feign</module>
<module>gcp-firebase</module>
<module>geotools</module>
Expand Down