Skip to content

Commit eb2d5cc

Browse files
committed
fix code issues
1 parent 1046ad6 commit eb2d5cc

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

articles/search/includes/quickstarts/search-get-started-rag-java.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ ms.date: 07/31/2025
2020
- [Java 21 (LTS)](/java/openjdk/install).
2121
- [Maven](https://maven.apache.org/download.cgi).
2222

23-
2423
## Configure access
2524

2625
Requests to the search endpoint must be authenticated and authorized. You can use API keys or roles for this task. Keys are easier to start with, but roles are more secure. This quickstart assumes roles.
@@ -335,23 +334,24 @@ Create a query script that uses the Azure AI Search index and the chat model to
335334
.toList();
336335
}
337336

338-
private static String queryOpenAI(OpenAIClient openAIClient, List<SearchResult> sources) {
337+
private static String queryOpenAI(OpenAIClient openAIClient,
338+
String userQuery, List<SearchResult> sources) {
339339
String deploymentModel = System.getenv("AZURE_DEPLOYMENT_MODEL");
340-
340+
341341
String sourcesText = sources.stream()
342342
.map(source -> source.getDocument(Object.class).toString())
343343
.collect(java.util.stream.Collectors.joining("\n"));
344-
344+
345345
var messages = List.of(
346346
new ChatRequestSystemMessage("""
347347
You are an assistant that recommends hotels based on
348348
search results."""),
349349
new ChatRequestUserMessage("""
350-
Can you recommend a few hotels that offer
351-
complimentary breakfast? Here are the search results:
352-
%s""".formatted(sourcesText))
350+
Can you recommend a few hotels that offer %s?
351+
Here are the search results:
352+
%s""".formatted(userQuery, sourcesText))
353353
);
354-
354+
355355
var chatOptions = new ChatCompletionsOptions(messages);
356356
ChatCompletions response = openAIClient.getChatCompletions(deploymentModel, chatOptions);
357357

@@ -362,10 +362,12 @@ Create a query script that uses the Azure AI Search index and the chat model to
362362
SearchClient searchClient = getSearchClient();
363363
OpenAIClient openAIClient = getOpenAIClient();
364364

365-
List<SearchResult> sources = searchDocuments(searchClient);
365+
String userQuery = "complimentary breakfast";
366+
List<SearchResult> sources = searchDocuments(searchClient, userQuery);
366367
String response = queryOpenAI(openAIClient, userQuery, sources);
367368

368369
System.out.println(response);
370+
System.exit(0);
369371
}
370372
}
371373
```
@@ -485,25 +487,26 @@ Tell me their description, address, tags, and the rate for one room that sleeps
485487
.toList();
486488
}
487489

488-
private static String queryOpenAI(OpenAIClient openAIClient, List<SearchResult> sources) {
490+
private static String queryOpenAI(OpenAIClient openAIClient,
491+
String userQuery, List<SearchResult> sources) {
489492
String deploymentModel = System.getenv("AZURE_DEPLOYMENT_MODEL");
490-
493+
491494
String sourcesText = sources.stream()
492495
.map(source -> source.getDocument(Object.class).toString())
493496
.collect(java.util.stream.Collectors.joining("\n"));
494-
497+
495498
var messages = List.of(
496499
new ChatRequestSystemMessage("""
497500
You are an assistant that recommends hotels based on
498501
search results."""),
499502
new ChatRequestUserMessage("""
500-
Can you recommend a few hotels that offer
501-
complimentary breakfast? Tell me their description,
502-
address, tags, and the rate for one room that sleeps
503-
4 people. Here are the search results:
504-
%s""".formatted(sourcesText))
503+
Can you recommend a few hotels that offer %s?
504+
Tell me their description, address, tags,
505+
and the rate for one room that sleeps 4 people.
506+
Here are the search results:
507+
%s""".formatted(userQuery, sourcesText))
505508
);
506-
509+
507510
var chatOptions = new ChatCompletionsOptions(messages);
508511
ChatCompletions response = openAIClient.getChatCompletions(
509512
deploymentModel, chatOptions);
@@ -515,10 +518,12 @@ Tell me their description, address, tags, and the rate for one room that sleeps
515518
SearchClient searchClient = getSearchClient();
516519
OpenAIClient openAIClient = getOpenAIClient();
517520

518-
List<SearchResult> sources = searchDocuments(searchClient);
521+
String userQuery = "complimentary breakfast";
522+
List<SearchResult> sources = searchDocuments(searchClient, userQuery);
519523
String response = queryOpenAI(openAIClient, userQuery, sources);
520524

521525
System.out.println(response);
526+
System.exit(0);
522527
}
523528
}
524529
```

0 commit comments

Comments
 (0)