From a571b3abb277d8fc666b08aaeec4894860d44d3c Mon Sep 17 00:00:00 2001 From: Stream Date: Wed, 28 Jan 2026 06:43:08 +0800 Subject: [PATCH] chore: fix type issues --- api/controllers/console/app/generator.py | 8 ++++---- api/core/llm_generator/llm_generator.py | 2 ++ api/core/workflow/nodes/llm/node.py | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/api/controllers/console/app/generator.py b/api/controllers/console/app/generator.py index 2349f16b9b..63870f8038 100644 --- a/api/controllers/console/app/generator.py +++ b/api/controllers/console/app/generator.py @@ -70,8 +70,8 @@ class ContextGeneratePayload(BaseModel): model_config_data: dict[str, Any] = Field(..., alias="model_config", description="Model configuration") available_vars: list[AvailableVarPayload] = Field(..., description="Available variables from upstream nodes") parameter_info: ParameterInfoPayload = Field(..., description="Target parameter metadata from the frontend") - code_context: CodeContextPayload | None = Field( - default=None, description="Existing code node context for incremental generation" + code_context: CodeContextPayload = Field( + description="Existing code node context for incremental generation" ) @@ -81,8 +81,8 @@ class SuggestedQuestionsPayload(BaseModel): language: str = Field( default="English", description="Language for generated questions (e.g. English, Chinese, Japanese)" ) - model_config_data: dict[str, Any] | None = Field( - default=None, + model_config_data: dict[str, Any] = Field( + default_factory=dict, alias="model_config", description="Model configuration (optional, uses system default if not provided)", ) diff --git a/api/core/llm_generator/llm_generator.py b/api/core/llm_generator/llm_generator.py index ab24c4328e..f8741729f9 100644 --- a/api/core/llm_generator/llm_generator.py +++ b/api/core/llm_generator/llm_generator.py @@ -730,6 +730,8 @@ Generate {language} code to extract/transform available variables for the target raise ValueError("Workflow not found for the given app model.") last_run = workflow_service.get_node_last_run(app_model=app, workflow=workflow, node_id=node_id) try: + if not last_run: + raise ValueError() node_type = last_run.node_type except Exception: try: diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py index a25e9cb1f2..924be1a2e2 100644 --- a/api/core/workflow/nodes/llm/node.py +++ b/api/core/workflow/nodes/llm/node.py @@ -1402,12 +1402,12 @@ class LLMNode(Node[LLMNodeData]): # Create typed NodeData from dict typed_node_data = LLMNodeData.model_validate(node_data) - prompt_template = typed_node_data.prompt_template + prompt_template: (Sequence[LLMNodeChatModelMessage | PromptMessageContext] | + LLMNodeCompletionModelPromptTemplate) = typed_node_data.prompt_template variable_selectors = [] prompt_context_selectors: list[Sequence[str]] = [] if isinstance(prompt_template, list): for prompt in prompt_template: - prompt: LLMNodeChatModelMessage | PromptMessageContext if isinstance(prompt, LLMNodeChatModelMessage) and prompt.edition_type == "jinja2": variable_template_parser = VariableTemplateParser(template=prompt.text) variable_selectors.extend(variable_template_parser.extract_variable_selectors()) @@ -1453,10 +1453,11 @@ class LLMNode(Node[LLMNodeData]): if isinstance(prompt_template, list): for prompt in prompt_template: - prompt: LLMNodeChatModelMessage | PromptMessageContext if isinstance(prompt, LLMNodeChatModelMessage) and prompt.edition_type == "jinja2": enable_jinja = True break + if isinstance(prompt, PromptMessageContext): + prompt_context_selectors.append(prompt.value_selector) else: prompt_template: LLMNodeCompletionModelPromptTemplate enable_jinja = True