add iteration support

This commit is contained in:
takatost
2024-07-25 23:07:27 +08:00
parent df133168dd
commit ae351bd40e
11 changed files with 193 additions and 162 deletions

View File

@ -1,5 +1,6 @@
import uuid
from typing import Optional, cast
from collections.abc import Mapping
from typing import Any, Optional, cast
from pydantic import BaseModel, Field
@ -61,7 +62,7 @@ class Graph(BaseModel):
@classmethod
def init(cls,
graph_config: dict,
graph_config: Mapping[str, Any],
root_node_id: Optional[str] = None) -> "Graph":
"""
Init graph

View File

@ -1,3 +1,6 @@
from collections.abc import Mapping
from typing import Any
from pydantic import BaseModel, Field
from core.app.entities.app_invoke_entities import InvokeFrom
@ -11,6 +14,7 @@ class GraphInitParams(BaseModel):
app_id: str = Field(..., description="app id")
workflow_type: WorkflowType = Field(..., description="workflow type")
workflow_id: str = Field(..., description="workflow id")
graph_config: Mapping[str, Any] = Field(..., description="graph config")
user_id: str = Field(..., description="user id")
user_from: UserFrom = Field(..., description="user from, account or end-user")
invoke_from: InvokeFrom = Field(..., description="invoke from, service-api, web-app, explore or debugger")

View File

@ -2,8 +2,8 @@ import logging
import queue
import threading
import time
from collections.abc import Generator
from typing import Optional
from collections.abc import Generator, Mapping
from typing import Any, Optional
from flask import Flask, current_app
from uritemplate.variable import VariableValue
@ -41,24 +41,29 @@ logger = logging.getLogger(__name__)
class GraphEngine:
def __init__(self, tenant_id: str,
app_id: str,
workflow_type: WorkflowType,
workflow_id: str,
user_id: str,
user_from: UserFrom,
invoke_from: InvokeFrom,
call_depth: int,
graph: Graph,
variable_pool: VariablePool,
max_execution_steps: int,
max_execution_time: int) -> None:
def __init__(
self,
tenant_id: str,
app_id: str,
workflow_type: WorkflowType,
workflow_id: str,
user_id: str,
user_from: UserFrom,
invoke_from: InvokeFrom,
call_depth: int,
graph: Graph,
graph_config: Mapping[str, Any],
variable_pool: VariablePool,
max_execution_steps: int,
max_execution_time: int
) -> None:
self.graph = graph
self.init_params = GraphInitParams(
tenant_id=tenant_id,
app_id=app_id,
workflow_type=workflow_type,
workflow_id=workflow_id,
graph_config=graph_config,
user_id=user_id,
user_from=user_from,
invoke_from=invoke_from,