File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed
src/main/java/com/javaaidev/agent Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change 20
20
@ RequestMapping ("/chat" )
21
21
public class ChatAgentController {
22
22
23
-
24
23
private static final String SYSTEM_TEXT = "You are a chef who is proficient in various cuisines. Please answer users' questions about cooking." ;
25
24
private final ChatClient chatClient ;
26
25
@@ -30,18 +29,21 @@ public ChatAgentController(ChatClient.Builder builder) {
30
29
31
30
@ PostMapping
32
31
public ChatResponse chat (@ RequestBody ChatRequest request ) {
32
+ if (request == null ) {
33
+ return new ChatResponse (List .of ());
34
+ }
33
35
var messages = request .messages ().stream ().flatMap (message -> {
34
36
if (message instanceof ThreadUserMessage userMessage ) {
35
37
return userMessage .content ().stream ().map (part -> {
36
- if (part instanceof TextContentPart textContentPart ) {
37
- return new UserMessage (textContentPart . text () );
38
+ if (part instanceof TextContentPart ( String text ) ) {
39
+ return new UserMessage (text );
38
40
}
39
41
return null ;
40
42
});
41
43
} else if (message instanceof ThreadAssistantMessage assistantMessage ) {
42
44
return assistantMessage .content ().stream ().map (part -> {
43
- if (part instanceof TextContentPart textContentPart ) {
44
- return new AssistantMessage (textContentPart . text () );
45
+ if (part instanceof TextContentPart ( String text ) ) {
46
+ return new AssistantMessage (text );
45
47
}
46
48
return null ;
47
49
});
You can’t perform that action at this time.
0 commit comments