mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-10-06 02:48:22 +00:00
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
"""Command service module for managing and executing command-based workflows."""
|
|
|
|
from loguru import logger
|
|
|
|
from .base_service import BaseService
|
|
from ..flow import CmdFlow, BaseFlow
|
|
from ..utils.common_utils import run_coro_safely
|
|
|
|
|
|
class CmdService(BaseService):
|
|
"""Service implementation for handling command flow execution logic."""
|
|
|
|
def __init__(self, **kwargs):
|
|
"""Initialize the command service instance."""
|
|
super().__init__(**kwargs)
|
|
self._cmd_flow: CmdFlow | None = None
|
|
|
|
def integrate_flow(self, flow: BaseFlow) -> str | None:
|
|
"""Integrate the workflow configuration into the command service."""
|
|
self._cmd_flow = CmdFlow(flow=self.service_config.cmd.flow)
|
|
|
|
def run(self):
|
|
"""Execute the command flow in either asynchronous or synchronous mode."""
|
|
super().run()
|
|
kwargs = self.service_config.cmd.model_extra
|
|
if self._cmd_flow.async_mode:
|
|
response = run_coro_safely(self._cmd_flow.call(**kwargs))
|
|
else:
|
|
response = self._cmd_flow.call_sync(**kwargs)
|
|
|
|
if response.answer:
|
|
logger.info(f"response.answer={response.answer}")
|