Skip to content

Commit

Permalink
Merge pull request #69 from insea-connect/cross-issue
Browse files Browse the repository at this point in the history
fix: fix the source problem with chat responses and added more time t…
  • Loading branch information
Earthyyy authored Jun 6, 2024
2 parents d6bbeb5 + 6f2742d commit 65c6fc6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ma.insea.connect.chatbot.controller;


import lombok.extern.slf4j.Slf4j;
import ma.insea.connect.chatbot.DTO.groupDTO.ChatbotGroupMessageRequestDTO;
import ma.insea.connect.chatbot.DTO.groupDTO.ChatbotGroupMessageResponseDTO;
import ma.insea.connect.chatbot.service.ChatbotService;
Expand All @@ -20,6 +21,7 @@
import java.util.regex.Pattern;


@Slf4j
@RestController
@RequestMapping("api/v1/chatbot")
public class ChatbotController {
Expand All @@ -35,6 +37,7 @@ private String cleanResponseMessage(String message) {
String regex = "【\\d+:\\d+†source】";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(message);
log.info("Formatted text without crosses "+matcher.replaceAll("") );
return matcher.replaceAll("");
}

Expand Down Expand Up @@ -71,6 +74,9 @@ public SseEmitter sendToBotConversationStream(@RequestBody ChatbotMessageRequest
public ResponseEntity<ChatbotMessageResponseDTO> sendToBotConversation(@RequestBody ChatbotMessageRequestDTO requestDTO) {
try {
ChatbotMessageResponseDTO chatbotMessageResponseDTO= chatbotService.sendToBotConversation(requestDTO);
chatbotMessageResponseDTO.setMessage(cleanResponseMessage(chatbotMessageResponseDTO.getMessage()));
log.info("the formated text included in the message body "+ chatbotMessageResponseDTO.getMessage());
log.info("the text it should have is "+cleanResponseMessage(chatbotMessageResponseDTO.getMessage()));
return ResponseEntity.ok(chatbotMessageResponseDTO);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,20 @@
import org.springframework.web.client.RestTemplate;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@Service
public class ChatbotService {

private String cleanResponseMessage(String message) {
String regex = "【\\d+:\\d+†source】";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(message);
log.info("Formatted text without crosses "+matcher.replaceAll("") );
return matcher.replaceAll("");
}
@Autowired
ChatMessageService chatMessageService;
@Value("${chatbotServer}")
Expand All @@ -44,7 +54,7 @@ public ChatbotMessageResponseDTO addInteractionInConversation(ChatbotMessageRequ
ChatMessageDTO botResponse = new ChatMessageDTO();
botResponse.setRecipientId(chatbotMessageRequestDTO.getSenderId());
botResponse.setSenderId(chatbotMessageRequestDTO.getRecipientId());
botResponse.setContent(responseContent);
botResponse.setContent(cleanResponseMessage(responseContent));
botResponse.setTimestamp(date);
chatMessageService.saveusermessage(userRequest);
chatMessageService.saveusermessage(botResponse);
Expand Down
2 changes: 1 addition & 1 deletion packages/insea-connect-chatbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def process_request_stream():
conversation['expires_at'] = datetime.now() + timedelta(minutes=15)

# Wait for the run to complete or time out
timeout_seconds = 5 * 60 # 5 minutes timeout
timeout_seconds = 300 * 60 # 5 minutes timeout
start_time = time.time()

while run.status != "completed":
Expand Down

0 comments on commit 65c6fc6

Please sign in to comment.