2023-08-21 21:28:52 -06:00
import yaml
2023-08-23 22:08:10 -06:00
config_default_vars = {
' log_prompts ' : False ,
' database_path ' : ' ./proxy-server.db ' ,
' auth_required ' : False ,
' frontend_api_client ' : ' ' ,
' verify_ssl ' : True ,
' load_num_prompts ' : False ,
' show_num_prompts ' : True ,
' show_uptime ' : True ,
2023-08-23 23:27:33 -06:00
' analytics_tracking_code ' : ' ' ,
2023-08-24 16:47:14 -06:00
' average_generation_time_mode ' : ' database ' ,
2023-08-24 17:55:55 -06:00
' info_html ' : None ,
2023-08-24 20:43:11 -06:00
' show_total_output_tokens ' : True ,
2023-09-11 20:47:19 -06:00
' simultaneous_requests_per_ip ' : 3 ,
2023-08-29 13:46:41 -06:00
' show_backend_info ' : True ,
2023-09-12 10:30:45 -06:00
' max_new_tokens ' : 500 ,
2023-09-12 16:40:09 -06:00
' manual_model_name ' : False ,
2023-09-14 14:05:50 -06:00
' enable_streaming ' : True ,
2023-09-12 16:40:09 -06:00
' enable_openi_compatible_backend ' : True ,
2023-09-14 15:07:17 -06:00
' openai_api_key ' : None ,
2023-09-13 20:25:56 -06:00
' expose_openai_system_prompt ' : True ,
' openai_system_prompt ' : """ You are an assistant chatbot. Your main function is to provide accurate and helpful responses to the user ' s queries. You should always be polite, respectful, and patient. You should not provide any personal opinions or advice unless specifically asked by the user. You should not make any assumptions about the user ' s knowledge or abilities. You should always strive to provide clear and concise answers. If you do not understand a user ' s query, ask for clarification. If you cannot provide an answer, apologize and suggest the user seek help elsewhere. \n Lines that start with " ### ASSISTANT " were messages you sent previously. \n Lines that start with " ### USER " were messages sent by the user you are chatting with. \n You will respond to the " ### RESPONSE: " prompt as the assistant and follow the instructions given by the user. \n \n """ ,
2023-09-23 23:24:08 -06:00
' http_host ' : None ,
2023-09-24 15:54:35 -06:00
' admin_token ' : None ,
2023-09-25 09:32:23 -06:00
' openai_epose_our_model ' : False ,
2023-09-25 22:01:57 -06:00
' openai_force_no_hashes ' : True ,
2023-09-26 22:09:11 -06:00
' include_system_tokens_in_stats ' : True ,
' openai_moderation_scan_last_n ' : 5 ,
' openai_org_name ' : ' OpenAI ' ,
' openai_silent_trim ' : False ,
2023-09-27 19:39:04 -06:00
' openai_moderation_enabled ' : True ,
2023-09-29 00:09:44 -06:00
' netdata_root ' : None ,
' show_backends ' : True ,
2023-10-03 13:40:08 -06:00
' background_homepage_cacher ' : True ,
2023-10-04 10:19:44 -06:00
' openai_moderation_timeout ' : 5 ,
' prioritize_by_size ' : False
2023-08-23 22:08:10 -06:00
}
2023-10-03 13:47:18 -06:00
config_required_vars = [ ' cluster ' , ' frontend_api_mode ' , ' llm_middleware_name ' ]
2023-08-23 23:11:12 -06:00
mode_ui_names = {
2023-10-03 13:40:08 -06:00
' ooba ' : ( ' Text Gen WebUI (ooba) ' , ' Blocking API url ' , ' Streaming API url ' ) ,
2023-09-12 01:10:58 -06:00
' vllm ' : ( ' Text Gen WebUI (ooba) ' , ' Blocking API url ' , ' Streaming API url ' ) ,
2023-08-23 23:11:12 -06:00
}
2023-08-23 22:08:10 -06:00
2023-08-21 21:28:52 -06:00
class ConfigLoader :
"""
default_vars = { " var1 " : " default1 " , " var2 " : " default2 " }
required_vars = [ " var1 " , " var3 " ]
config_loader = ConfigLoader ( " config.yaml " , default_vars , required_vars )
config = config_loader . load_config ( )
"""
def __init__ ( self , config_file , default_vars = None , required_vars = None ) :
self . config_file = config_file
self . default_vars = default_vars if default_vars else { }
self . required_vars = required_vars if required_vars else [ ]
self . config = { }
def load_config ( self ) - > ( bool , str | None , str | None ) :
with open ( self . config_file , ' r ' ) as stream :
try :
self . config = yaml . safe_load ( stream )
except yaml . YAMLError as exc :
return False , None , exc
if self . config is None :
# Handle empty file
self . config = { }
# Set default variables if they are not present in the config file
for var , default_value in self . default_vars . items ( ) :
if var not in self . config :
self . config [ var ] = default_value
# Check if required variables are present in the config file
for var in self . required_vars :
if var not in self . config :
return False , None , f ' Required variable " { var } " is missing from the config file '
return True , self . config , None