11package io .github .alexcheng1982 .springai .dashscope .example ;
22
33import 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 ;
67import org .springframework .web .bind .annotation .PostMapping ;
78import org .springframework .web .bind .annotation .RequestBody ;
89import 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}
0 commit comments