Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
refactor: convert isinstance chains to match/case (part 7) (#35902) (#36826)
Evan372a2e3e9c96
diff --git a/api/core/app/apps/common/workflow_response_converter.py b/api/core/app/apps/common/workflow_response_converter.pyindex 297279954ee..96fc55526cb 100644--- a/api/core/app/apps/common/workflow_response_converter.py+++ b/api/core/app/apps/common/workflow_response_converter.py@@ -562,15 +562,16 @@ class WorkflowResponseConverter:outputs, outputs_truncated = self._truncate_mapping(encoded_outputs)metadata = self._merge_metadata(event.execution_metadata, snapshot)- if isinstance(event, QueueNodeSucceededEvent):- status = WorkflowNodeExecutionStatus.SUCCEEDED- error_message = event.error- elif isinstance(event, QueueNodeFailedEvent):- status = WorkflowNodeExecutionStatus.FAILED- error_message = event.error- else:- status = WorkflowNodeExecutionStatus.EXCEPTION- error_message = event.error+ match event:+ case QueueNodeSucceededEvent():+ status = WorkflowNodeExecutionStatus.SUCCEEDED+ error_message = event.error+ case QueueNodeFailedEvent():+ status = WorkflowNodeExecutionStatus.FAILED+ error_message = event.error+ case _:+ status = WorkflowNodeExecutionStatus.EXCEPTION+ error_message = event.errorreturn NodeFinishStreamResponse(task_id=task_id,diff --git a/api/core/base/tts/app_generator_tts_publisher.py b/api/core/base/tts/app_generator_tts_publisher.pyindex 7002b1a4701..b00d2b56135 100644--- a/api/core/base/tts/app_generator_tts_publisher.py+++ b/api/core/base/tts/app_generator_tts_publisher.py@@ -91,26 +91,28 @@ class AppGeneratorTTSPublisher:)future_queue.put(futures_result)break- elif isinstance(message.event, QueueAgentMessageEvent | QueueLLMChunkEvent):- message_content = message.event.chunk.delta.message.content- if not message_content:- continue- match message_content:- case str():- self.msg_text += message_content- case list():- for content in message_content:- if not isinstance(content, TextPromptMessageContent):- continue- self.msg_text += content.data- elif isinstance(message.event, QueueTextChunkEvent):- self.msg_text += message.event.text- elif isinstance(message.event, QueueNodeSucceededEvent):- if message.event.outputs is None:- continue- output = message.event.outputs.get("output", "")- if isinstance(output, str):- self.msg_text += output+ else:+ match message.event:+ case QueueAgentMessageEvent() | QueueLLMChunkEvent():+ message_content = message.event.chunk.delta.message.content+ if not message_content:+ continue+ match message_content:+ case str():+ self.msg_text += message_content+ case list():+ for content in message_content:+ if not isinstance(content, TextPromptMessageContent):+ continue+ self.msg_text += content.data+ case QueueTextChunkEvent():+ self.msg_text += message.event.text+ case QueueNodeSucceededEvent():+ if message.event.outputs is None:+ continue+ output = message.event.outputs.get("output", "")+ if isinstance(output, str):+ self.msg_text += outputself.last_message = messagesentence_arr, text_tmp = self._extract_sentence(self.msg_text)if len(sentence_arr) >= min(self.max_sentence, 7):diff --git a/api/core/rag/extractor/blob/blob.py b/api/core/rag/extractor/blob/blob.pyindex b2e6d782d82..4537c1b5373 100644--- a/api/core/rag/extractor/blob/blob.py+++ b/api/core/rag/extractor/blob/blob.py@@ -54,36 +54,39 @@ class Blob(BaseModel):def as_string(self) -> str:"""Read data as a string."""- if self.data is None and self.path:- return Path(str(self.path)).read_text(encoding=self.encoding)- elif isinstance(self.data, bytes):- return self.data.decode(self.encoding)- elif isinstance(self.data, str):- return self.data- else:- raise ValueError(f"Unable to get string for blob {self}")+ match self.data:+ case None if self.path:+ return Path(str(self.path)).read_text(encoding=self.encoding)+ case bytes():+ return self.data.decode(self.encoding)+ case str():+ return self.data+ case _:+ raise ValueError(f"Unable to get string for blob {self}")def as_bytes(self) -> bytes:"""Read data as bytes."""- if isinstance(self.data, bytes):- return self.data- elif isinstance(self.data, str):- return self.data.encode(self.encoding)- elif self.data is None and self.path:- return Path(str(self.path)).read_bytes()- else:- raise ValueError(f"Unable to get bytes for blob {self}")+ match self.data:+ case bytes():+ return self.data+ case str():+ return self.data.encode(self.encoding)+ case None if self.path:+ return Path(str(self.path)).read_bytes()+ case _:+ raise ValueError(f"Unable to get bytes for blob {self}")@contextlib.contextmanagerdef as_bytes_io(self) -> Generator[BytesIO | BufferedReader, None, None]:"""Read data as a byte stream."""- if isinstance(self.data, bytes):- yield BytesIO(self.data)- elif self.data is None and self.path:- with open(str(self.path), "rb") as f:- yield f- else:- raise NotImplementedError(f"Unable to convert blob {self}")+ match self.data:+ case bytes():+ yield BytesIO(self.data)+ case None if self.path:+ with open(str(self.path), "rb") as f:+ yield f+ case _:+ raise NotImplementedError(f"Unable to convert blob {self}")@classmethoddef from_path(