Skip to content

Commit

Permalink
feat: create url
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Mar 10, 2024
1 parent 9daa5c0 commit 8c082b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
*/
package ch.xxx.aidoclibchat.adapter.client;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -21,10 +25,19 @@
@Component
public class OpenLibraryRestClient implements OpenLibraryClient {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenLibraryRestClient.class);

private final String baseUrl = "https://openlibrary.org/search.json";

@Override
public Response apply(Request request) {
LOGGER.info(request.toString());
var authorOpt = Optional.ofNullable(request.author()).stream().filter(myAuthor -> !myAuthor.isBlank())
.map(myAuthor -> "author=" + myAuthor.replace(" ", "+")).findFirst();
var titleOpt = Optional.ofNullable(request.title()).stream().filter(myAuthor -> !myAuthor.isBlank())
.map(myAuthor -> "title=" + myAuthor.replace(" ", "+")).findFirst();
var subjectOpt = Optional.ofNullable(request.subject()).stream().filter(myAuthor -> !myAuthor.isBlank())
.map(myAuthor -> "subject=" + myAuthor.replace(" ", "+")).findFirst();
var paramStr = "?" + List.of(authorOpt, titleOpt, subjectOpt).stream().filter(Optional::isPresent)
.map(myOpt -> myOpt.get()).collect(Collectors.joining("&"));
LOGGER.info(this.baseUrl + paramStr);
return new Response("Kevin Rudd");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public String functionCall(String question) {
throw new RuntimeException("No parameters found.");
}
} catch (Exception e) {
LOGGER.error("ChatResponse: {}", response);
LOGGER.error("Chatresult Json Mapping failed.", e);
LOGGER.error("ChatResponse: {}", response);
}
}
myToolsList.forEach(myTool -> {
Expand Down

0 comments on commit 8c082b0

Please sign in to comment.