event.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. from datetime import datetime
  2. from pydantic import BaseModel, Field
  3. from core.model_runtime.entities.llm_entities import LLMUsage
  4. from core.workflow.entities.node_entities import NodeRunResult
  5. from models.workflow import WorkflowNodeExecutionStatus
  6. class RunCompletedEvent(BaseModel):
  7. run_result: NodeRunResult = Field(..., description="run result")
  8. class RunStreamChunkEvent(BaseModel):
  9. chunk_content: str = Field(..., description="chunk content")
  10. from_variable_selector: list[str] = Field(..., description="from variable selector")
  11. class RunRetrieverResourceEvent(BaseModel):
  12. retriever_resources: list[dict] = Field(..., description="retriever resources")
  13. context: str = Field(..., description="context")
  14. class ModelInvokeCompletedEvent(BaseModel):
  15. """
  16. Model invoke completed
  17. """
  18. text: str
  19. usage: LLMUsage
  20. finish_reason: str | None = None
  21. class RunRetryEvent(BaseModel):
  22. """Node Run Retry event"""
  23. error: str = Field(..., description="error")
  24. retry_index: int = Field(..., description="Retry attempt number")
  25. start_at: datetime = Field(..., description="Retry start time")
  26. class SingleStepRetryEvent(NodeRunResult):
  27. """Single step retry event"""
  28. status: str = WorkflowNodeExecutionStatus.RETRY.value
  29. elapsed_time: float = Field(..., description="elapsed time")