@@ -52,17 +52,21 @@ quarkus.langchain4j.openai.timeout=60s
52
52
53
53
%dev.quarkus.mailer.mock=false
54
54
55
- quarkus.langchain4j.openai.chat-model.temperature=0.0 #<1>
56
- quarkus.langchain4j.easy-rag.path=src/main/resources/catalog #<2>
55
+ quarkus.langchain4j.openai.chat-model.temperature=0.0
56
+ quarkus.langchain4j.easy-rag.path=src/main/resources/catalog
57
57
58
- booking.daystostart=1
58
+ booking.daystostart=1 #<3>
59
59
booking.daystoend=3
60
+ booking.firstname=john
61
+ booking.lastname=doe
62
+ booking.number=123-456
60
63
61
- quarkus.langchain4j.openai.chat-model.model-name=gpt-4o #<3 >
64
+ quarkus.langchain4j.openai.chat-model.model-name=gpt-4o #<4 >
62
65
----
63
66
<1> The "temperature" parameter in AI language models controls the randomness of text generation. Lower values result in more predictable outputs, while higher values encourage creativity and diversity in responses.
64
67
<2> Path to where documents are stored for the Retrieval Augmentation Generation (ie. the documents the AI model will use to build local knowledge)
65
- <3> The specific model to use. IMPORTANT: gpt3.5-turbo is much cheaper but the results will be slower and less reliable.
68
+ <3> Sample booking data
69
+ <4> The specific model to use. IMPORTANT: gpt3.5-turbo is much cheaper but the results will be slower and less reliable.
66
70
67
71
68
72
== Embedding the business document
@@ -162,27 +166,24 @@ Create a new `BookingService` Java class in `src/main/java` in the `com.redhat.d
162
166
package com.redhat.developers;
163
167
164
168
import java.time.LocalDate;
169
+ import java.util.Map;
170
+
165
171
import org.eclipse.microprofile.config.inject.ConfigProperty;
166
172
167
173
import jakarta.enterprise.context.ApplicationScoped;
174
+ import jakarta.inject.Inject;
168
175
169
176
@ApplicationScoped
170
177
public class BookingService {
171
178
172
- @ConfigProperty(name="booking.daystostart")
173
- int daystostart;
174
-
175
- @ConfigProperty(name="booking.daystoend")
176
- int daystoend;
177
-
178
- private static String FIRSTNAME="john";
179
- private static String LASTNAME="doe";
180
- private static String BOOKINGNUMBER ="123-456"; // <1>
179
+ @Inject
180
+ @ConfigProperty(name = "booking") #<1>
181
+ Map<String, String> booking;
181
182
182
183
public Booking getBookingDetails(String bookingNumber, String customerName, String customerSurname) {
183
184
ensureExists(bookingNumber, customerName, customerSurname);
184
- LocalDate bookingFrom = LocalDate.now().plusDays(daystostart);
185
- LocalDate bookingTo = LocalDate.now().plusDays(daystoend);
185
+ LocalDate bookingFrom = LocalDate.now().plusDays(Long.parseLong(booking.get(" daystostart")) );
186
+ LocalDate bookingTo = LocalDate.now().plusDays(Long.parseLong(booking.get(" daystoend")) );
186
187
// Retrieval from DB mocking
187
188
Customer customer = new Customer(customerName, customerSurname);
188
189
return new Booking(bookingNumber, bookingFrom, bookingTo, customer);
@@ -191,15 +192,16 @@ public class BookingService {
191
192
public void cancelBooking(String bookingNumber, String customerName, String customerSurname) {
192
193
ensureExists(bookingNumber, customerName, customerSurname);
193
194
194
- // TODO add logic to double check booking conditions in case the LLM got it wrong.
195
+ // TODO add logic to double check booking conditions in case the LLM got it
196
+ // wrong.
195
197
// throw new BookingCannotBeCancelledException(bookingNumber);
196
198
}
197
199
198
200
private void ensureExists(String bookingNumber, String customerName, String customerSurname) {
199
201
// Check mocking
200
- if (!(bookingNumber.equals(BOOKINGNUMBER )
201
- && customerName.toLowerCase().equals(FIRSTNAME )
202
- && customerSurname.toLowerCase().equals(LASTNAME ))) {
202
+ if (!(bookingNumber.equals(booking.get("number") )
203
+ && customerName.toLowerCase().equals(booking.get("firstname") )
204
+ && customerSurname.toLowerCase().equals(booking.get("lastname") ))) {
203
205
throw new BookingNotFoundException(bookingNumber);
204
206
}
205
207
}
@@ -219,7 +221,7 @@ class BookingCannotBeCancelledException extends RuntimeException {
219
221
}
220
222
}
221
223
----
222
- <1> We hardcoded a booking entry for simplicity's sake. Of course, in a real world scenario this would likely come from a database.
224
+ <1> Retrieve a single booking from the application.properties file. ( in the real world this data would likely come from a DB instead :) )
223
225
224
226
Now we define a `BookingTools` singleton that will serve our AI with proper tools.
225
227
@@ -297,7 +299,7 @@ Create a new `ChatSocket` Java record in `src/main/java` in the `com.redhat.deve
297
299
----
298
300
package com.redhat.developers;
299
301
300
- import jakarta.websocket .OnOpen;
302
+ import io.quarkus.websockets.next .OnOpen;
301
303
import io.quarkus.websockets.next.OnTextMessage;
302
304
import io.quarkus.websockets.next.WebSocket;
303
305
@@ -316,7 +318,7 @@ public class ChatSocket {
316
318
}
317
319
318
320
@OnTextMessage
319
- public String onMessage(String userMessage){
321
+ public String onMessage(String userMessage) {
320
322
return assistant.chat(userMessage);
321
323
}
322
324
}
0 commit comments