File tree Expand file tree Collapse file tree 4 files changed +43
-5
lines changed
src/main/java/com/javaaidev/agent Expand file tree Collapse file tree 4 files changed +43
-5
lines changed Original file line number Diff line number Diff line change 21
21
<dependencies >
22
22
<dependency >
23
23
<groupId >org.springframework.boot</groupId >
24
- <artifactId >spring-boot-starter-web </artifactId >
24
+ <artifactId >spring-boot-starter-webflux </artifactId >
25
25
</dependency >
26
26
<dependency >
27
27
<groupId >org.springframework.ai</groupId >
31
31
<dependency >
32
32
<groupId >com.javaaidev</groupId >
33
33
<artifactId >chat-agent-ui</artifactId >
34
- <version >0.6 .0</version >
34
+ <version >0.7 .0</version >
35
35
</dependency >
36
36
37
37
<dependency >
Original file line number Diff line number Diff line change 11
11
import reactor .core .publisher .Flux ;
12
12
13
13
@ RestController
14
- @ RequestMapping ("/chat " )
14
+ @ RequestMapping ("/chat_non_streaming " )
15
15
public class ChatAgentController extends AbstractChatAgentController {
16
16
17
17
private final ChatClient chatClient ;
Original file line number Diff line number Diff line change 3
3
import com .javaaidev .chatagent .model .ChatRequest ;
4
4
import org .springframework .ai .chat .client .ChatClient ;
5
5
import org .springframework .ai .chat .messages .Message ;
6
+ import org .springframework .http .MediaType ;
6
7
import org .springframework .http .codec .ServerSentEvent ;
7
8
import org .springframework .web .bind .annotation .PostMapping ;
8
9
import org .springframework .web .bind .annotation .RequestBody ;
11
12
import reactor .core .publisher .Flux ;
12
13
13
14
@ RestController
14
- @ RequestMapping ("/chat_streaming " )
15
+ @ RequestMapping ("/chat " )
15
16
public class ChatAgentStreamingController extends AbstractChatAgentController {
16
17
17
18
private final ChatClient chatClient ;
@@ -20,7 +21,7 @@ public ChatAgentStreamingController(ChatClient.Builder builder) {
20
21
chatClient = builder .build ();
21
22
}
22
23
23
- @ PostMapping
24
+ @ PostMapping ( produces = MediaType . TEXT_EVENT_STREAM_VALUE )
24
25
public Flux <ServerSentEvent <String >> chatStreaming (@ RequestBody ChatRequest request ) {
25
26
var messages = chatRequestToMessages (request );
26
27
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