support for variables
This commit is contained in:
parent
1dd8e119bf
commit
111e3064c2
0
chain_service/__main__.py
Normal file
0
chain_service/__main__.py
Normal file
|
|
@ -34,6 +34,7 @@ async def run_chain_controller(
|
|||
task_id=run_chain_input.task_id,
|
||||
namespace_id=chain.namespace_id,
|
||||
recipients=run_chain_input.recipients,
|
||||
variables=run_chain_input.variables,
|
||||
)
|
||||
|
||||
progress_chain = await progress_chain_repository.upsert(progress_chain)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from .base import BaseConfig, BaseMongoModel
|
|||
from enum import Enum
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Literal, Union, Annotated, Optional, List
|
||||
from typing import Literal, Union, Annotated, Optional, Dict, List
|
||||
|
||||
|
||||
class ProgressActionStatusEnum(str, Enum):
|
||||
|
|
@ -51,6 +51,7 @@ Action = Annotated[
|
|||
class ProgressChain(BaseMongoModel):
|
||||
task_id: int
|
||||
namespace_id: str
|
||||
variables: Annotated[Optional[Dict], Field(default={})]
|
||||
recipients: Annotated[Optional[List[int]], Field(default=[])]
|
||||
name: Annotated[Optional[str], Field(default=None)]
|
||||
actions: Annotated[Optional[List[Action]], Field(default=[])]
|
||||
|
|
@ -62,11 +63,18 @@ class ProgressChain(BaseMongoModel):
|
|||
chain: Chain,
|
||||
task_id: int,
|
||||
namespace_id: str,
|
||||
variables: Optional[Dict] = {},
|
||||
recipients: Optional[List[int]] = [],
|
||||
):
|
||||
|
||||
for action in filter(lambda c: c.action_type == "comment", chain.actions):
|
||||
for key, value in variables.items():
|
||||
action.text = action.text.replace(f"{{{{{key}}}}}", value)
|
||||
|
||||
return ProgressChain(
|
||||
task_id=task_id,
|
||||
namespace_id=namespace_id,
|
||||
variables=variables,
|
||||
recipients=recipients,
|
||||
name=chain.name,
|
||||
actions=map(Chain.model_dump, chain.actions),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
from .base import BaseConfig
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Annotated, Optional, List
|
||||
from typing import Annotated, Optional, Dict, List
|
||||
|
||||
|
||||
class RunChainInput(BaseModel):
|
||||
task_id: int
|
||||
chain_id: str
|
||||
variables: Annotated[Optional[Dict], Field(default={})]
|
||||
recipients: Annotated[Optional[List[int]], Field(default=[])]
|
||||
|
||||
class Config(BaseConfig):
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user