From 5200668336781f26e45abaf0eb90f7a22f3d8929 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 14 Mar 2024 12:56:25 +0800 Subject: [PATCH 1/4] fix: null conversation id --- ...nable_tool_file_without_conversation_id.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py diff --git a/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py b/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py new file mode 100644 index 00000000000000..d91288bcf5d7d9 --- /dev/null +++ b/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py @@ -0,0 +1,36 @@ +"""enable tool file without conversation id + +Revision ID: 563cf8bf777b +Revises: b5429b71023c +Create Date: 2024-03-14 04:54:56.679506 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '563cf8bf777b' +down_revision = 'b5429b71023c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('tool_files', schema=None) as batch_op: + batch_op.alter_column('conversation_id', + existing_type=postgresql.UUID(), + nullable=True) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('tool_files', schema=None) as batch_op: + batch_op.alter_column('conversation_id', + existing_type=postgresql.UUID(), + nullable=False) + + # ### end Alembic commands ### From baf536eb2bad33d28e7676d02e55c024f0f44e95 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 14 Mar 2024 12:56:57 +0800 Subject: [PATCH 2/4] fix: linter --- .../563cf8bf777b_enable_tool_file_without_conversation_id.py | 1 - api/models/tools.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py b/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py index d91288bcf5d7d9..299f442de989be 100644 --- a/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py +++ b/api/migrations/versions/563cf8bf777b_enable_tool_file_without_conversation_id.py @@ -6,7 +6,6 @@ """ from alembic import op -import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. diff --git a/api/models/tools.py b/api/models/tools.py index bceef7a8290151..4bdf2503ce0619 100644 --- a/api/models/tools.py +++ b/api/models/tools.py @@ -218,7 +218,7 @@ class ToolFile(db.Model): # tenant id tenant_id = db.Column(UUID, nullable=False) # conversation id - conversation_id = db.Column(UUID, nullable=False) + conversation_id = db.Column(UUID, nullable=True) # file key file_key = db.Column(db.String(255), nullable=False) # mime type From 13a724864dce82f2d9baf6dc07424455b29f993f Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 14 Mar 2024 13:24:48 +0800 Subject: [PATCH 3/4] fix: conversation_id equals to none --- api/core/workflow/nodes/tool/tool_node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/workflow/nodes/tool/tool_node.py b/api/core/workflow/nodes/tool/tool_node.py index b03ad45e6ce8cd..ca217182ccfd5c 100644 --- a/api/core/workflow/nodes/tool/tool_node.py +++ b/api/core/workflow/nodes/tool/tool_node.py @@ -78,7 +78,7 @@ def _convert_tool_messages(self, messages: list[ToolInvokeMessage]) -> tuple[str messages=messages, user_id=self.user_id, tenant_id=self.tenant_id, - conversation_id='', + conversation_id=None, ) # extract plain text and files files = self._extract_tool_response_binary(messages) From d85b5b9134c4c01aca354922d4a667091e12adaf Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Thu, 14 Mar 2024 16:38:22 +0800 Subject: [PATCH 4/4] fix: tool --- api/core/workflow/nodes/tool/entities.py | 11 +++++++++-- api/core/workflow/nodes/tool/tool_node.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/api/core/workflow/nodes/tool/entities.py b/api/core/workflow/nodes/tool/entities.py index 0b3bf76aacfd2a..7eb3cf655b1bdc 100644 --- a/api/core/workflow/nodes/tool/entities.py +++ b/api/core/workflow/nodes/tool/entities.py @@ -3,7 +3,6 @@ from pydantic import BaseModel, validator from core.workflow.entities.base_node_data_entities import BaseNodeData -from core.workflow.entities.variable_entities import VariableSelector ToolParameterValue = Union[str, int, float, bool] @@ -16,8 +15,10 @@ class ToolEntity(BaseModel): tool_configurations: dict[str, ToolParameterValue] class ToolNodeData(BaseNodeData, ToolEntity): - class ToolInput(VariableSelector): + class ToolInput(BaseModel): + variable: str variable_type: Literal['selector', 'static'] + value_selector: Optional[list[str]] value: Optional[str] @validator('value') @@ -25,6 +26,12 @@ def check_value(cls, value, values, **kwargs): if values['variable_type'] == 'static' and value is None: raise ValueError('value is required for static variable') return value + + @validator('value_selector') + def check_value_selector(cls, value_selector, values, **kwargs): + if values['variable_type'] == 'selector' and value_selector is None: + raise ValueError('value_selector is required for selector variable') + return value_selector """ Tool Node Schema diff --git a/api/core/workflow/nodes/tool/tool_node.py b/api/core/workflow/nodes/tool/tool_node.py index ca217182ccfd5c..d0bfd9e7973467 100644 --- a/api/core/workflow/nodes/tool/tool_node.py +++ b/api/core/workflow/nodes/tool/tool_node.py @@ -44,7 +44,7 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult: return NodeRunResult( status=WorkflowNodeExecutionStatus.FAILED, inputs=parameters, - error=f'Failed to invoke tool: {str(e)}' + error=f'Failed to invoke tool: {str(e)}', ) # convert tool messages @@ -56,6 +56,7 @@ def _run(self, variable_pool: VariablePool) -> NodeRunResult: 'text': plain_text, 'files': files }, + inputs=parameters ) def _generate_parameters(self, variable_pool: VariablePool, node_data: ToolNodeData) -> dict: