-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
230 lines (192 loc) · 8.05 KB
/
config.py
File metadata and controls
230 lines (192 loc) · 8.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""
Configuration File for AI-Powered Customer Success Agent
This file contains non-sensitive configuration settings.
"""
import os
from typing import Dict, Any, Optional
# --- Application Information ---
APP_NAME = "AI Customer Success Agent"
APP_VERSION = "1.0.0"
APP_DESCRIPTION = "Real-time voice-powered customer success agent with AI capabilities"
# --- Murf AI API Configuration ---
MURF_BASE_URL = "https://api.murf.ai/v1"
MURF_STREAM_URL = "https://api.murf.ai/v1/speech/stream"
# Default Murf TTS Voice Configuration
MURF_DEFAULT_VOICE_ID = "en-US-natalie"
MURF_DEFAULT_SPEED = 1.0
MURF_DEFAULT_PITCH = 0.0
MURF_DEFAULT_VOLUME = 1.0
MURF_DEFAULT_AUDIO_FORMAT = "mp3"
MURF_DEFAULT_SAMPLE_RATE = 24000
# Murf API Request Configuration
MURF_REQUEST_TIMEOUT = 30
MURF_MAX_RETRIES = 3
MURF_RETRY_DELAY_BASE = 2
# --- Azure GPT 4.1 LLM Configuration ---
# Azure GPT Endpoint URL
AZURE_GPT_ENDPOINT = "https://models.github.ai/inference"
# The model name you are deploying on Azure
AZURE_GPT_MODEL = "openai/gpt-4.1"
# LLM Generation Parameters (adjust these for desired response behavior)
LLM_MAX_TOKENS = 1000
LLM_TEMPERATURE = 0.7
LLM_TOP_P = 0.95
LLM_FREQUENCY_PENALTY = 0.0
LLM_PRESENCE_PENALTY = 0.0
LLM_STOP_SEQUENCES = "" # Comma-separated list of stop sequences (e.g., "STOP,END")
# LLM Request Configuration
LLM_REQUEST_TIMEOUT = 60
LLM_MAX_RETRIES = 3
LLM_RETRY_DELAY_BASE = 2
# LLM Conversation Context Management
# Max number of messages to keep in conversation history
LLM_MAX_HISTORY_LENGTH = 20
# Max tokens for the entire conversation context (messages + system prompt)
# Adjust based on your LLM's context window (e.g., 8192, 16384, 32768 for GPT-4 variants)
# Keep it less than the model's actual context window to allow for the response.
LLM_MAX_TOKENS_PER_CONTEXT = 4000
# --- OpenAI Whisper STT Configuration ---
# OpenAI Whisper API endpoint (using official OpenAI API)
WHISPER_ENDPOINT = "https://api.openai.com/v1/audio/transcriptions"
# The Whisper model name
WHISPER_MODEL = "whisper-1"
# Whisper STT Configuration
WHISPER_LANGUAGE = "en" # English only for now
WHISPER_RESPONSE_FORMAT = "json" # json, text, srt, verbose_json, vtt
WHISPER_TEMPERATURE = 0.0 # Lower temperature for more consistent transcription
# Whisper Request Configuration
WHISPER_REQUEST_TIMEOUT = 30
WHISPER_MAX_RETRIES = 3
WHISPER_RETRY_DELAY_BASE = 2
# Audio file size limits for Whisper
WHISPER_MAX_FILE_SIZE = 25 * 1024 * 1024 # 25MB (OpenAI's limit)
WHISPER_SUPPORTED_FORMATS = ["mp3", "mp4", "mpeg", "mpga", "m4a", "wav", "webm"]
# --- Flask Application Configuration ---
FLASK_SECRET_KEY = "Vivek@1234!" # Set as requested
FLASK_DEBUG = True # Set to False in production
FLASK_HOST = "0.0.0.0"
FLASK_PORT = 5000
FLASK_CORS_ORIGINS = "*" # Comma-separated list of allowed origins (e.g., "http://localhost:3000,https://yourfrontend.com")
# --- Flask-SocketIO Configuration ---
SOCKETIO_CORS_ORIGINS = "*" # Comma-separated list of allowed origins for SocketIO
SOCKETIO_ASYNC_MODE = "threading" # Can be 'eventlet', 'gevent', 'threading'
SOCKETIO_PING_TIMEOUT = 60 # seconds
SOCKETIO_PING_INTERVAL = 25 # seconds
SOCKETIO_MAX_HTTP_BUFFER_SIZE = 1048576 # 1MB (bytes)
# --- Session Management ---
SESSION_INACTIVITY_TIMEOUT_SECONDS = 3600 # 1 hour
SESSION_CLEANUP_INTERVAL_SECONDS = 600 # 10 minutes
MURF_STREAM_CHUNK_SIZE = 4096 # Chunk size for streaming audio from Murf
# --- Input/Output Configuration ---
# Supported input methods
SUPPORTED_INPUT_METHODS = ["voice", "text"]
DEFAULT_INPUT_METHOD = "voice"
# Text input settings
TEXT_INPUT_MAX_LENGTH = 1000 # Maximum characters for text input
TEXT_INPUT_RATE_LIMIT = 10 # Maximum text requests per minute per session
# Audio input settings
AUDIO_INPUT_MAX_DURATION = 300 # Maximum audio duration in seconds (5 minutes)
AUDIO_INPUT_SUPPORTED_FORMATS = ["wav", "mp3", "webm", "ogg"]
# --- Environment-based Configuration Override ---
def get_config_value(key: str, default: Any = None, config_type: type = str) -> Any:
"""
Get configuration value with environment variable override support.
Args:
key (str): Configuration key name
default (Any): Default value if not found
config_type (type): Type to convert the value to
Returns:
Any: Configuration value
"""
# Check environment variable first
env_value = os.getenv(key)
if env_value is not None:
if config_type == bool:
return env_value.lower() in ('true', '1', 'yes', 'on')
elif config_type == int:
return int(env_value)
elif config_type == float:
return float(env_value)
else:
return env_value
# Use default from this config file
return default
# --- Configuration Dictionary for Easy Access ---
CONFIG = {
# Application
"APP_NAME": APP_NAME,
"APP_VERSION": APP_VERSION,
"APP_DESCRIPTION": APP_DESCRIPTION,
# Murf API
"MURF_BASE_URL": MURF_BASE_URL,
"MURF_STREAM_URL": MURF_STREAM_URL,
"MURF_DEFAULT_VOICE_ID": MURF_DEFAULT_VOICE_ID,
"MURF_DEFAULT_SPEED": MURF_DEFAULT_SPEED,
"MURF_DEFAULT_PITCH": MURF_DEFAULT_PITCH,
"MURF_DEFAULT_VOLUME": MURF_DEFAULT_VOLUME,
"MURF_DEFAULT_AUDIO_FORMAT": MURF_DEFAULT_AUDIO_FORMAT,
"MURF_DEFAULT_SAMPLE_RATE": MURF_DEFAULT_SAMPLE_RATE,
"MURF_REQUEST_TIMEOUT": MURF_REQUEST_TIMEOUT,
"MURF_MAX_RETRIES": MURF_MAX_RETRIES,
"MURF_RETRY_DELAY_BASE": MURF_RETRY_DELAY_BASE,
# Azure GPT LLM
"AZURE_GPT_ENDPOINT": AZURE_GPT_ENDPOINT,
"AZURE_GPT_MODEL": AZURE_GPT_MODEL,
"LLM_MAX_TOKENS": LLM_MAX_TOKENS,
"LLM_TEMPERATURE": LLM_TEMPERATURE,
"LLM_TOP_P": LLM_TOP_P,
"LLM_FREQUENCY_PENALTY": LLM_FREQUENCY_PENALTY,
"LLM_PRESENCE_PENALTY": LLM_PRESENCE_PENALTY,
"LLM_STOP_SEQUENCES": LLM_STOP_SEQUENCES,
"LLM_REQUEST_TIMEOUT": LLM_REQUEST_TIMEOUT,
"LLM_MAX_RETRIES": LLM_MAX_RETRIES,
"LLM_RETRY_DELAY_BASE": LLM_RETRY_DELAY_BASE,
"LLM_MAX_HISTORY_LENGTH": LLM_MAX_HISTORY_LENGTH,
"LLM_MAX_TOKENS_PER_CONTEXT": LLM_MAX_TOKENS_PER_CONTEXT,
# OpenAI Whisper STT
"WHISPER_ENDPOINT": WHISPER_ENDPOINT,
"WHISPER_MODEL": WHISPER_MODEL,
"WHISPER_LANGUAGE": WHISPER_LANGUAGE,
"WHISPER_RESPONSE_FORMAT": WHISPER_RESPONSE_FORMAT,
"WHISPER_TEMPERATURE": WHISPER_TEMPERATURE,
"WHISPER_REQUEST_TIMEOUT": WHISPER_REQUEST_TIMEOUT,
"WHISPER_MAX_RETRIES": WHISPER_MAX_RETRIES,
"WHISPER_RETRY_DELAY_BASE": WHISPER_RETRY_DELAY_BASE,
"WHISPER_MAX_FILE_SIZE": WHISPER_MAX_FILE_SIZE,
"WHISPER_SUPPORTED_FORMATS": WHISPER_SUPPORTED_FORMATS,
# Flask
"FLASK_SECRET_KEY": FLASK_SECRET_KEY,
"FLASK_DEBUG": FLASK_DEBUG,
"FLASK_HOST": FLASK_HOST,
"FLASK_PORT": FLASK_PORT,
"FLASK_CORS_ORIGINS": FLASK_CORS_ORIGINS,
# SocketIO
"SOCKETIO_CORS_ORIGINS": SOCKETIO_CORS_ORIGINS,
"SOCKETIO_ASYNC_MODE": SOCKETIO_ASYNC_MODE,
"SOCKETIO_PING_TIMEOUT": SOCKETIO_PING_TIMEOUT,
"SOCKETIO_PING_INTERVAL": SOCKETIO_PING_INTERVAL,
"SOCKETIO_MAX_HTTP_BUFFER_SIZE": SOCKETIO_MAX_HTTP_BUFFER_SIZE,
# Session Management
"SESSION_INACTIVITY_TIMEOUT_SECONDS": SESSION_INACTIVITY_TIMEOUT_SECONDS,
"SESSION_CLEANUP_INTERVAL_SECONDS": SESSION_CLEANUP_INTERVAL_SECONDS,
"MURF_STREAM_CHUNK_SIZE": MURF_STREAM_CHUNK_SIZE,
# Input/Output
"SUPPORTED_INPUT_METHODS": SUPPORTED_INPUT_METHODS,
"DEFAULT_INPUT_METHOD": DEFAULT_INPUT_METHOD,
"TEXT_INPUT_MAX_LENGTH": TEXT_INPUT_MAX_LENGTH,
"TEXT_INPUT_RATE_LIMIT": TEXT_INPUT_RATE_LIMIT,
"AUDIO_INPUT_MAX_DURATION": AUDIO_INPUT_MAX_DURATION,
"AUDIO_INPUT_SUPPORTED_FORMATS": AUDIO_INPUT_SUPPORTED_FORMATS,
}
def get_config() -> Dict[str, Any]:
"""
Get the complete configuration dictionary with environment variable overrides.
Returns:
Dict[str, Any]: Complete configuration dictionary
"""
# Apply environment variable overrides
config_copy = CONFIG.copy()
# Override with environment variables if they exist
for key, default_value in config_copy.items():
config_copy[key] = get_config_value(key, default_value, type(default_value))
return config_copy