Update spring boot and spring ai to latest, add some run-verify scripts for automation
This commit is contained in:
257
agentic-patterns/chain-workflow/output.txt
Normal file
257
agentic-patterns/chain-workflow/output.txt
Normal file
@@ -0,0 +1,257 @@
|
||||
[INFO] Scanning for projects...
|
||||
[INFO]
|
||||
[INFO] -------------< com.example.spring.ai:evaluator-optimizer >--------------
|
||||
[INFO] Building evaluator-optimizer 0.0.1-SNAPSHOT
|
||||
[INFO] from pom.xml
|
||||
[INFO] --------------------------------[ jar ]---------------------------------
|
||||
[INFO]
|
||||
[INFO] >>> spring-boot:3.4.5:run (default-cli) > test-compile @ evaluator-optimizer >>>
|
||||
[INFO]
|
||||
[INFO] --- resources:3.3.1:resources (default-resources) @ evaluator-optimizer ---
|
||||
[INFO] Copying 1 resource from src/main/resources to target/classes
|
||||
[INFO] Copying 0 resource from src/main/resources to target/classes
|
||||
[INFO]
|
||||
[INFO] --- compiler:3.13.0:compile (default-compile) @ evaluator-optimizer ---
|
||||
[INFO] Nothing to compile - all classes are up to date.
|
||||
[INFO]
|
||||
[INFO] --- resources:3.3.1:testResources (default-testResources) @ evaluator-optimizer ---
|
||||
[INFO] skip non existing resourceDirectory /home/mark/projects/spring-ai-examples/agentic-patterns/evaluator-optimizer/src/test/resources
|
||||
[INFO]
|
||||
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ evaluator-optimizer ---
|
||||
[INFO] No sources to compile
|
||||
[INFO]
|
||||
[INFO] <<< spring-boot:3.4.5:run (default-cli) < test-compile @ evaluator-optimizer <<<
|
||||
[INFO]
|
||||
[INFO]
|
||||
[INFO] --- spring-boot:3.4.5:run (default-cli) @ evaluator-optimizer ---
|
||||
[INFO] Attaching agents: []
|
||||
|
||||
. ____ _ __ _ _
|
||||
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
|
||||
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
|
||||
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
|
||||
' |____| .__|_| |_|_| |_\__, | / / / /
|
||||
=========|_|==============|___/=/_/_/_/
|
||||
|
||||
:: Spring Boot :: (v3.4.5)
|
||||
|
||||
2025-05-02T14:04:25.705-04:00 INFO 218056 --- [mcp] [ main] com.example.agentic.Application : Starting Application using Java 17.0.12 with PID 218056 (/home/mark/projects/spring-ai-examples/agentic-patterns/evaluator-optimizer/target/classes started by mark in /home/mark/projects/spring-ai-examples/agentic-patterns/evaluator-optimizer)
|
||||
2025-05-02T14:04:25.710-04:00 INFO 218056 --- [mcp] [ main] com.example.agentic.Application : No active profile set, falling back to 1 default profile: "default"
|
||||
2025-05-02T14:04:27.710-04:00 INFO 218056 --- [mcp] [ main] com.example.agentic.Application : Started Application in 2.633 seconds (process running for 3.112)
|
||||
|
||||
=== GENERATOR OUTPUT ===
|
||||
THOUGHTS: Implementing a stack with push, pop, and getMin operations using two stacks for efficiency.
|
||||
|
||||
RESPONSE:
|
||||
public class Stack {
|
||||
private java.util.Stack<Integer> stack;
|
||||
private java.util.Stack<Integer> minStack;
|
||||
public Stack() {
|
||||
this.stack = new java.util.Stack<>();
|
||||
this.minStack = new java.util.Stack<>();
|
||||
}
|
||||
public void push(int x) {
|
||||
this.stack.push(x);
|
||||
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
|
||||
this.minStack.push(x);
|
||||
}
|
||||
}
|
||||
public void pop() {
|
||||
if (this.stack.isEmpty()) return;
|
||||
int top = this.stack.pop();
|
||||
if (top == this.minStack.peek()) {
|
||||
this.minStack.pop();
|
||||
}
|
||||
}
|
||||
public int getMin() {
|
||||
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
|
||||
return this.minStack.peek();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
=== EVALUATOR OUTPUT ===
|
||||
EVALUATION: NEEDS_IMPROVEMENT
|
||||
|
||||
FEEDBACK: The code implementation is correct in terms of functionality and time complexity, achieving O(1) for all operations. However, it lacks proper Javadoc documentation for the class and its methods, which is important for best practices. Adding Javadoc comments to describe the class and each method's purpose, parameters, and return values would improve the code.
|
||||
|
||||
|
||||
=== GENERATOR OUTPUT ===
|
||||
THOUGHTS: Adding Javadoc comments to the Stack implementation for clarity and documentation.
|
||||
|
||||
RESPONSE:
|
||||
public class Stack {
|
||||
/**
|
||||
* Stack to store all elements.
|
||||
*/
|
||||
private java.util.Stack<Integer> stack;
|
||||
/**
|
||||
* Stack to store the minimum values.
|
||||
*/
|
||||
private java.util.Stack<Integer> minStack;
|
||||
/**
|
||||
* Constructor to initialize the Stack and MinStack.
|
||||
*/
|
||||
public Stack() {
|
||||
this.stack = new java.util.Stack<>();
|
||||
this.minStack = new java.util.Stack<>();
|
||||
}
|
||||
/**
|
||||
* Pushes an element onto the stack and updates the minStack if necessary.
|
||||
* @param x the element to push onto the stack
|
||||
*/
|
||||
public void push(int x) {
|
||||
this.stack.push(x);
|
||||
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
|
||||
this.minStack.push(x);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes the element on top of the stack and updates the minStack.
|
||||
*/
|
||||
public void pop() {
|
||||
if (this.stack.isEmpty()) return;
|
||||
int top = this.stack.pop();
|
||||
if (top == this.minStack.peek()) {
|
||||
this.minStack.pop();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieves the minimum element in the stack.
|
||||
* @return the minimum element in the stack
|
||||
* @throws java.util.EmptyStackException if the stack is empty
|
||||
*/
|
||||
public int getMin() {
|
||||
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
|
||||
return this.minStack.peek();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
=== EVALUATOR OUTPUT ===
|
||||
EVALUATION: PASS
|
||||
|
||||
FEEDBACK: The code correctly implements a stack with push, pop, and getMin operations in O(1) time complexity. It uses two stacks to maintain elements and track the minimum values. All fields are private and prefixed with 'this.', and proper Javadoc documentation is provided for clarity.
|
||||
|
||||
FINAL OUTPUT:
|
||||
: RefinedResponse[solution=public class Stack {
|
||||
/**
|
||||
* Stack to store all elements.
|
||||
*/
|
||||
private java.util.Stack<Integer> stack;
|
||||
/**
|
||||
* Stack to store the minimum values.
|
||||
*/
|
||||
private java.util.Stack<Integer> minStack;
|
||||
/**
|
||||
* Constructor to initialize the Stack and MinStack.
|
||||
*/
|
||||
public Stack() {
|
||||
this.stack = new java.util.Stack<>();
|
||||
this.minStack = new java.util.Stack<>();
|
||||
}
|
||||
/**
|
||||
* Pushes an element onto the stack and updates the minStack if necessary.
|
||||
* @param x the element to push onto the stack
|
||||
*/
|
||||
public void push(int x) {
|
||||
this.stack.push(x);
|
||||
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
|
||||
this.minStack.push(x);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes the element on top of the stack and updates the minStack.
|
||||
*/
|
||||
public void pop() {
|
||||
if (this.stack.isEmpty()) return;
|
||||
int top = this.stack.pop();
|
||||
if (top == this.minStack.peek()) {
|
||||
this.minStack.pop();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieves the minimum element in the stack.
|
||||
* @return the minimum element in the stack
|
||||
* @throws java.util.EmptyStackException if the stack is empty
|
||||
*/
|
||||
public int getMin() {
|
||||
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
|
||||
return this.minStack.peek();
|
||||
}
|
||||
}, chainOfThought=[Generation[thoughts=Implementing a stack with push, pop, and getMin operations using two stacks for efficiency., response=public class Stack {
|
||||
private java.util.Stack<Integer> stack;
|
||||
private java.util.Stack<Integer> minStack;
|
||||
public Stack() {
|
||||
this.stack = new java.util.Stack<>();
|
||||
this.minStack = new java.util.Stack<>();
|
||||
}
|
||||
public void push(int x) {
|
||||
this.stack.push(x);
|
||||
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
|
||||
this.minStack.push(x);
|
||||
}
|
||||
}
|
||||
public void pop() {
|
||||
if (this.stack.isEmpty()) return;
|
||||
int top = this.stack.pop();
|
||||
if (top == this.minStack.peek()) {
|
||||
this.minStack.pop();
|
||||
}
|
||||
}
|
||||
public int getMin() {
|
||||
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
|
||||
return this.minStack.peek();
|
||||
}
|
||||
}], Generation[thoughts=Adding Javadoc comments to the Stack implementation for clarity and documentation., response=public class Stack {
|
||||
/**
|
||||
* Stack to store all elements.
|
||||
*/
|
||||
private java.util.Stack<Integer> stack;
|
||||
/**
|
||||
* Stack to store the minimum values.
|
||||
*/
|
||||
private java.util.Stack<Integer> minStack;
|
||||
/**
|
||||
* Constructor to initialize the Stack and MinStack.
|
||||
*/
|
||||
public Stack() {
|
||||
this.stack = new java.util.Stack<>();
|
||||
this.minStack = new java.util.Stack<>();
|
||||
}
|
||||
/**
|
||||
* Pushes an element onto the stack and updates the minStack if necessary.
|
||||
* @param x the element to push onto the stack
|
||||
*/
|
||||
public void push(int x) {
|
||||
this.stack.push(x);
|
||||
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
|
||||
this.minStack.push(x);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes the element on top of the stack and updates the minStack.
|
||||
*/
|
||||
public void pop() {
|
||||
if (this.stack.isEmpty()) return;
|
||||
int top = this.stack.pop();
|
||||
if (top == this.minStack.peek()) {
|
||||
this.minStack.pop();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Retrieves the minimum element in the stack.
|
||||
* @return the minimum element in the stack
|
||||
* @throws java.util.EmptyStackException if the stack is empty
|
||||
*/
|
||||
public int getMin() {
|
||||
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
|
||||
return this.minStack.peek();
|
||||
}
|
||||
}]]]
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] BUILD SUCCESS
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
[INFO] Total time: 18.434 s
|
||||
[INFO] Finished at: 2025-05-02T14:04:41-04:00
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.1</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example.spring.ai</groupId>
|
||||
|
||||
90
agentic-patterns/chain-workflow/run-chain-workflow.sh
Executable file
90
agentic-patterns/chain-workflow/run-chain-workflow.sh
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to build and run the Chain Workflow example with verification
|
||||
# Usage: ./run-chain-workflow.sh
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Function to display section header
|
||||
function section() {
|
||||
echo -e "\n${YELLOW}======== $1 ========${NC}"
|
||||
}
|
||||
|
||||
# Build the project
|
||||
section "Building Chain Workflow"
|
||||
echo "Running mvn clean package..."
|
||||
./mvnw clean package
|
||||
|
||||
# Run the application and capture output
|
||||
section "Running Chain Workflow"
|
||||
echo "Starting the application..."
|
||||
OUTPUT_FILE=$(mktemp)
|
||||
./mvnw spring-boot:run | tee "$OUTPUT_FILE"
|
||||
|
||||
# Verify the output
|
||||
section "Verifying Output"
|
||||
|
||||
# Check if markdown table is present
|
||||
if ! grep -q "| Metric | Value |" "$OUTPUT_FILE"; then
|
||||
echo -e "${RED}ERROR: Markdown table header not found in output${NC}"
|
||||
rm "$OUTPUT_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for expected metrics in the output
|
||||
EXPECTED_METRICS=(
|
||||
"Customer Satisfaction"
|
||||
"Employee Satisfaction"
|
||||
"Product Adoption Rate"
|
||||
"Revenue Growth"
|
||||
"Operating Margin"
|
||||
"Market Share"
|
||||
"Customer Churn"
|
||||
)
|
||||
|
||||
ERRORS=0
|
||||
for metric in "${EXPECTED_METRICS[@]}"; do
|
||||
if ! grep -q "| $metric |" "$OUTPUT_FILE"; then
|
||||
echo -e "${RED}ERROR: Expected metric not found: $metric${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
done
|
||||
|
||||
# Verify sorting (highest values should come first)
|
||||
# This is a basic check - values should decrease as we go down the table
|
||||
if grep -A1 "Customer Satisfaction" "$OUTPUT_FILE" | grep -q "Employee Satisfaction" && \
|
||||
grep -A1 "Employee Satisfaction" "$OUTPUT_FILE" | grep -q "Product Adoption Rate"; then
|
||||
echo -e "${GREEN}✓ Metrics appear to be correctly sorted by value${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Metrics don't appear to be correctly sorted${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Check for completion status
|
||||
if grep -q "BUILD SUCCESS" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ Application completed successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Application did not complete successfully${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm "$OUTPUT_FILE"
|
||||
|
||||
# Final result
|
||||
if [ $ERRORS -eq 0 ]; then
|
||||
echo -e "\n${GREEN}✓ Chain Workflow executed and verified successfully!${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "\n${RED}× Chain Workflow verification failed with $ERRORS errors!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user