Skip to content

Commit 22e9fba

Browse files
committed
fix: spring ai update
1 parent c66da6e commit 22e9fba

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

backend/src/main/java/ch/xxx/aidoclibchat/adapter/config/FunctionConfig.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@
1717

1818
import java.util.function.Function;
1919

20+
import org.springframework.ai.tool.annotation.Tool;
2021
import org.springframework.context.annotation.Bean;
2122
import org.springframework.context.annotation.Configuration;
22-
import org.springframework.context.annotation.Description;
2323

2424
import ch.xxx.aidoclibchat.domain.client.OpenLibraryClient;
2525

2626
@Configuration
2727
public class FunctionConfig {
2828
private final OpenLibraryClient openLibraryClient;
29+
public static final String OPEN_LIBRARY_CLIENT = "openLibraryClient";
2930

3031
public FunctionConfig(OpenLibraryClient openLibraryClient) {
3132
this.openLibraryClient = openLibraryClient;
3233
}
3334

34-
@Bean
35-
@Description("Search for books by author, title or subject.")
35+
@Bean(OPEN_LIBRARY_CLIENT)
36+
@Tool(description = "Search for books by author, title or subject.")
3637
public Function<OpenLibraryClient.Request, OpenLibraryClient.Response> openLibraryClient() {
3738
return this.openLibraryClient::apply;
3839
}

backend/src/main/java/ch/xxx/aidoclibchat/domain/client/OpenLibraryClient.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.List;
1616
import java.util.function.Function;
1717

18+
import org.springframework.ai.tool.annotation.ToolParam;
19+
1820
import com.fasterxml.jackson.annotation.JsonClassDescription;
1921
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
2022
import com.fasterxml.jackson.annotation.JsonInclude;
@@ -24,21 +26,29 @@
2426

2527
public interface OpenLibraryClient extends Function<OpenLibraryClient.Request, OpenLibraryClient.Response> {
2628
@JsonIgnoreProperties(ignoreUnknown = true)
27-
record Book(@JsonProperty(value= "author_name", required = false) List<String> authorName,
28-
@JsonProperty(value= "language", required = false) List<String> languages,
29-
@JsonProperty(value= "publish_date", required = false) List<String> publishDates,
30-
@JsonProperty(value= "publisher", required = false) List<String> publishers,
31-
String title, String type,
32-
@JsonProperty(value= "subject", required = false) List<String> subjects,
33-
@JsonProperty(value= "place", required = false) List<String> places,
34-
@JsonProperty(value= "time", required = false) List<String> times,
35-
@JsonProperty(value= "person", required = false) List<String> persons,
36-
@JsonProperty(value= "ratings_average", required = false) Double ratingsAverage) {}
29+
record Book(@JsonProperty(value = "author_name", required = false) List<String> authorName,
30+
@JsonProperty(value = "language", required = false) List<String> languages,
31+
@JsonProperty(value = "publish_date", required = false) List<String> publishDates,
32+
@JsonProperty(value = "publisher", required = false) List<String> publishers, String title, String type,
33+
@JsonProperty(value = "subject", required = false) List<String> subjects,
34+
@JsonProperty(value = "place", required = false) List<String> places,
35+
@JsonProperty(value = "time", required = false) List<String> times,
36+
@JsonProperty(value = "person", required = false) List<String> persons,
37+
@JsonProperty(value = "ratings_average", required = false) Double ratingsAverage) {
38+
}
39+
3740
@JsonInclude(Include.NON_NULL)
3841
@JsonClassDescription("OpenLibrary API request")
39-
record Request(@JsonProperty(required=false, value="author") @JsonPropertyDescription("The book author") String author,
40-
@JsonProperty(required=false, value="title") @JsonPropertyDescription("The book title") String title,
41-
@JsonProperty(required=false, value="subject") @JsonPropertyDescription("The book subject") String subject) {}
42+
record Request(
43+
@JsonProperty(required = false, value = "author") @ToolParam(description = "The book authors name")
44+
@JsonPropertyDescription("The book authors name") String author,
45+
@JsonProperty(required = false, value = "title") @ToolParam(description = "The book title")
46+
@JsonPropertyDescription("The book title") String title,
47+
@JsonProperty(required = false, value = "subject") @ToolParam(description = "The book subject")
48+
@JsonPropertyDescription("The book subject") String subject) {
49+
}
50+
4251
@JsonIgnoreProperties(ignoreUnknown = true)
43-
record Response(Long numFound, Long start, Boolean numFoundExact, List<Book> docs) {}
52+
record Response(Long numFound, Long start, Boolean numFoundExact, List<Book> docs) {
53+
}
4454
}

backend/src/main/java/ch/xxx/aidoclibchat/usecase/service/FunctionService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
2626

27+
import ch.xxx.aidoclibchat.adapter.config.FunctionConfig;
2728
import ch.xxx.aidoclibchat.domain.model.dto.FunctionResult;
2829
import ch.xxx.aidoclibchat.domain.model.dto.FunctionSearch.ResultFormat;
2930

@@ -69,13 +70,13 @@ public FunctionResult functionCall(String question, ResultFormat resultFormat) {
6970
}
7071

7172
private FunctionResult functionCallText(String question) {
72-
var result = this.chatClient.prompt().user(this.promptStr + question).functions("openLibraryClient").call()
73+
var result = this.chatClient.prompt().user(this.promptStr + question).tools(FunctionConfig.OPEN_LIBRARY_CLIENT).call()
7374
.content();
7475
return new FunctionResult(result, null);
7576
}
7677

7778
private FunctionResult functionCallJson(String question) {
78-
var result = this.chatClient.prompt().user(this.promptStr + question).functions("openLibraryClient").call()
79+
var result = this.chatClient.prompt().user(this.promptStr + question).tools(FunctionConfig.OPEN_LIBRARY_CLIENT).call()
7980
.entity(new ParameterizedTypeReference<List<JsonResult>>() {});
8081
return new FunctionResult(null, result);
8182
}

backend/src/main/resources/application-ollama.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ spring.liquibase.change-log=classpath:/dbchangelog/db.changelog-master-ollama.xm
1212
# document processing
1313
# config free production use
1414
#spring.ai.ollama.chat.model=qwen2.5:32b
15-
spring.ai.ollama.chat.model=llama3.1:8b
15+
spring.ai.ollama.chat.model=deepseek-r1:14b
16+
#spring.ai.ollama.chat.model=llama3.1:8b
1617
spring.ai.ollama.chat.options.num-ctx=12288
1718
spring.ai.embedding.transformer.onnx.modelUri=https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1/resolve/main/onnx/model_quantized.onnx
1819
spring.ai.embedding.transformer.tokenizer.uri=https://huggingface.co/mixedbread-ai/mxbai-embed-large-v1/resolve/main/tokenizer.json

0 commit comments

Comments
 (0)