Skip to content

Commit

Permalink
Merge pull request #49 from code2tan/main
Browse files Browse the repository at this point in the history
feat: add async chat demo
  • Loading branch information
lltx authored Feb 27, 2025
2 parents 4593fc3 + c462564 commit 3e02589
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.github.pigmesh.ai.deepseek.config.DeepSeekProperties;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.Json;
import io.github.pigmesh.ai.deepseek.core.SyncOrAsyncOrStreaming;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionChoice;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionRequest;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
Expand Down Expand Up @@ -48,6 +49,19 @@ public ChatCompletionResponse syncChat(String prompt) {
return deepSeekClient.chatCompletion(request).execute();
}

// 异步
@GetMapping(value = "/async/chat")
public void asyncChat(String prompt) {
ChatCompletionRequest request = ChatCompletionRequest.builder().model(deepSeekProperties.getModel())
.addUserMessage(prompt).build();
SyncOrAsyncOrStreaming<ChatCompletionResponse> asyncOrStreaming = deepSeekClient.chatCompletion(request);
asyncOrStreaming.onResponse((responseContent) -> {
log.info("处理返回数据:{}", Json.toJson(responseContent));
}, exception -> {
log.info("处理异常数据:{}", exception.getMessage());
});
}

@GetMapping(value = "/models", produces = MediaType.APPLICATION_JSON_VALUE)
public ModelsResponse models() {
return deepSeekClient.models();
Expand Down

0 comments on commit 3e02589

Please sign in to comment.