1+ #! /bin/bash
2+
3+ # Script to download and setup Spring Boot CLI
4+
5+ # Check if spring-boot-cli directory exists and remove it if it does
6+ if [ -d " spring-boot-cli" ]; then
7+ echo " Found existing spring-boot-cli directory, removing it..."
8+ rm -rf spring-boot-cli
9+ fi
10+
11+ echo " Downloading Spring Boot CLI 3.5.0..."
12+ curl -L https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-cli/3.5.0/spring-boot-cli-3.5.0-bin.zip -o spring-boot-cli-3.5.0-bin.zip
13+
14+ echo " Creating spring-boot-cli directory..."
15+ mkdir -p spring-boot-cli
16+
17+ echo " Extracting Spring Boot CLI to spring-boot-cli folder..."
18+ unzip -q spring-boot-cli-3.5.0-bin.zip -d spring-boot-cli
19+
20+ echo " Cleaning up zip file..."
21+ rm spring-boot-cli-3.5.0-bin.zip
22+
23+ echo " Spring Boot CLI setup complete!"
24+ echo " You can find the CLI in the spring-boot-cli directory."
25+
26+ # Check if assistant directory exists and remove it if it does
27+ if [ -d " assistant" ]; then
28+ echo " Found existing assistant directory, removing it..."
29+ rm -rf assistant
30+ fi
31+
32+ echo " "
33+ echo " About to initialize Spring Boot project with the following command:"
34+ echo -e " \033[1m./spring-boot-cli/spring-3.5.0/bin/spring init --java-version=21 \033[0m"
35+ echo " --build=maven \\ "
36+ echo " --packaging=jar \\ "
37+ echo " --type=maven-project \\ "
38+ echo " --artifact-id=assistant \\ "
39+ echo " --name=assistant \\ "
40+ echo " --group-id=com.example \\ "
41+ echo -e " \033[1m--dependencies=web,thymeleaf,spring-ai-bedrock-converse \033[0m\\ "
42+ echo " --extract \\ "
43+ echo " assistant"
44+
45+ echo " "
46+ echo " Press any key to continue with Spring initialization..."
47+ read -n 1 -s
48+
49+ echo " "
50+ echo " Initializing Spring Boot project..."
51+ ./spring-boot-cli/spring-3.5.0/bin/spring init --java-version=21 \
52+ --build=maven \
53+ --packaging=jar \
54+ --type=maven-project \
55+ --artifact-id=assistant \
56+ --name=assistant \
57+ --group-id=com.example \
58+ --dependencies=web,thymeleaf,spring-ai-bedrock-converse \
59+ --extract \
60+ assistant
61+
62+ echo " "
63+ echo " Configuring application.properties..."
64+ cd assistant
65+ cat > src/main/resources/application.properties << 'EOL '
66+ # Simplified logging pattern - only show the message
67+ logging.pattern.console=%msg%n
68+
69+ # Debugging
70+ logging.level.org.springframework.ai=DEBUG
71+ spring.ai.chat.observations.log-completion=true
72+ spring.ai.chat.observations.include-error-logging=true
73+ spring.ai.tools.observations.include-content=true
74+
75+ # Thymeleaf Configuration
76+ spring.thymeleaf.cache=false
77+ spring.thymeleaf.prefix=classpath:/templates/
78+ spring.thymeleaf.suffix=.html
79+
80+ # Amazon Bedrock Configuration
81+ spring.ai.bedrock.aws.region=us-east-1
82+ spring.ai.bedrock.converse.chat.options.max-tokens=10000
83+ spring.ai.bedrock.converse.chat.options.model=us.anthropic.claude-3-7-sonnet-20250219-v1:0
84+ EOL
85+
86+ echo " "
87+ echo " Opening files in VS Code..."
88+ code pom.xml
89+ code src/main/java/com/example/assistant/AssistantApplication.java
90+ code src/main/resources/application.properties
91+
92+ echo " "
93+ echo " Press any key to continue with updating AssistantApplication.java..."
94+ read -n 1 -s
95+
96+ echo " "
97+ echo " Updating AssistantApplication.java with CommandLineRunner..."
98+ cat > src/main/java/com/example/assistant/AssistantApplication.java << 'EOL '
99+ package com.example.assistant;
100+
101+ import org.springframework.boot.SpringApplication;
102+ import org.springframework.boot.autoconfigure.SpringBootApplication;
103+
104+ import org.springframework.ai.chat.client.ChatClient;
105+ import org.springframework.boot.CommandLineRunner;
106+ import org.springframework.context.annotation.Bean;
107+ import java.util.Scanner;
108+
109+ @SpringBootApplication
110+ public class AssistantApplication {
111+
112+ public static void main(String[] args) {
113+ SpringApplication.run(AssistantApplication.class, args);
114+ }
115+
116+ @Bean
117+ public CommandLineRunner cli(ChatClient.Builder chatClientBuilder) {
118+ return args -> {
119+ var chatClient = chatClientBuilder
120+ .defaultSystem("You are a AI Assistant, expert in all sorts of things related to travel and expenses management.")
121+ .build();
122+
123+ System.out.println("\nI am your AI Assistant.\n");
124+ try (Scanner scanner = new Scanner(System.in)) {
125+ while (true) {
126+ System.out.print("\nUSER: ");
127+ System.out.println("\nASSISTANT: " +
128+ chatClient.prompt(scanner.nextLine()) // Get the user input
129+ .call()
130+ .content());
131+ }
132+ }
133+ };
134+ }
135+ }
136+ EOL
137+
138+ echo " "
139+ echo " Building the project with Maven..."
140+ ./mvnw spring-boot:run -Dspring-boot.run.arguments=" --logging.level.org.springframework.ai=INFO"
141+
142+ echo " "
143+ echo " Press any key after you've exited the application..."
144+ read -n 1 -s
145+
146+ echo " "
147+ echo " Reverting AssistantApplication.java to original state..."
148+ cat > src/main/java/com/example/assistant/AssistantApplication.java << 'EOL '
149+ package com.example.assistant;
150+
151+ import org.springframework.boot.SpringApplication;
152+ import org.springframework.boot.autoconfigure.SpringBootApplication;
153+
154+ @SpringBootApplication
155+ public class AssistantApplication {
156+
157+ public static void main(String[] args) {
158+ SpringApplication.run(AssistantApplication.class, args);
159+ }
160+ }
161+ EOL
162+
163+ echo " "
164+ echo " Initializing Git repository..."
165+ git init
166+ git add .
167+ git commit -m " Create project"
168+
169+ cd ..
0 commit comments