ChatClient返回响应:返回实体类
This commit is contained in:
parent
7826a93f81
commit
c96f375592
@ -0,0 +1,43 @@
|
||||
package com.huangge1199.aiagent.controller;
|
||||
|
||||
import com.huangge1199.aiagent.common.R;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* ResControlle
|
||||
*
|
||||
* @author huangge1199
|
||||
* @since 2025/5/17 12:23:36
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/res")
|
||||
@Tag(name = "ChatClient返回响应")
|
||||
public class ResControlle {
|
||||
|
||||
private final ChatClient chatClient;
|
||||
|
||||
public ResControlle(ChatClient.Builder builder) {
|
||||
this.chatClient = builder.build();
|
||||
}
|
||||
|
||||
record ActorFilms(String actor, List<String> movies) {
|
||||
}
|
||||
|
||||
@PostMapping("/entity")
|
||||
@Operation(summary = "实体返回")
|
||||
public R<ActorFilms> entityRes(@RequestBody String question ) {
|
||||
ActorFilms actorFilms = chatClient.prompt()
|
||||
.user(question)
|
||||
.call()
|
||||
.entity(ActorFilms.class);
|
||||
return R.ok(actorFilms);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user