Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ui/src/components/ai-chat/component/answer-content/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ function showSource(row: any) {
}

const regenerationChart = (chat: chatType) => {
props.sendMessage(chat.problem_text, { re_chat: true })
const startNode = props.chatRecord.execution_details?.find(
(detail) => detail.type === 'start-node',
)
props.sendMessage(chat.problem_text, {
re_chat: true,
image_list: startNode?.image_list || [],
document_list: startNode?.document_list || [],
audio_list: startNode?.audio_list || [],
video_list: startNode?.video_list || [],
other_list: startNode?.other_list || [],
})
}
const stopChat = (chat: chatType) => {
props.chatManagement.stop(chat.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some issues and suggestions for improvement in your code:

Issues:

  1. Undefined chatRecord: The variable props.chatRecord is being used without checking if it's defined, which could lead to an error or incorrect behavior.

  2. Lack of Error Handling: If execution_details or specific nodes like start-node don't exist, the rest of the image/document/audio/video/other lists will be empty.

  3. Overloading Message Parameters: The sendMessage function seems to accept multiple optional parameters (re_chat, image_list, etc.), but not all fields may always be populated. Consider handling this more robustly within each use case.

  4. Repetition of Logic: The logic for constructing the objects that contain image/document/audio/video/other lists can be refactored into a helper function or class property to reduce redundancy.

Suggestions:

@@ -156,7 +156,17 @@ function showSource(row: any) {}
 
 const regenerationChart = (chat: chatType) => {
   // Ensure chatRecord is defined before accessing properties
   if (!props.chatRecord?.execution_details) {
     console.warn('Execution details not found');
     return;
   }
   
   const getDetailsByType = (type) =>
     props.chatRecord.execution_details.find((detail) => detail.type === type);
  
  const startNode = getDetailsByType('start-node');
  props.sendMessage(chat.problem_text, {
    re_chat: true,
    image_list: startNode?.image_list || [],
    document_list: startNode?.document_list || [],
    audio_list: startNode?.audio_list || [],
    video_list: startNode?.video_list || [],
    other_list: startNode?.other_list || [],
  });
}
const stopChat = (chat: chatType) => {
  props.chatManagement.stop(chat.id);

These changes make the code cleaner, safer, less repetitive, and easier to maintain. They also address potential undefined errors when dealing with data that might be absent from certain stages.

Expand Down
Loading