84 lines
3.6 KiB
Python
84 lines
3.6 KiB
Python
import yaml
|
|
|
|
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,
|
|
'analytics_tracking_code': '',
|
|
'average_generation_time_mode': 'database',
|
|
'info_html': None,
|
|
'show_total_output_tokens': True,
|
|
'simultaneous_requests_per_ip': 3,
|
|
'show_backend_info': True,
|
|
'max_new_tokens': 500,
|
|
'manual_model_name': False,
|
|
'enable_streaming': True,
|
|
'enable_openi_compatible_backend': True,
|
|
'openai_api_key': None,
|
|
'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.\nLines that start with "### ASSISTANT" were messages you sent previously.\nLines that start with "### USER" were messages sent by the user you are chatting with.\nYou will respond to the "### RESPONSE:" prompt as the assistant and follow the instructions given by the user.\n\n""",
|
|
'http_host': None,
|
|
'admin_token': None,
|
|
'openai_epose_our_model': False,
|
|
'openai_force_no_hashes': True,
|
|
'include_system_tokens_in_stats': True,
|
|
'openai_moderation_scan_last_n': 5,
|
|
'openai_org_name': 'OpenAI',
|
|
'openai_silent_trim': False,
|
|
'openai_moderation_enabled': True,
|
|
'netdata_root': None,
|
|
'show_backends': True,
|
|
'background_homepage_cacher': True,
|
|
'openai_moderation_timeout': 5,
|
|
'prioritize_by_size': False
|
|
}
|
|
config_required_vars = ['cluster', 'frontend_api_mode', 'llm_middleware_name']
|
|
|
|
mode_ui_names = {
|
|
'ooba': ('Text Gen WebUI (ooba)', 'Blocking API url', 'Streaming API url'),
|
|
'vllm': ('Text Gen WebUI (ooba)', 'Blocking API url', 'Streaming API url'),
|
|
}
|
|
|
|
|
|
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
|