|
|
@ -45,17 +45,23 @@ class ModelFactory: |
|
|
|
|
|
|
|
|
# Resolving Env Vars for Keys |
|
|
# Resolving Env Vars for Keys |
|
|
api_key_env = provider_data.get('api_key') |
|
|
api_key_env = provider_data.get('api_key') |
|
|
if api_key_env and api_key_env.startswith("${"): |
|
|
|
|
|
|
|
|
if api_key_env and api_key_env.startswith("${") and api_key_env.endswith("}"): |
|
|
api_key = os.getenv(api_key_env[2:-1]) |
|
|
api_key = os.getenv(api_key_env[2:-1]) |
|
|
else: |
|
|
else: |
|
|
api_key = api_key_env |
|
|
api_key = api_key_env |
|
|
|
|
|
|
|
|
base_url_env = provider_data.get('base_url') |
|
|
base_url_env = provider_data.get('base_url') |
|
|
if base_url_env and base_url_env.startswith("${"): |
|
|
|
|
|
|
|
|
if base_url_env and base_url_env.startswith("${") and base_url_env.endswith("}"): |
|
|
base_url = os.getenv(base_url_env[2:-1]) |
|
|
base_url = os.getenv(base_url_env[2:-1]) |
|
|
else: |
|
|
else: |
|
|
base_url = base_url_env |
|
|
base_url = base_url_env |
|
|
|
|
|
|
|
|
|
|
|
# Fallbacks if environment variables are not set |
|
|
|
|
|
if not api_key: |
|
|
|
|
|
api_key = os.getenv("NEW_HORIZON_API_KEY") or os.getenv("OPENAI_API_KEY", "hZwAGW4H8v87Ol8tXvqEEY") |
|
|
|
|
|
if not base_url: |
|
|
|
|
|
base_url = os.getenv("NEW_HORIZON_BASE_URL") or os.getenv("API_URL", "http://ai.newhorizonco.uk/v1") |
|
|
|
|
|
|
|
|
# 3. Instantiate the correct Class |
|
|
# 3. Instantiate the correct Class |
|
|
if provider_name == 'openai_like': |
|
|
if provider_name == 'openai_like': |
|
|
return OpenAILike( |
|
|
return OpenAILike( |
|
|
@ -65,8 +71,7 @@ class ModelFactory: |
|
|
max_tokens=model_config_data.get('max_tokens', 4096), |
|
|
max_tokens=model_config_data.get('max_tokens', 4096), |
|
|
collect_metrics_on_completion=True, |
|
|
collect_metrics_on_completion=True, |
|
|
default_headers={ |
|
|
default_headers={ |
|
|
"Authorization": f"Bearer {api_key}", |
|
|
|
|
|
"Content-Type": "application/json" |
|
|
|
|
|
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" |
|
|
}, |
|
|
}, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|