Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,23 @@ class ImageUnderstandNodeSerializer(serializers.Serializer):

class IImageUnderstandNode(INode):
type = 'image-understand-node'
support = [WorkflowMode.APPLICATION, WorkflowMode.APPLICATION_LOOP]
support = [WorkflowMode.APPLICATION, WorkflowMode.APPLICATION_LOOP, WorkflowMode.KNOWLEDGE,
WorkflowMode.KNOWLEDGE_LOOP]

def get_node_params_serializer_class(self) -> Type[serializers.Serializer]:
return ImageUnderstandNodeSerializer

def _run(self):
res = self.workflow_manage.get_reference_field(self.node_params_serializer.data.get('image_list')[0],
self.node_params_serializer.data.get('image_list')[1:])
return self.execute(image=res, **self.node_params_serializer.data, **self.flow_params_serializer.data)

def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, history_chat_record, stream, chat_id,
if [WorkflowMode.KNOWLEDGE, WorkflowMode.KNOWLEDGE_LOOP].__contains__(
self.workflow_manage.flow.workflow_mode):
return self.execute(image=res, **self.node_params_serializer.data, **self.flow_params_serializer.data,
**{'history_chat_record': [], 'stream': True, 'chat_record_id': None})
else:
return self.execute(image=res, **self.node_params_serializer.data, **self.flow_params_serializer.data)

def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, history_chat_record, stream,
model_params_setting,
chat_record_id,
image,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are no significant irregularities or potential issues in the provided code. However, there's an additional piece of logic added to handle specific knowledge workflows (KNOWLEDGE and KNOWLEDGE_LOOP) that modifies the execution parameters before calling the _run() method internally:

if [WorkflowMode.KNOWLEDGE, WorkflowMode.KNOWLEDGE_LOOP].__contains__(self.workflow_manage.flow.workflow_mode):
    return self.execute(image=res, **self.node_params_serializer.data, **self.flow_params_serializer.data,
                        **{'history_chat_record': [], 'stream': True,  'chat_record_id': None})
else:
    return self._run()

This addition helps ensure compatibility with other workflow modes while setting default values appropriate for knowledge-related workflows, such as having an empty history record and enabling streaming.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def save_context(self, details, workflow_manage):
if self.node_params.get('is_result', False):
self.answer_text = details.get('answer')

def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, history_chat_record, stream, chat_id,
def execute(self, model_id, system, prompt, dialogue_number, dialogue_type, history_chat_record, stream,
model_params_setting,
chat_record_id,
image,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are several issues in this code snippet:

  1. Line Length: The line length exceeds Python's recommended maximum of 80 characters. This can make the code harder to read and maintain.

  2. Variable Naming: The variable names workflow_manage, model_id, stream, image, and chat_record_id should be more descriptive to enhance readability.

  3. Function Signature Complexity: While not incorrect, keeping function signatures concise is generally good practice.

  4. Return Statement: Since there seems to be no explicit return statement at the end of the function, it might be an accidental omission.

Optimizations and Suggestions

  1. Improve Variable Names:

    def save_context(self, conversation_details, workflow_management):
        if conversation_details.get('is_response', False):
            self.answer_text = conversation_details.get('response_content')
  2. Refactor Line Length:
    Break down long lines into more manageable pieces using parentheses or continuation lines with backslashes (\) for continued expressions within parentheses.

  3. Add Return Statement (if needed):
    Add a return statement at the end of the function if necessary. For example:

    def execute(
        self,
        model_identifier=None,
        system_prompt=None,
        user_input=None,
        dialog_number=None,
        dialog_type="text",
        previous_conversation_records=None,
        streaming=False,
        chat_log_id=None,
        attached_image=None
    ):
        # Function implementation here
        
        return None  # Or any specific output depending on context

These changes will improve the readability and usability of the code while maintaining its functionality.

Expand Down
Loading