Add conversation_id to workflow

pull/20652/head
IamIpanda 12 months ago
parent 5ccfb1f4ba
commit ae45f2c230

@ -48,6 +48,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
streaming: Literal[True], streaming: Literal[True],
call_depth: int, call_depth: int,
workflow_thread_pool_id: Optional[str], workflow_thread_pool_id: Optional[str],
conversation_id: Optional[str],
) -> Generator[Mapping | str, None, None]: ... ) -> Generator[Mapping | str, None, None]: ...
@overload @overload
@ -62,6 +63,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
streaming: Literal[False], streaming: Literal[False],
call_depth: int, call_depth: int,
workflow_thread_pool_id: Optional[str], workflow_thread_pool_id: Optional[str],
conversation_id: Optional[str],
) -> Mapping[str, Any]: ... ) -> Mapping[str, Any]: ...
@overload @overload
@ -76,6 +78,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
streaming: bool, streaming: bool,
call_depth: int, call_depth: int,
workflow_thread_pool_id: Optional[str], workflow_thread_pool_id: Optional[str],
conversation_id: Optional[str],
) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]: ... ) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]: ...
def generate( def generate(
@ -89,6 +92,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
streaming: bool = True, streaming: bool = True,
call_depth: int = 0, call_depth: int = 0,
workflow_thread_pool_id: Optional[str] = None, workflow_thread_pool_id: Optional[str] = None,
conversation_id: Optional[str] = None,
) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]: ) -> Union[Mapping[str, Any], Generator[Mapping | str, None, None]]:
files: Sequence[Mapping[str, Any]] = args.get("files") or [] files: Sequence[Mapping[str, Any]] = args.get("files") or []
@ -133,6 +137,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
call_depth=call_depth, call_depth=call_depth,
trace_manager=trace_manager, trace_manager=trace_manager,
workflow_execution_id=workflow_run_id, workflow_execution_id=workflow_run_id,
conversation_id=conversation_id,
) )
contexts.plugin_tool_providers.set({}) contexts.plugin_tool_providers.set({})
@ -280,6 +285,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
node_id=node_id, inputs=args["inputs"] node_id=node_id, inputs=args["inputs"]
), ),
workflow_execution_id=str(uuid.uuid4()), workflow_execution_id=str(uuid.uuid4()),
conversation_id=None,
) )
contexts.plugin_tool_providers.set({}) contexts.plugin_tool_providers.set({})
contexts.plugin_tool_providers_lock.set(threading.Lock()) contexts.plugin_tool_providers_lock.set(threading.Lock())
@ -356,6 +362,7 @@ class WorkflowAppGenerator(BaseAppGenerator):
extras={"auto_generate_conversation_name": False}, extras={"auto_generate_conversation_name": False},
single_loop_run=WorkflowAppGenerateEntity.SingleLoopRunEntity(node_id=node_id, inputs=args["inputs"]), single_loop_run=WorkflowAppGenerateEntity.SingleLoopRunEntity(node_id=node_id, inputs=args["inputs"]),
workflow_execution_id=str(uuid.uuid4()), workflow_execution_id=str(uuid.uuid4()),
conversation_id=None,
) )
contexts.plugin_tool_providers.set({}) contexts.plugin_tool_providers.set({})
contexts.plugin_tool_providers_lock.set(threading.Lock()) contexts.plugin_tool_providers_lock.set(threading.Lock())

@ -96,6 +96,7 @@ class WorkflowAppRunner(WorkflowBasedAppRunner):
SystemVariableKey.APP_ID: app_config.app_id, SystemVariableKey.APP_ID: app_config.app_id,
SystemVariableKey.WORKFLOW_ID: app_config.workflow_id, SystemVariableKey.WORKFLOW_ID: app_config.workflow_id,
SystemVariableKey.WORKFLOW_EXECUTION_ID: self.application_generate_entity.workflow_execution_id, SystemVariableKey.WORKFLOW_EXECUTION_ID: self.application_generate_entity.workflow_execution_id,
SystemVariableKey.CONVERSATION_ID: self.application_generate_entity.conversation_id,
} }
variable_pool = VariablePool( variable_pool = VariablePool(

@ -205,6 +205,7 @@ class WorkflowAppGenerateEntity(AppGenerateEntity):
# app config # app config
app_config: WorkflowUIBasedAppConfig app_config: WorkflowUIBasedAppConfig
workflow_execution_id: str workflow_execution_id: str
conversation_id: Optional[str]
class SingleIterationRunEntity(BaseModel): class SingleIterationRunEntity(BaseModel):
""" """

@ -165,6 +165,7 @@ class PluginAppBackwardsInvocation(BaseBackwardsInvocation):
streaming=stream, streaming=stream,
call_depth=1, call_depth=1,
workflow_thread_pool_id=None, workflow_thread_pool_id=None,
conversation_id=None,
) )
@classmethod @classmethod

@ -95,6 +95,7 @@ class WorkflowTool(Tool):
streaming=False, streaming=False,
call_depth=self.workflow_call_depth + 1, call_depth=self.workflow_call_depth + 1,
workflow_thread_pool_id=self.thread_pool_id, workflow_thread_pool_id=self.thread_pool_id,
conversation_id=conversation_id,
) )
assert isinstance(result, dict) assert isinstance(result, dict)
data = result.get("data", {}) data = result.get("data", {})

@ -113,6 +113,7 @@ class AppGenerateService:
streaming=streaming, streaming=streaming,
call_depth=0, call_depth=0,
workflow_thread_pool_id=None, workflow_thread_pool_id=None,
conversation_id=None,
), ),
), ),
request_id, request_id,

@ -200,11 +200,11 @@ const formatItem = (
variable: 'sys.dialogue_count', variable: 'sys.dialogue_count',
type: VarType.number, type: VarType.number,
}) })
res.vars.push({
variable: 'sys.conversation_id',
type: VarType.string,
})
} }
res.vars.push({
variable: 'sys.conversation_id',
type: VarType.string,
})
res.vars.push({ res.vars.push({
variable: 'sys.user_id', variable: 'sys.user_id',
type: VarType.string, type: VarType.string,

Loading…
Cancel
Save