File tree Expand file tree Collapse file tree
src/main/java/com/javaaidev/agent Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121 <dependencies >
2222 <dependency >
2323 <groupId >org.springframework.boot</groupId >
24- <artifactId >spring-boot-starter-web </artifactId >
24+ <artifactId >spring-boot-starter-webflux </artifactId >
2525 </dependency >
2626 <dependency >
2727 <groupId >org.springframework.ai</groupId >
3131 <dependency >
3232 <groupId >com.javaaidev</groupId >
3333 <artifactId >chat-agent-ui</artifactId >
34- <version >0.6 .0</version >
34+ <version >0.7 .0</version >
3535 </dependency >
3636
3737 <dependency >
Original file line number Diff line number Diff line change 1111import reactor .core .publisher .Flux ;
1212
1313@ RestController
14- @ RequestMapping ("/chat " )
14+ @ RequestMapping ("/chat_non_streaming " )
1515public class ChatAgentController extends AbstractChatAgentController {
1616
1717 private final ChatClient chatClient ;
Original file line number Diff line number Diff line change 33import com .javaaidev .chatagent .model .ChatRequest ;
44import org .springframework .ai .chat .client .ChatClient ;
55import org .springframework .ai .chat .messages .Message ;
6+ import org .springframework .http .MediaType ;
67import org .springframework .http .codec .ServerSentEvent ;
78import org .springframework .web .bind .annotation .PostMapping ;
89import org .springframework .web .bind .annotation .RequestBody ;
1112import reactor .core .publisher .Flux ;
1213
1314@ RestController
14- @ RequestMapping ("/chat_streaming " )
15+ @ RequestMapping ("/chat " )
1516public class ChatAgentStreamingController extends AbstractChatAgentController {
1617
1718 private final ChatClient chatClient ;
@@ -20,7 +21,7 @@ public ChatAgentStreamingController(ChatClient.Builder builder) {
2021 chatClient = builder .build ();
2122 }
2223
23- @ PostMapping
24+ @ PostMapping ( produces = MediaType . TEXT_EVENT_STREAM_VALUE )
2425 public Flux <ServerSentEvent <String >> chatStreaming (@ RequestBody ChatRequest request ) {
2526 var messages = chatRequestToMessages (request );
2627 return chatClient .prompt ().system (SYSTEM_TEXT ).messages (messages .toArray (new Message [0 ]))
Original file line number Diff line number Diff line change 1+ package com .javaaidev .agent ;
2+
3+ import org .springframework .ai .chat .client .ChatClient ;
4+ import org .springframework .web .bind .annotation .PostMapping ;
5+ import org .springframework .web .bind .annotation .RequestBody ;
6+
7+ public class SimpleChatController {
8+
9+ public static final String SYSTEM_TEXT = """
10+ You are a chef who is proficient in various cuisines. Please answer users' questions about cooking.
11+ For other unrelated inputs, simply tell the user that you don't know.
12+ """ ;
13+
14+ private final ChatClient chatClient ;
15+
16+ public SimpleChatController (ChatClient .Builder builder ) {
17+ chatClient = builder .build ();
18+ }
19+
20+ @ PostMapping ("/simple_chat" )
21+ public ChatOutput chat (@ RequestBody ChatInput chatInput ) {
22+ return new ChatOutput (
23+ chatClient .prompt ()
24+ .system (SYSTEM_TEXT )
25+ .user (chatInput .input ())
26+ .call ().content ());
27+ }
28+
29+
30+ public record ChatInput (String input ) {
31+
32+ }
33+
34+ public record ChatOutput (String output ) {
35+
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments