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
|
||||
@@ -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>
|
||||
@@ -16,7 +16,7 @@
|
||||
<description>Demo project for Spring Boot</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
|
||||
<spring-ai.version>1.0.0-M8</spring-ai.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -25,16 +25,16 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||
</dependency> -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-starter-model-anthropic</artifactId>
|
||||
<artifactId>spring-ai-starter-model-openai</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.ai</groupId>-->
|
||||
<!-- <artifactId>spring-ai-starter-model-anthropic</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
|
||||
141
agentic-patterns/evaluator-optimizer/run-evaluator-optimizer.sh
Executable file
141
agentic-patterns/evaluator-optimizer/run-evaluator-optimizer.sh
Executable file
@@ -0,0 +1,141 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to build and run the Evaluator-Optimizer example with verification
|
||||
# Usage: ./run-evaluator-optimizer.sh
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
# Initialize error counter
|
||||
ERRORS=0
|
||||
|
||||
# Function to display section header
|
||||
function section() {
|
||||
echo -e "\n${YELLOW}======== $1 ========${NC}"
|
||||
}
|
||||
|
||||
# Build the project
|
||||
section "Building Evaluator-Optimizer"
|
||||
echo "Running mvn clean package..."
|
||||
if ! ./mvnw clean package; then
|
||||
echo -e "${RED}Build failed! Cannot continue.${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run the application and capture output
|
||||
section "Running Evaluator-Optimizer"
|
||||
echo "Starting the application..."
|
||||
OUTPUT_FILE=$(mktemp)
|
||||
./mvnw spring-boot:run | tee "$OUTPUT_FILE" || true
|
||||
|
||||
section "Verifying Output"
|
||||
|
||||
# Check if the application completed successfully
|
||||
if ! grep -q "BUILD SUCCESS" "$OUTPUT_FILE"; then
|
||||
echo -e "${RED}ERROR: Application did not complete successfully${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Check for PASS evaluation in the final output
|
||||
if grep -q "EVALUATION: PASS" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ Final evaluation PASSED${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Final evaluation did not PASS${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Check for FINAL OUTPUT message
|
||||
if grep -q "FINAL OUTPUT:" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ Final output generated successfully${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Final output not found${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
section "Checking Stack Implementation Requirements"
|
||||
|
||||
# 1. Check for push method
|
||||
if grep -q "public void push" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ push(x) method implemented correctly${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: push method not implemented correctly${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 2. Check for pop method
|
||||
if grep -q "public void pop" "$OUTPUT_FILE" || grep -q "public int pop" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ pop() method implemented correctly${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: pop method not implemented correctly${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 3. Check for getMin method
|
||||
if grep -q "public int getMin" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ getMin() method implemented correctly${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: getMin method not implemented correctly${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 4. Check for private fields
|
||||
if grep -q "private" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ private fields used${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: private fields not found${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 5. Check for 'this.' keyword usage
|
||||
if grep -q "this\." "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ 'this.' keyword used correctly${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: 'this.' keyword usage not found${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 6. Check for JavaDoc style comments
|
||||
if grep -q "\/\*\*" "$OUTPUT_FILE" && grep -q "\* @" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ JavaDoc documentation present${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: JavaDoc documentation not properly implemented${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# 7. Check for O(1) operations mention
|
||||
if grep -q "O(1)" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ O(1) operations confirmed${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: O(1) operations not confirmed${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Verify iterative improvement process
|
||||
if grep -q "NEEDS_IMPROVEMENT" "$OUTPUT_FILE" && grep -q "PASS" "$OUTPUT_FILE"; then
|
||||
echo -e "${GREEN}✓ Iterative improvement process confirmed (NEEDS_IMPROVEMENT → PASS)${NC}"
|
||||
echo -e "${CYAN} The evaluator-optimizer workflow is functioning correctly!${NC}"
|
||||
else
|
||||
echo -e "${RED}ERROR: Could not verify iterative improvement process${NC}"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
rm "$OUTPUT_FILE"
|
||||
|
||||
# Final result
|
||||
if [ $ERRORS -eq 0 ]; then
|
||||
echo -e "\n${GREEN}✓ Evaluator-Optimizer executed and verified successfully!${NC}"
|
||||
echo -e "${GREEN}✓ Stack implementation meets all requirements.${NC}"
|
||||
exit 0
|
||||
else
|
||||
echo -e "\n${RED}× Evaluator-Optimizer verification failed with $ERRORS errors!${NC}"
|
||||
exit 1
|
||||
fi
|
||||
@@ -3,7 +3,7 @@ spring.main.web-application-type=none
|
||||
|
||||
# OpenAI
|
||||
spring.ai.openai.api-key=${OPENAI_API_KEY}
|
||||
|
||||
spring.ai.openai.chat.options.model=gpt-4o
|
||||
# Anthropic
|
||||
spring.ai.anthropic.api-key=${ANTHROPIC_API_KEY}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.5</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.5</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.5</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.5</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.7-SNAPSHOT</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.example.java_ai_function_callback;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.tool.ToolCallback;
|
||||
import org.springframework.ai.tool.function.FunctionToolCallback;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringAiJavaFunctionCallbackApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SpringAiJavaFunctionCallbackApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner init(ChatClient.Builder chatClientBuilder) {
|
||||
return args -> {
|
||||
try {
|
||||
ChatClient chatClient = chatClientBuilder.build();
|
||||
ChatResponse response = chatClient
|
||||
.prompt("What are the weather conditions in San Francisco, Tokyo, and Paris? Find the temperature in Celsius for each of the three locations.")
|
||||
.toolNames("WeatherInfo")
|
||||
.call().chatResponse();
|
||||
|
||||
System.out.println("Response: " + response);
|
||||
System.out.println("Exiting successfully");
|
||||
System.exit(0);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error during weather check: " + e.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public enum Unit {
|
||||
C("metric"),
|
||||
F("imperial");
|
||||
|
||||
private final String unitName;
|
||||
|
||||
Unit(String unitName) {
|
||||
this.unitName = unitName;
|
||||
}
|
||||
|
||||
public String getUnitName() {
|
||||
return unitName;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public ToolCallback weatherFunctionInfo(Function<WeatherRequest, WeatherResponse> currentWeather) {
|
||||
return FunctionToolCallback.builder("WeatherInfo", currentWeather)
|
||||
.description(
|
||||
"Find the weather conditions, forecasts, and temperatures for a location, like a city or state."
|
||||
)
|
||||
.inputType(WeatherRequest.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<WeatherRequest, WeatherResponse> currentWeather() {
|
||||
return request -> new MockJavaWeatherService().apply(request);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class MockJavaWeatherService implements Function<WeatherRequest, WeatherResponse> {
|
||||
|
||||
@Override
|
||||
public WeatherResponse apply(WeatherRequest weatherRequest) {
|
||||
double temperature = 10.0;
|
||||
if (weatherRequest.getLocation().contains("Paris")) {
|
||||
temperature = 15.0;
|
||||
}
|
||||
else if (weatherRequest.getLocation().contains("Tokyo")) {
|
||||
temperature = 10.0;
|
||||
}
|
||||
else if (weatherRequest.getLocation().contains("San Francisco")) {
|
||||
temperature = 30.0;
|
||||
}
|
||||
|
||||
return new WeatherResponse(temperature, 15.0, 20.0, 2.0, 53, 45, Unit.C);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
mark@feynman.187885:1746111141
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.example.java_ai_function_callback;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class SpringAiJavaFunctionCallbackApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.3</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.6</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.4.4</version>
|
||||
<version>3.4.5</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>org.springframework.ai.example</groupId>
|
||||
|
||||
58
run-example.sh
Executable file
58
run-example.sh
Executable file
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to build and run Spring AI examples
|
||||
# Usage: ./run-example.sh <project-directory-name>
|
||||
# Example: ./run-example.sh agentic-patterns/chain-workflow
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Base directory for Spring AI examples
|
||||
BASE_DIR=$(dirname "$(readlink -f "$0")")
|
||||
|
||||
# Check if project name is provided
|
||||
if [ -z "$1" ]; then
|
||||
echo -e "${RED}Error: Project directory not specified${NC}"
|
||||
echo "Usage: ./run-example.sh <project-directory-name>"
|
||||
echo "Example: ./run-example.sh agentic-patterns/chain-workflow"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PROJECT_PATH="$BASE_DIR/$1"
|
||||
|
||||
# Check if project directory exists
|
||||
if [ ! -d "$PROJECT_PATH" ]; then
|
||||
echo -e "${RED}Error: Project directory not found: $PROJECT_PATH${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if pom.xml exists
|
||||
if [ ! -f "$PROJECT_PATH/pom.xml" ]; then
|
||||
echo -e "${RED}Error: pom.xml not found in $PROJECT_PATH${NC}"
|
||||
echo "This script is for Maven-based Spring AI examples only."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Function to display section header
|
||||
function section() {
|
||||
echo -e "\n${YELLOW}======== $1 ========${NC}"
|
||||
}
|
||||
|
||||
# Navigate to project directory
|
||||
cd "$PROJECT_PATH"
|
||||
PROJECT_NAME=$(basename "$PROJECT_PATH")
|
||||
|
||||
section "Building $PROJECT_NAME"
|
||||
echo "Running mvn clean package..."
|
||||
./mvnw clean package
|
||||
|
||||
section "Running $PROJECT_NAME"
|
||||
echo "Starting the application..."
|
||||
./mvnw spring-boot:run
|
||||
|
||||
echo -e "\n${GREEN}Execution completed successfully!${NC}"
|
||||
Reference in New Issue
Block a user