Skip to content

Commit

Permalink
update example
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcheng1982 committed Jun 19, 2024
1 parent 026fcb9 commit 2834bc3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.github.alexcheng1982</groupId>
<artifactId>spring-ai-dashscope-spring-boot-starter</artifactId>
<version>1.1.2</version>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.github.alexcheng1982.springai.dashscope.example;

import java.util.List;
import org.springframework.ai.chat.ChatClient;
import org.springframework.ai.embedding.EmbeddingClient;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -29,21 +30,22 @@ public record EmbeddingResponse(List<Double> result) {
}

private final ChatClient chatClient;
private final EmbeddingClient embeddingClient;
private final EmbeddingModel embeddingModel;

public DemoController(ChatClient chatClient,
EmbeddingClient embeddingClient) {
this.chatClient = chatClient;
this.embeddingClient = embeddingClient;
public DemoController(ChatModel chatModel,
EmbeddingModel embeddingModel) {
this.chatClient = ChatClient.create(chatModel);
this.embeddingModel = embeddingModel;
}

@PostMapping("/chat")
public ChatResponse chat(@RequestBody ChatRequest request) {
return new ChatResponse(chatClient.call(request.input()));
return new ChatResponse(
chatClient.prompt().user(request.input()).call().content());
}

@PostMapping("/embed")
public EmbeddingResponse embed(@RequestBody EmbeddingRequest request) {
return new EmbeddingResponse(embeddingClient.embed(request.input()));
return new EmbeddingResponse(embeddingModel.embed(request.input()));
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<module>client</module>
<module>spring-boot-autoconfigure</module>
<module>spring-boot-starter</module>
<module>example</module>
</modules>

<scm>
Expand Down

0 comments on commit 2834bc3

Please sign in to comment.