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
3 changes: 2 additions & 1 deletion apps/application/flow/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,8 @@ async def anext_async(agen):
'ai-chat-node': lambda n: [*(n.get('properties').get('node_data').get('mcp_tool_ids') or []),
*(n.get('properties').get('node_data').get('tool_ids') or []),
*(n.get('properties').get('node_data').get('skill_tool_ids') or [])],
'mcp-node': lambda n: [n.get('properties').get('node_data').get('mcp_tool_id')]
'mcp-node': lambda n: [n.get('properties').get('node_data').get('mcp_tool_id')],
'tool-workflow-lib-node': lambda n: [n.get('properties').get('node_data').get('tool_lib_id')]
},
'MODEL': {'ai-chat-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
'question-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet contains some stylistic improvements and comments that can enhance readability. However, without more context about its purpose and usage within a larger system, there are no substantial optimization suggestions. Here are a few changes you might consider:

  1. Consistency: Ensure consistent spacing around operators (=, or), commas, and other punctuation. This improves readability.

    async def anext_async(agen):
        '''Helper function to yield from gen if defined'''
        try:
            return await agen.__anext__()
        except StopAsyncIteration:
            yield None
            raise
    
    MODELS = {
        'ai-chat-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
        'question-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
    }
  2. Comments: Provide explanatory comments for complex or unusual logic blocks to improve maintainability.

    # Define helper function to yield from generator if it's defined
    async def anext_async(agen):
        """Helper function to yield from generator if it's defined"""
        try:
            return await agen.__anext__()
        except StopAsyncIteration:
            yield None
            raise
    
    MODELS = {
        'ai-chat-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
        'question-node': lambda n: [n.get('properties').get('node_data').get('model_id')],
    }
    
    # Add support for MCP nodes in tool IDs
    NODE_TEMPLATES['NODE-TYPE'] = {  # Replace 'NODE-TYPE' with actual type key
        'mcp-tool-id': ('tool_workflows/multi_component_processor_tool.json'),
        ...
    }
  3. Code Structure: If certain sections of the code involve significant processing or data manipulations, they might benefit from being extracted into separate utility functions.

  4. Error Handling: Ensure proper error handling is implemented and documented.

    # Check if mcp_node exists before accessing properties
    if 'node_template_mcp_node' in obj_info[m]:
        node_template_mcp_node = obj_info[m]['node_template_mcp_node']
        node_type_mcp_tool_ids = [
            id_item['properties'].get('node_data').get('mcp_tool_id')
            for item in node_template_mcp_node['components']
            if item.get('node_type') == mtc.MCP_TOOL_TYPE 
        ]
    else:
        log.error("Missing 'node_template_mcp_node'")
        continue

These adjustments can help clarify the structure and intent of the code, making it easier to read and potentially improving performance or maintaining it over time.

Expand Down
Loading