Skip to content

Commit b425b04

Browse files
committed
Fix README new ChatClient migration snippet
1 parent 4a2ad60 commit b425b04

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

README.md

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ On our march to release 1.0.0 M1 we have made several breaking changes. Apologi
1414

1515
**(22.05.2024)**
1616

17-
A major change was made that took the 'old' `ChatClient` and moved the functionality into `ChatModel`. The 'new' `ChatClient` now takes an instance of `ChatModel`. This was done do support a fluent API for creating and executing prompts in a style similar to other client classes in the Spring ecosystem, such as `RestClient`, `WebClient`, and `JdbcClient`. Refer to the [JavaDoc](https://docs.spring.io/spring-ai/docs/1.0.0-SNAPSHOT/api/) for more information on the Fluent API, proper reference documentation is coming shortly.
17+
A major change was made that took the 'old' `ChatClient` and moved the functionality into `ChatModel`. The 'new' `ChatClient` now takes an instance of `ChatModel`. This was done do support a fluent API for creating and executing prompts in a style similar to other client classes in the Spring ecosystem, such as `RestClient`, `WebClient`, and `JdbcClient`. Refer to the [JavaDoc](https://docs.spring.io/spring-ai/docs/1.0.0-SNAPSHOT/api/) for more information on the Fluent API, proper reference documentation is coming shortly.
1818

1919
We renamed the 'old' `ModelClient` to `Model` and renamed implementing classes, for example `ImageClient` was renamed to `ImageModel`. The `Model` implementation represent the portability layer that converts between the Spring AI API and the underlying AI Model API.
2020

@@ -25,39 +25,39 @@ NOTE: The `ChatClient` class is now in the package `org.springframework.ai.chat.
2525
#### Approach 1
2626

2727
Now, instead of getting an Autoconfigured `ChatClient` instance, you will get a `ChatModel` instance. The `call` method signatures after renaming remain the same.
28-
To adapt your code should refactor you code to change use of the type `ChatClient` to `ChatModel`
28+
To adapt your code should refactor you code to change use of the type `ChatClient` to `ChatModel`
2929
Here is an example of existing code before the change
3030

3131
```java
3232
@RestController
33-
public class OldSimpleAiController {
34-
33+
public class OldSimpleAiController {
34+
3535
private final ChatClient chatClient;
36-
36+
3737
public OldSimpleAiController(ChatClient chatClient) {
3838
this.chatClient = chatClient;
3939
}
40-
41-
@GetMapping("/ai/simple")
40+
41+
@GetMapping("/ai/simple")
4242
Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
4343
return Map.of("generation", chatClient.call(message));
4444
}
4545
}
4646
```
4747

48-
Now after the changes this will be
48+
Now after the changes this will be
4949

5050
```java
5151
@RestController
5252
public class SimpleAiController {
53-
53+
5454
private final ChatModel chatModel;
55-
55+
5656
public SimpleAiController(ChatModel chatModel) {
5757
this.chatModel = chatModel;
5858
}
59-
60-
@GetMapping("/ai/simple")
59+
60+
@GetMapping("/ai/simple")
6161
Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
6262
return Map.of("generation", chatModel.call(message));
6363
}
@@ -80,9 +80,9 @@ Here is an example of existing code before the change
8080
```java
8181
@RestController
8282
class OldSimpleAiController {
83-
83+
8484
ChatClient chatClient;
85-
85+
8686
OldSimpleAiController(ChatClient chatClient) {
8787
this.chatClient = chatClient;
8888
}
@@ -97,23 +97,22 @@ class OldSimpleAiController {
9797
}
9898
```
9999

100-
101100
Now after the changes this will be
102101

103102
```java
104103
@RestController
105104
class SimpleAiController {
106105

107-
private final ChatClient.Builder builder;
108-
106+
private final ChatClient chatClient;
107+
109108
SimpleAiController(ChatClient.Builder builder) {
110-
this.builder = builder;
109+
this.builder = builder.build();
111110
}
112-
113-
@GetMapping("/ai/simple")
111+
112+
@GetMapping("/ai/simple")
114113
Map<String, String> completion(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
115114
return Map.of(
116-
"generation",
115+
"generation",
117116
chatClient.prompt().user(message).call().content()
118117
);
119118
}
@@ -130,7 +129,7 @@ There is a tag in the GitHub repository called [v1.0.0-SNAPSHOT-before-chatclien
130129
```bash
131130
git checkout tags/v1.0.0-SNAPSHOT-before-chatclient-changes
132131

133-
./mvnw clean install -DskipTests
132+
./mvnw clean install -DskipTests
134133
```
135134

136135

0 commit comments

Comments
 (0)