|
1 | 1 | package com.ke.bella.workflow.api; |
2 | 2 |
|
| 3 | +import java.time.LocalDateTime; |
3 | 4 | import java.time.ZoneId; |
4 | 5 | import java.util.ArrayList; |
5 | 6 | import java.util.Collections; |
|
18 | 19 |
|
19 | 20 | import javax.servlet.http.HttpServletRequest; |
20 | 21 |
|
21 | | -import java.time.LocalDateTime; |
22 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.format.annotation.DateTimeFormat; |
23 | 24 | import org.springframework.util.Assert; |
24 | 25 | import org.springframework.util.CollectionUtils; |
25 | 26 | import org.springframework.util.StringUtils; |
26 | | -import org.springframework.format.annotation.DateTimeFormat; |
27 | | -import org.springframework.http.ResponseEntity; |
28 | 27 | import org.springframework.web.bind.annotation.GetMapping; |
29 | 28 | import org.springframework.web.bind.annotation.PathVariable; |
30 | 29 | import org.springframework.web.bind.annotation.PostMapping; |
|
79 | 78 | import com.ke.bella.workflow.utils.JsonUtils; |
80 | 79 | import com.ke.bella.workflow.utils.OpenAiUtils; |
81 | 80 | import com.theokanning.openai.assistants.message.Message; |
| 81 | +import com.theokanning.openai.assistants.message.MessageContent; |
82 | 82 | import com.theokanning.openai.assistants.message.MessageListSearchParameters; |
| 83 | +import com.theokanning.openai.assistants.message.content.Text; |
83 | 84 | import com.theokanning.openai.service.OpenAiService; |
84 | 85 |
|
85 | 86 | import lombok.AllArgsConstructor; |
@@ -650,12 +651,28 @@ public Page<DifyChatFlowRun> pageChatFlowRuns(@PathVariable String workflowId, |
650 | 651 | } |
651 | 652 |
|
652 | 653 | for (List<Message> groupedMessage : groupedMessages) { |
| 654 | + String query = Optional.ofNullable(groupedMessage.get(0).getContent()) |
| 655 | + .filter(content -> !content.isEmpty()) |
| 656 | + .map(content -> content.get(0)) |
| 657 | + .map(MessageContent::getText) |
| 658 | + .map(Text::getValue) |
| 659 | + .orElse(""); |
| 660 | + |
| 661 | + String answer = groupedMessage.subList(1, groupedMessage.size()).stream() |
| 662 | + .map(e -> Optional.ofNullable(e.getContent()) |
| 663 | + .filter(content -> !content.isEmpty()) |
| 664 | + .map(content -> content.get(0)) |
| 665 | + .map(MessageContent::getText) |
| 666 | + .map(Text::getValue) |
| 667 | + .orElse("")) |
| 668 | + .filter(Objects::nonNull) |
| 669 | + .collect(Collectors.joining()); |
| 670 | + |
653 | 671 | DifyChatFlowRun run = DifyChatFlowRun.builder() |
654 | 672 | .id(groupedMessage.get(0).getId()) |
655 | 673 | .conversation_id(groupedMessage.get(0).getThreadId()) |
656 | | - .query(groupedMessage.get(0).getContent().get(0).getText().getValue()) |
657 | | - .answer(groupedMessage.subList(1, groupedMessage.size()).stream().map(e -> e.getContent().get(0).getText().getValue()) |
658 | | - .collect(Collectors.joining())) |
| 674 | + .query(query) |
| 675 | + .answer(answer) |
659 | 676 | .created_at((long) groupedMessage.get(0).getCreatedAt()) |
660 | 677 | .workflow_run_id(Optional.ofNullable(groupedMessage.get(0).getMetadata()).map(e -> e.get("workflowRunId")).orElse(null)) |
661 | 678 | .build(); |
|
0 commit comments