Skip to content

Commit

Permalink
fix: function interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Dec 8, 2024
1 parent 5aab871 commit ca17d4b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

Expand All @@ -31,6 +32,8 @@ public class OpenLibraryRestClient implements OpenLibraryClient {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenLibraryRestClient.class);
private final String baseUrl = "https://openlibrary.org/search.json";
private final RestClient restClient;
@Value("${openlibrary.result-size:10}")
private int resultLimit;

public OpenLibraryRestClient(RestClient restClient) {
this.restClient = restClient;
Expand All @@ -44,7 +47,7 @@ public Response apply(Request request) {
var paramsStr = List.of(authorOpt, titleOpt, subjectOpt).stream()
.filter(Optional::isPresent).map(Optional::get).collect(Collectors.joining("&"));
var urlStr =
String.format("%s?%s&limit=10", this.baseUrl, paramsStr);
String.format("%s?%s&limit=%d", this.baseUrl, paramsStr, this.resultLimit);
LOGGER.info(urlStr);
var response = this.restClient.get().uri(urlStr).retrieve().body(Response.class);
return response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FunctionController(FunctionService functionService) {

@PostMapping(path="/books", produces = MediaType.APPLICATION_JSON_VALUE)
public FunctionResult postQuestion(@RequestBody FunctionSearch functionSearch) {
return new FunctionResult(this.functionService.functionCall(functionSearch.question(), functionSearch.resultAmount()));
return new FunctionResult(this.functionService.functionCall(functionSearch.question()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*/
package ch.xxx.aidoclibchat.domain.model.dto;

public record FunctionSearch(String question, Long resultAmount) { }
public record FunctionSearch(String question) { }
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public FunctionService(Builder builder) {
this.chatClient = builder.build();
}

public String functionCall(String question, Long resultsAmount) {
public String functionCall(String question) {
if (!this.activeProfile.contains("ollama")) {
return "";
}
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ management.endpoint.health.show-details=always

embedding-token-limit=2000
document-token-limit=2000
image.result-size=20
image.result-size=20
openlibrary.result-size=10
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export class FunctionSearchComponent {
);
this.functionSearchService
.postLibraryFunction({
question: this.searchValueControl.value,
resultAmount: 10,
question: this.searchValueControl.value
} as FunctionSearch)
.pipe(
tap(() => this.repeatSub?.unsubscribe()),
Expand Down
1 change: 0 additions & 1 deletion frontend/src/angular/src/app/model/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/
export interface FunctionSearch {
question: string;
resultAmount: number;
}

export interface Book {
Expand Down

0 comments on commit ca17d4b

Please sign in to comment.