Advertisement
aa11111111111

Untitled

Jan 16th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.77 KB | None | 0 0
  1. #data_models > silence_timer
  2.  
  3. from enum import Enum
  4. from typing import Dict, Optional, Union, List
  5. from pydantic import BaseModel, Field
  6. from uuid import UUID
  7. import uuid
  8.  
  9. class SilenceTypes(str, Enum):
  10.     CHECK_CUSTOMER = "check_customer"
  11.     HANG_UP = "hang_up"
  12.  
  13. class LLMMessage(BaseModel):
  14.     role: str
  15.     message: str
  16.  
  17. class TimerState(BaseModel):
  18.     timeout: float
  19.     task: Optional[object] = None
  20.     is_running: bool = False
  21.     is_paused: bool = False
  22.     pause_time: Optional[float] = None
  23.     remaining_time: Optional[float] = None
  24.  
  25. class SilenceTimerConfig(BaseModel):
  26.     id: UUID = Field(description="Unique identifier for the silence timer configuration")
  27.    
  28.     ######### from the DB #########
  29.  
  30.     # Timeouts
  31.     check_customer_timeout: float = Field(default=30.0, description="Timeout for checking customer presence")
  32.     hangup_timeout: float = Field(default=60.0, description="Timeout before hanging up")
  33.    
  34.     # Feature flags
  35.     enable_check_customer: bool = Field(default=True, description="Enable/disable customer presence check")
  36.     enable_hangup: bool = Field(default=True, description="Enable/disable automatic hangup")
  37.    
  38.    
  39.     # Optional messages - can be overridden or use defaults
  40.     default_messages: Optional[Dict[SilenceTypes, Union[str, List[str]]]] = Field(
  41.         default={
  42.             SilenceTypes.CHECK_CUSTOMER: [
  43.                 "Are you still there?",
  44.                 "Hello, are you with me?",
  45.                 "I noticed you've been quiet. Are you still there?"
  46.             ],
  47.             SilenceTypes.HANG_UP: [
  48.                 "Since I haven't heard from you, I'll end the call now. Goodbye!",
  49.                 "I'll have to go now. Have a great day!"
  50.             ]
  51.         }
  52.     )
  53.     llm_messages: Optional[Dict[SilenceTypes, LLMMessage]] = Field(
  54.         default={
  55.             SilenceTypes.CHECK_CUSTOMER: LLMMessage(
  56.                 role="system",
  57.                 message="The user has been silent. Generate a natural way to check if they're still there."
  58.             ),
  59.             SilenceTypes.HANG_UP: LLMMessage(
  60.                 role="system",
  61.                 message="The user has been silent for too long. Generate a polite message to end the call."
  62.             )
  63.         }
  64.     )
  65.  
  66.     class Config:
  67.         from_attributes = True  # Allows ORM model conversion
  68.  
  69. # Create a default instance of the config
  70. default_config = SilenceTimerConfig(
  71.     id=uuid.uuid4(),  # Generate a default UUID for the default config
  72.     check_customer_timeout=30.0,
  73.     hangup_timeout=60.0,
  74.     enable_check_customer=True,
  75.     enable_hangup=True
  76. )
  77.  
  78. # Export these for backward compatibility
  79. SILENCE_TYPE_TO_MESSAGE = default_config.default_messages
  80. SILENCE_TYPE_TO_LLM_MESSAGE = default_config.llm_messages
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement