Skip to content

Commit 2834bc3

Browse files
committed
update example
1 parent 026fcb9 commit 2834bc3

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>io.github.alexcheng1982</groupId>
4949
<artifactId>spring-ai-dashscope-spring-boot-starter</artifactId>
50-
<version>1.1.2</version>
50+
<version>1.2.0</version>
5151
</dependency>
5252
<dependency>
5353
<groupId>org.springdoc</groupId>

example/src/main/java/io/github/alexcheng1982/springai/dashscope/example/DemoController.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.github.alexcheng1982.springai.dashscope.example;
22

33
import java.util.List;
4-
import org.springframework.ai.chat.ChatClient;
5-
import org.springframework.ai.embedding.EmbeddingClient;
4+
import org.springframework.ai.chat.client.ChatClient;
5+
import org.springframework.ai.chat.model.ChatModel;
6+
import org.springframework.ai.embedding.EmbeddingModel;
67
import org.springframework.web.bind.annotation.PostMapping;
78
import org.springframework.web.bind.annotation.RequestBody;
89
import org.springframework.web.bind.annotation.RequestMapping;
@@ -29,21 +30,22 @@ public record EmbeddingResponse(List<Double> result) {
2930
}
3031

3132
private final ChatClient chatClient;
32-
private final EmbeddingClient embeddingClient;
33+
private final EmbeddingModel embeddingModel;
3334

34-
public DemoController(ChatClient chatClient,
35-
EmbeddingClient embeddingClient) {
36-
this.chatClient = chatClient;
37-
this.embeddingClient = embeddingClient;
35+
public DemoController(ChatModel chatModel,
36+
EmbeddingModel embeddingModel) {
37+
this.chatClient = ChatClient.create(chatModel);
38+
this.embeddingModel = embeddingModel;
3839
}
3940

4041
@PostMapping("/chat")
4142
public ChatResponse chat(@RequestBody ChatRequest request) {
42-
return new ChatResponse(chatClient.call(request.input()));
43+
return new ChatResponse(
44+
chatClient.prompt().user(request.input()).call().content());
4345
}
4446

4547
@PostMapping("/embed")
4648
public EmbeddingResponse embed(@RequestBody EmbeddingRequest request) {
47-
return new EmbeddingResponse(embeddingClient.embed(request.input()));
49+
return new EmbeddingResponse(embeddingModel.embed(request.input()));
4850
}
4951
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<module>client</module>
3030
<module>spring-boot-autoconfigure</module>
3131
<module>spring-boot-starter</module>
32+
<module>example</module>
3233
</modules>
3334

3435
<scm>

0 commit comments

Comments
 (0)