2026-10-30 16:13:53 +08:00
|
|
|
"""Execute plugin callbacks into standalone workflow nodes."""
|
|
|
|
|
|
2026-03-25 21:58:56 +08:00
|
|
|
from graphon.enums import BuiltinNodeTypes
|
2026-03-28 05:05:32 +08:00
|
|
|
from graphon.nodes.llm.entities import ModelConfig as LLMModelConfig
|
2026-10-30 16:13:53 +08:00
|
|
|
from graphon.nodes.parameter_extractor.entities import ParameterConfig, ParameterExtractorNodeData
|
|
|
|
|
from graphon.nodes.question_classifier.entities import ClassConfig, QuestionClassifierNodeData
|
|
|
|
|
from services.knowledge.retrieval.retrieval import KnowledgeRetriever
|
2025-02-17 17:05:13 +08:00
|
|
|
from services.workflow_service import WorkflowService
|
|
|
|
|
|
|
|
|
|
|
2026-10-30 16:13:53 +08:00
|
|
|
class PluginNodeInvocationService:
|
|
|
|
|
"""Invoke nodes with workflow and retrieval dependencies bound at construction."""
|
|
|
|
|
|
|
|
|
|
def __init__(self, *, workflow: WorkflowService, knowledge_retrieval: KnowledgeRetriever) -> None:
|
|
|
|
|
self._workflow = workflow
|
|
|
|
|
self._knowledge_retrieval = knowledge_retrieval
|
|
|
|
|
|
2025-02-17 17:05:13 +08:00
|
|
|
def invoke_parameter_extractor(
|
2026-10-30 16:13:53 +08:00
|
|
|
self,
|
2025-02-17 17:05:13 +08:00
|
|
|
tenant_id: str,
|
|
|
|
|
user_id: str,
|
|
|
|
|
parameters: list[ParameterConfig],
|
2026-03-28 05:05:32 +08:00
|
|
|
model_config: LLMModelConfig,
|
2025-02-17 17:05:13 +08:00
|
|
|
instruction: str,
|
|
|
|
|
query: str,
|
2026-10-30 16:13:53 +08:00
|
|
|
) -> dict[str, object]:
|
2025-02-17 17:05:13 +08:00
|
|
|
node_id = "1919810"
|
|
|
|
|
node_data = ParameterExtractorNodeData(
|
|
|
|
|
title="parameter_extractor",
|
|
|
|
|
desc="parameter_extractor",
|
|
|
|
|
parameters=parameters,
|
|
|
|
|
reasoning_mode="function_call",
|
|
|
|
|
query=[node_id, "query"],
|
|
|
|
|
model=model_config,
|
2026-10-30 16:13:53 +08:00
|
|
|
instruction=instruction, # instructions with variables are not supported
|
2025-02-17 17:05:13 +08:00
|
|
|
)
|
|
|
|
|
node_data_dict = node_data.model_dump()
|
2026-03-15 15:24:59 +08:00
|
|
|
node_data_dict["type"] = BuiltinNodeTypes.PARAMETER_EXTRACTOR
|
2026-10-30 16:13:53 +08:00
|
|
|
execution = self._workflow.run_free_workflow_node(
|
2025-02-17 17:05:13 +08:00
|
|
|
node_data_dict,
|
|
|
|
|
tenant_id=tenant_id,
|
|
|
|
|
user_id=user_id,
|
|
|
|
|
node_id=node_id,
|
2026-10-30 16:13:53 +08:00
|
|
|
user_inputs={f"{node_id}.query": query},
|
|
|
|
|
knowledge_retrieval=self._knowledge_retrieval,
|
2025-02-17 17:05:13 +08:00
|
|
|
)
|
|
|
|
|
return {
|
2025-05-17 12:31:27 +08:00
|
|
|
"inputs": execution.inputs,
|
|
|
|
|
"outputs": execution.outputs,
|
|
|
|
|
"process_data": execution.process_data,
|
2025-02-17 17:05:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def invoke_question_classifier(
|
2026-10-30 16:13:53 +08:00
|
|
|
self,
|
2025-02-17 17:05:13 +08:00
|
|
|
tenant_id: str,
|
|
|
|
|
user_id: str,
|
2026-03-28 05:05:32 +08:00
|
|
|
model_config: LLMModelConfig,
|
2025-02-17 17:05:13 +08:00
|
|
|
classes: list[ClassConfig],
|
|
|
|
|
instruction: str,
|
|
|
|
|
query: str,
|
2026-10-30 16:13:53 +08:00
|
|
|
) -> dict[str, object]:
|
2025-02-17 17:05:13 +08:00
|
|
|
node_id = "1919810"
|
|
|
|
|
node_data = QuestionClassifierNodeData(
|
|
|
|
|
title="question_classifier",
|
|
|
|
|
desc="question_classifier",
|
|
|
|
|
query_variable_selector=[node_id, "query"],
|
|
|
|
|
model=model_config,
|
|
|
|
|
classes=classes,
|
2026-10-30 16:13:53 +08:00
|
|
|
instruction=instruction, # instructions with variables are not supported
|
2025-02-17 17:05:13 +08:00
|
|
|
)
|
2026-10-30 16:13:53 +08:00
|
|
|
execution = self._workflow.run_free_workflow_node(
|
|
|
|
|
node_data.model_dump(),
|
2025-02-17 17:05:13 +08:00
|
|
|
tenant_id=tenant_id,
|
|
|
|
|
user_id=user_id,
|
|
|
|
|
node_id=node_id,
|
2026-10-30 16:13:53 +08:00
|
|
|
user_inputs={f"{node_id}.query": query},
|
|
|
|
|
knowledge_retrieval=self._knowledge_retrieval,
|
2025-02-17 17:05:13 +08:00
|
|
|
)
|
|
|
|
|
return {
|
2025-05-17 12:31:27 +08:00
|
|
|
"inputs": execution.inputs,
|
|
|
|
|
"outputs": execution.outputs,
|
|
|
|
|
"process_data": execution.process_data,
|
2025-02-17 17:05:13 +08:00
|
|
|
}
|