mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 20:17:29 +08:00
refactor(api): type WorkflowRun.to_dict with WorkflowRunDict TypedDict (#35047)
Co-authored-by: Ke Wang <ke@pika.art>
This commit is contained in:
parent
815c536e05
commit
c34f67495c
@ -671,6 +671,29 @@ class Workflow(Base): # bug
|
|||||||
return str(d)
|
return str(d)
|
||||||
|
|
||||||
|
|
||||||
|
class WorkflowRunDict(TypedDict):
|
||||||
|
id: str
|
||||||
|
tenant_id: str
|
||||||
|
app_id: str
|
||||||
|
workflow_id: str
|
||||||
|
type: WorkflowType
|
||||||
|
triggered_from: WorkflowRunTriggeredFrom
|
||||||
|
version: str
|
||||||
|
graph: Mapping[str, Any]
|
||||||
|
inputs: Mapping[str, Any]
|
||||||
|
status: WorkflowExecutionStatus
|
||||||
|
outputs: Mapping[str, Any]
|
||||||
|
error: str | None
|
||||||
|
elapsed_time: float
|
||||||
|
total_tokens: int
|
||||||
|
total_steps: int
|
||||||
|
created_by_role: CreatorUserRole
|
||||||
|
created_by: str
|
||||||
|
created_at: datetime
|
||||||
|
finished_at: datetime | None
|
||||||
|
exceptions_count: int
|
||||||
|
|
||||||
|
|
||||||
class WorkflowRun(Base):
|
class WorkflowRun(Base):
|
||||||
"""
|
"""
|
||||||
Workflow Run
|
Workflow Run
|
||||||
@ -790,29 +813,29 @@ class WorkflowRun(Base):
|
|||||||
def workflow(self):
|
def workflow(self):
|
||||||
return db.session.scalar(select(Workflow).where(Workflow.id == self.workflow_id))
|
return db.session.scalar(select(Workflow).where(Workflow.id == self.workflow_id))
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self) -> WorkflowRunDict:
|
||||||
return {
|
return WorkflowRunDict(
|
||||||
"id": self.id,
|
id=self.id,
|
||||||
"tenant_id": self.tenant_id,
|
tenant_id=self.tenant_id,
|
||||||
"app_id": self.app_id,
|
app_id=self.app_id,
|
||||||
"workflow_id": self.workflow_id,
|
workflow_id=self.workflow_id,
|
||||||
"type": self.type,
|
type=self.type,
|
||||||
"triggered_from": self.triggered_from,
|
triggered_from=self.triggered_from,
|
||||||
"version": self.version,
|
version=self.version,
|
||||||
"graph": self.graph_dict,
|
graph=self.graph_dict,
|
||||||
"inputs": self.inputs_dict,
|
inputs=self.inputs_dict,
|
||||||
"status": self.status,
|
status=self.status,
|
||||||
"outputs": self.outputs_dict,
|
outputs=self.outputs_dict,
|
||||||
"error": self.error,
|
error=self.error,
|
||||||
"elapsed_time": self.elapsed_time,
|
elapsed_time=self.elapsed_time,
|
||||||
"total_tokens": self.total_tokens,
|
total_tokens=self.total_tokens,
|
||||||
"total_steps": self.total_steps,
|
total_steps=self.total_steps,
|
||||||
"created_by_role": self.created_by_role,
|
created_by_role=self.created_by_role,
|
||||||
"created_by": self.created_by,
|
created_by=self.created_by,
|
||||||
"created_at": self.created_at,
|
created_at=self.created_at,
|
||||||
"finished_at": self.finished_at,
|
finished_at=self.finished_at,
|
||||||
"exceptions_count": self.exceptions_count,
|
exceptions_count=self.exceptions_count,
|
||||||
}
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_dict(cls, data: dict[str, Any]) -> "WorkflowRun":
|
def from_dict(cls, data: dict[str, Any]) -> "WorkflowRun":
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user