Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #data_models > silence_timer
- from enum import Enum
- from typing import Dict, Optional, Union, List
- from pydantic import BaseModel, Field
- from uuid import UUID
- import uuid
- class SilenceTypes(str, Enum):
- CHECK_CUSTOMER = "check_customer"
- HANG_UP = "hang_up"
- class LLMMessage(BaseModel):
- role: str
- message: str
- class TimerState(BaseModel):
- timeout: float
- task: Optional[object] = None
- is_running: bool = False
- is_paused: bool = False
- pause_time: Optional[float] = None
- remaining_time: Optional[float] = None
- class SilenceTimerConfig(BaseModel):
- id: UUID = Field(description="Unique identifier for the silence timer configuration")
- ######### from the DB #########
- # Timeouts
- check_customer_timeout: float = Field(default=30.0, description="Timeout for checking customer presence")
- hangup_timeout: float = Field(default=60.0, description="Timeout before hanging up")
- # Feature flags
- enable_check_customer: bool = Field(default=True, description="Enable/disable customer presence check")
- enable_hangup: bool = Field(default=True, description="Enable/disable automatic hangup")
- # Optional messages - can be overridden or use defaults
- default_messages: Optional[Dict[SilenceTypes, Union[str, List[str]]]] = Field(
- default={
- SilenceTypes.CHECK_CUSTOMER: [
- "Are you still there?",
- "Hello, are you with me?",
- "I noticed you've been quiet. Are you still there?"
- ],
- SilenceTypes.HANG_UP: [
- "Since I haven't heard from you, I'll end the call now. Goodbye!",
- "I'll have to go now. Have a great day!"
- ]
- }
- )
- llm_messages: Optional[Dict[SilenceTypes, LLMMessage]] = Field(
- default={
- SilenceTypes.CHECK_CUSTOMER: LLMMessage(
- role="system",
- message="The user has been silent. Generate a natural way to check if they're still there."
- ),
- SilenceTypes.HANG_UP: LLMMessage(
- role="system",
- message="The user has been silent for too long. Generate a polite message to end the call."
- )
- }
- )
- class Config:
- from_attributes = True # Allows ORM model conversion
- # Create a default instance of the config
- default_config = SilenceTimerConfig(
- id=uuid.uuid4(), # Generate a default UUID for the default config
- check_customer_timeout=30.0,
- hangup_timeout=60.0,
- enable_check_customer=True,
- enable_hangup=True
- )
- # Export these for backward compatibility
- SILENCE_TYPE_TO_MESSAGE = default_config.default_messages
- SILENCE_TYPE_TO_LLM_MESSAGE = default_config.llm_messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement