mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-16 08:25:18 +02:00
chore: code refactor
This commit is contained in:
parent
c0cbc65de3
commit
c7812bf189
29 changed files with 538 additions and 800 deletions
|
|
@ -108,13 +108,16 @@ class PipecatEngine:
|
|||
# Custom tool manager (initialized in initialize())
|
||||
self._custom_tool_manager: Optional[CustomToolManager] = None
|
||||
|
||||
# Tracks whether a call transfer is in progress
|
||||
self._transferring_call: bool = False
|
||||
|
||||
# Embeddings configuration (passed from run_pipeline.py)
|
||||
self._embeddings_api_key: Optional[str] = embeddings_api_key
|
||||
self._embeddings_model: Optional[str] = embeddings_model
|
||||
self._embeddings_base_url: Optional[str] = embeddings_base_url
|
||||
|
||||
# Transfer state tracking - prevents auto hang-up during call transfers
|
||||
self._transfer_in_progress: bool = False
|
||||
|
||||
# Audio configuration (set via set_audio_config from _run_pipeline)
|
||||
self._audio_config = None
|
||||
|
||||
async def _get_organization_id(self) -> Optional[int]:
|
||||
"""Get and cache the organization ID from workflow run."""
|
||||
|
|
@ -248,7 +251,7 @@ class PipecatEngine:
|
|||
await function_call_params.result_callback(
|
||||
result, properties=properties
|
||||
)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in transition function {name}: {str(e)}")
|
||||
error_result = {"status": "error", "error": str(e)}
|
||||
|
|
@ -281,7 +284,7 @@ class PipecatEngine:
|
|||
async def calculate_func(function_call_params: FunctionCallParams) -> None:
|
||||
logger.info(f"LLM Function Call EXECUTED: safe_calculator")
|
||||
logger.info(f"Arguments: {function_call_params.arguments}")
|
||||
|
||||
|
||||
try:
|
||||
expr = function_call_params.arguments.get("expression", "")
|
||||
result = safe_calculator(expr)
|
||||
|
|
@ -297,7 +300,7 @@ class PipecatEngine:
|
|||
) -> None:
|
||||
logger.info(f"LLM Function Call EXECUTED: get_current_time")
|
||||
logger.info(f"Arguments: {function_call_params.arguments}")
|
||||
|
||||
|
||||
try:
|
||||
timezone = function_call_params.arguments.get("timezone", "UTC")
|
||||
result = get_current_time(timezone)
|
||||
|
|
@ -308,7 +311,7 @@ class PipecatEngine:
|
|||
async def convert_time_func(function_call_params: FunctionCallParams) -> None:
|
||||
logger.info(f"LLM Function Call EXECUTED: convert_time")
|
||||
logger.info(f"Arguments: {function_call_params.arguments}")
|
||||
|
||||
|
||||
try:
|
||||
result = convert_time(
|
||||
function_call_params.arguments.get("source_timezone"),
|
||||
|
|
@ -339,7 +342,7 @@ class PipecatEngine:
|
|||
async def retrieve_kb_func(function_call_params: FunctionCallParams) -> None:
|
||||
logger.info("LLM Function Call EXECUTED: retrieve_from_knowledge_base")
|
||||
logger.info(f"Arguments: {function_call_params.arguments}")
|
||||
|
||||
|
||||
try:
|
||||
query = function_call_params.arguments.get("query", "")
|
||||
organization_id = await self._get_organization_id()
|
||||
|
|
@ -540,7 +543,9 @@ class PipecatEngine:
|
|||
self._current_node, run_in_background=False
|
||||
)
|
||||
|
||||
frame_to_push = CancelFrame(reason=reason) if abort_immediately else EndFrame(reason=reason)
|
||||
frame_to_push = (
|
||||
CancelFrame(reason=reason) if abort_immediately else EndFrame(reason=reason)
|
||||
)
|
||||
|
||||
# Apply disposition mapping - first try call_disposition if it is,
|
||||
# extracted from the call conversation then fall back to reason
|
||||
|
|
@ -713,6 +718,10 @@ class PipecatEngine:
|
|||
f"Stasis connection set for immediate transfers: {connection.channel_id}"
|
||||
)
|
||||
|
||||
def set_audio_config(self, audio_config) -> None:
|
||||
"""Set the audio configuration for the pipeline."""
|
||||
self._audio_config = audio_config
|
||||
|
||||
def set_mute_pipeline(self, mute: bool) -> None:
|
||||
"""Set the pipeline mute state.
|
||||
|
||||
|
|
@ -725,6 +734,15 @@ class PipecatEngine:
|
|||
logger.debug(f"Setting pipeline mute state to: {mute}")
|
||||
self._mute_pipeline = mute
|
||||
|
||||
def set_transferring_call(self, transferring: bool) -> None:
|
||||
"""Set the call transfer state.
|
||||
|
||||
Args:
|
||||
transferring: True when a call transfer is in progress, False otherwise
|
||||
"""
|
||||
logger.debug(f"Setting transferring call state to: {transferring}")
|
||||
self._transferring_call = transferring
|
||||
|
||||
async def handle_llm_text_frame(self, text: str):
|
||||
"""Accumulate LLM text frames to build reference text."""
|
||||
self._current_llm_generation_reference_text += text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue