Skip to content

Commit cba325a

Browse files
committed
Update spring boot and spring ai to latest, add some run-verify scripts for automation
1 parent 234d3ff commit cba325a

File tree

38 files changed

+682
-51
lines changed

38 files changed

+682
-51
lines changed
Lines changed: 257 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,257 @@
1+
[INFO] Scanning for projects...
2+
[INFO]
3+
[INFO] -------------< com.example.spring.ai:evaluator-optimizer >--------------
4+
[INFO] Building evaluator-optimizer 0.0.1-SNAPSHOT
5+
[INFO] from pom.xml
6+
[INFO] --------------------------------[ jar ]---------------------------------
7+
[INFO]
8+
[INFO] >>> spring-boot:3.4.5:run (default-cli) > test-compile @ evaluator-optimizer >>>
9+
[INFO]
10+
[INFO] --- resources:3.3.1:resources (default-resources) @ evaluator-optimizer ---
11+
[INFO] Copying 1 resource from src/main/resources to target/classes
12+
[INFO] Copying 0 resource from src/main/resources to target/classes
13+
[INFO]
14+
[INFO] --- compiler:3.13.0:compile (default-compile) @ evaluator-optimizer ---
15+
[INFO] Nothing to compile - all classes are up to date.
16+
[INFO]
17+
[INFO] --- resources:3.3.1:testResources (default-testResources) @ evaluator-optimizer ---
18+
[INFO] skip non existing resourceDirectory /home/mark/projects/spring-ai-examples/agentic-patterns/evaluator-optimizer/src/test/resources
19+
[INFO]
20+
[INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ evaluator-optimizer ---
21+
[INFO] No sources to compile
22+
[INFO]
23+
[INFO] <<< spring-boot:3.4.5:run (default-cli) < test-compile @ evaluator-optimizer <<<
24+
[INFO]
25+
[INFO]
26+
[INFO] --- spring-boot:3.4.5:run (default-cli) @ evaluator-optimizer ---
27+
[INFO] Attaching agents: []
28+
29+
. ____ _ __ _ _
30+
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
31+
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
32+
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
33+
' |____| .__|_| |_|_| |_\__, | / / / /
34+
=========|_|==============|___/=/_/_/_/
35+
36+
:: Spring Boot :: (v3.4.5)
37+
38+
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)
39+
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"
40+
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)
41+
42+
=== GENERATOR OUTPUT ===
43+
THOUGHTS: Implementing a stack with push, pop, and getMin operations using two stacks for efficiency.
44+
45+
RESPONSE:
46+
public class Stack {
47+
private java.util.Stack<Integer> stack;
48+
private java.util.Stack<Integer> minStack;
49+
public Stack() {
50+
this.stack = new java.util.Stack<>();
51+
this.minStack = new java.util.Stack<>();
52+
}
53+
public void push(int x) {
54+
this.stack.push(x);
55+
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
56+
this.minStack.push(x);
57+
}
58+
}
59+
public void pop() {
60+
if (this.stack.isEmpty()) return;
61+
int top = this.stack.pop();
62+
if (top == this.minStack.peek()) {
63+
this.minStack.pop();
64+
}
65+
}
66+
public int getMin() {
67+
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
68+
return this.minStack.peek();
69+
}
70+
}
71+
72+
73+
=== EVALUATOR OUTPUT ===
74+
EVALUATION: NEEDS_IMPROVEMENT
75+
76+
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.
77+
78+
79+
=== GENERATOR OUTPUT ===
80+
THOUGHTS: Adding Javadoc comments to the Stack implementation for clarity and documentation.
81+
82+
RESPONSE:
83+
public class Stack {
84+
/**
85+
* Stack to store all elements.
86+
*/
87+
private java.util.Stack<Integer> stack;
88+
/**
89+
* Stack to store the minimum values.
90+
*/
91+
private java.util.Stack<Integer> minStack;
92+
/**
93+
* Constructor to initialize the Stack and MinStack.
94+
*/
95+
public Stack() {
96+
this.stack = new java.util.Stack<>();
97+
this.minStack = new java.util.Stack<>();
98+
}
99+
/**
100+
* Pushes an element onto the stack and updates the minStack if necessary.
101+
* @param x the element to push onto the stack
102+
*/
103+
public void push(int x) {
104+
this.stack.push(x);
105+
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
106+
this.minStack.push(x);
107+
}
108+
}
109+
/**
110+
* Removes the element on top of the stack and updates the minStack.
111+
*/
112+
public void pop() {
113+
if (this.stack.isEmpty()) return;
114+
int top = this.stack.pop();
115+
if (top == this.minStack.peek()) {
116+
this.minStack.pop();
117+
}
118+
}
119+
/**
120+
* Retrieves the minimum element in the stack.
121+
* @return the minimum element in the stack
122+
* @throws java.util.EmptyStackException if the stack is empty
123+
*/
124+
public int getMin() {
125+
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
126+
return this.minStack.peek();
127+
}
128+
}
129+
130+
131+
=== EVALUATOR OUTPUT ===
132+
EVALUATION: PASS
133+
134+
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.
135+
136+
FINAL OUTPUT:
137+
: RefinedResponse[solution=public class Stack {
138+
/**
139+
* Stack to store all elements.
140+
*/
141+
private java.util.Stack<Integer> stack;
142+
/**
143+
* Stack to store the minimum values.
144+
*/
145+
private java.util.Stack<Integer> minStack;
146+
/**
147+
* Constructor to initialize the Stack and MinStack.
148+
*/
149+
public Stack() {
150+
this.stack = new java.util.Stack<>();
151+
this.minStack = new java.util.Stack<>();
152+
}
153+
/**
154+
* Pushes an element onto the stack and updates the minStack if necessary.
155+
* @param x the element to push onto the stack
156+
*/
157+
public void push(int x) {
158+
this.stack.push(x);
159+
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
160+
this.minStack.push(x);
161+
}
162+
}
163+
/**
164+
* Removes the element on top of the stack and updates the minStack.
165+
*/
166+
public void pop() {
167+
if (this.stack.isEmpty()) return;
168+
int top = this.stack.pop();
169+
if (top == this.minStack.peek()) {
170+
this.minStack.pop();
171+
}
172+
}
173+
/**
174+
* Retrieves the minimum element in the stack.
175+
* @return the minimum element in the stack
176+
* @throws java.util.EmptyStackException if the stack is empty
177+
*/
178+
public int getMin() {
179+
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
180+
return this.minStack.peek();
181+
}
182+
}, chainOfThought=[Generation[thoughts=Implementing a stack with push, pop, and getMin operations using two stacks for efficiency., response=public class Stack {
183+
private java.util.Stack<Integer> stack;
184+
private java.util.Stack<Integer> minStack;
185+
public Stack() {
186+
this.stack = new java.util.Stack<>();
187+
this.minStack = new java.util.Stack<>();
188+
}
189+
public void push(int x) {
190+
this.stack.push(x);
191+
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
192+
this.minStack.push(x);
193+
}
194+
}
195+
public void pop() {
196+
if (this.stack.isEmpty()) return;
197+
int top = this.stack.pop();
198+
if (top == this.minStack.peek()) {
199+
this.minStack.pop();
200+
}
201+
}
202+
public int getMin() {
203+
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
204+
return this.minStack.peek();
205+
}
206+
}], Generation[thoughts=Adding Javadoc comments to the Stack implementation for clarity and documentation., response=public class Stack {
207+
/**
208+
* Stack to store all elements.
209+
*/
210+
private java.util.Stack<Integer> stack;
211+
/**
212+
* Stack to store the minimum values.
213+
*/
214+
private java.util.Stack<Integer> minStack;
215+
/**
216+
* Constructor to initialize the Stack and MinStack.
217+
*/
218+
public Stack() {
219+
this.stack = new java.util.Stack<>();
220+
this.minStack = new java.util.Stack<>();
221+
}
222+
/**
223+
* Pushes an element onto the stack and updates the minStack if necessary.
224+
* @param x the element to push onto the stack
225+
*/
226+
public void push(int x) {
227+
this.stack.push(x);
228+
if (this.minStack.isEmpty() || x <= this.minStack.peek()) {
229+
this.minStack.push(x);
230+
}
231+
}
232+
/**
233+
* Removes the element on top of the stack and updates the minStack.
234+
*/
235+
public void pop() {
236+
if (this.stack.isEmpty()) return;
237+
int top = this.stack.pop();
238+
if (top == this.minStack.peek()) {
239+
this.minStack.pop();
240+
}
241+
}
242+
/**
243+
* Retrieves the minimum element in the stack.
244+
* @return the minimum element in the stack
245+
* @throws java.util.EmptyStackException if the stack is empty
246+
*/
247+
public int getMin() {
248+
if (this.minStack.isEmpty()) throw new java.util.EmptyStackException();
249+
return this.minStack.peek();
250+
}
251+
}]]]
252+
[INFO] ------------------------------------------------------------------------
253+
[INFO] BUILD SUCCESS
254+
[INFO] ------------------------------------------------------------------------
255+
[INFO] Total time: 18.434 s
256+
[INFO] Finished at: 2025-05-02T14:04:41-04:00
257+
[INFO] ------------------------------------------------------------------------

agentic-patterns/chain-workflow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.4.1</version>
9+
<version>3.4.5</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.example.spring.ai</groupId>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/bin/bash
2+
3+
# Script to build and run the Chain Workflow example with verification
4+
# Usage: ./run-chain-workflow.sh
5+
6+
set -e
7+
8+
# Colors for output
9+
GREEN='\033[0;32m'
10+
RED='\033[0;31m'
11+
YELLOW='\033[0;33m'
12+
NC='\033[0m' # No Color
13+
14+
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
15+
cd "$SCRIPT_DIR"
16+
17+
# Function to display section header
18+
function section() {
19+
echo -e "\n${YELLOW}======== $1 ========${NC}"
20+
}
21+
22+
# Build the project
23+
section "Building Chain Workflow"
24+
echo "Running mvn clean package..."
25+
./mvnw clean package
26+
27+
# Run the application and capture output
28+
section "Running Chain Workflow"
29+
echo "Starting the application..."
30+
OUTPUT_FILE=$(mktemp)
31+
./mvnw spring-boot:run | tee "$OUTPUT_FILE"
32+
33+
# Verify the output
34+
section "Verifying Output"
35+
36+
# Check if markdown table is present
37+
if ! grep -q "| Metric | Value |" "$OUTPUT_FILE"; then
38+
echo -e "${RED}ERROR: Markdown table header not found in output${NC}"
39+
rm "$OUTPUT_FILE"
40+
exit 1
41+
fi
42+
43+
# Check for expected metrics in the output
44+
EXPECTED_METRICS=(
45+
"Customer Satisfaction"
46+
"Employee Satisfaction"
47+
"Product Adoption Rate"
48+
"Revenue Growth"
49+
"Operating Margin"
50+
"Market Share"
51+
"Customer Churn"
52+
)
53+
54+
ERRORS=0
55+
for metric in "${EXPECTED_METRICS[@]}"; do
56+
if ! grep -q "| $metric |" "$OUTPUT_FILE"; then
57+
echo -e "${RED}ERROR: Expected metric not found: $metric${NC}"
58+
ERRORS=$((ERRORS+1))
59+
fi
60+
done
61+
62+
# Verify sorting (highest values should come first)
63+
# This is a basic check - values should decrease as we go down the table
64+
if grep -A1 "Customer Satisfaction" "$OUTPUT_FILE" | grep -q "Employee Satisfaction" && \
65+
grep -A1 "Employee Satisfaction" "$OUTPUT_FILE" | grep -q "Product Adoption Rate"; then
66+
echo -e "${GREEN}✓ Metrics appear to be correctly sorted by value${NC}"
67+
else
68+
echo -e "${RED}ERROR: Metrics don't appear to be correctly sorted${NC}"
69+
ERRORS=$((ERRORS+1))
70+
fi
71+
72+
# Check for completion status
73+
if grep -q "BUILD SUCCESS" "$OUTPUT_FILE"; then
74+
echo -e "${GREEN}✓ Application completed successfully${NC}"
75+
else
76+
echo -e "${RED}ERROR: Application did not complete successfully${NC}"
77+
ERRORS=$((ERRORS+1))
78+
fi
79+
80+
# Clean up
81+
rm "$OUTPUT_FILE"
82+
83+
# Final result
84+
if [ $ERRORS -eq 0 ]; then
85+
echo -e "\n${GREEN}✓ Chain Workflow executed and verified successfully!${NC}"
86+
exit 0
87+
else
88+
echo -e "\n${RED}× Chain Workflow verification failed with $ERRORS errors!${NC}"
89+
exit 1
90+
fi

agentic-patterns/evaluator-optimizer/pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.4.1</version>
9+
<version>3.4.5</version>
1010
<relativePath /> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.example.spring.ai</groupId>
@@ -16,7 +16,7 @@
1616
<description>Demo project for Spring Boot</description>
1717
<properties>
1818
<java.version>17</java.version>
19-
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
19+
<spring-ai.version>1.0.0-M8</spring-ai.version>
2020
</properties>
2121
<dependencies>
2222
<dependency>
@@ -25,16 +25,16 @@
2525
</dependency>
2626

2727

28-
<!-- <dependency>
29-
<groupId>org.springframework.ai</groupId>
30-
<artifactId>spring-ai-starter-model-openai</artifactId>
31-
</dependency> -->
32-
3328
<dependency>
3429
<groupId>org.springframework.ai</groupId>
35-
<artifactId>spring-ai-starter-model-anthropic</artifactId>
30+
<artifactId>spring-ai-starter-model-openai</artifactId>
3631
</dependency>
3732

33+
<!-- <dependency>-->
34+
<!-- <groupId>org.springframework.ai</groupId>-->
35+
<!-- <artifactId>spring-ai-starter-model-anthropic</artifactId>-->
36+
<!-- </dependency>-->
37+
3838

3939
<!-- <dependency>
4040
<groupId>org.springframework.ai</groupId>

0 commit comments

Comments
 (0)