diff --git a/app.py b/app.py index d0d4d14..9033bb9 100644 --- a/app.py +++ b/app.py @@ -132,6 +132,35 @@ def get_client_for_model(model_name: str): def get_openai_client_and_model( model_name="adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic", ): + """Get OpenAI client and model name. + + Supports MODEL_X references (e.g., MODEL_1, MODEL_2, MODEL_3) that map to + environment variables MODEL_ENDPOINT_X and MODEL_API_KEY_X. + """ + # Handle MODEL_X references + if model_name and model_name.startswith("MODEL_"): + try: + model_num = model_name.split("_")[1] + endpoint_key = f"MODEL_ENDPOINT_{model_num}" + api_key_key = f"MODEL_API_KEY_{model_num}" + model_name_key = f"MODEL_NAME_{model_num}" + + endpoint = os.environ.get(endpoint_key) + api_key = os.environ.get(api_key_key) + + if endpoint and api_key: + client = get_client_for_endpoint(endpoint, api_key) + # Get the actual model name from environment, or use sensible default + actual_model = os.environ.get(model_name_key, "model") + return client, actual_model + else: + print(f"Warning: MODEL_{model_num} not configured ({endpoint_key} or {api_key_key} missing)") + # Fall back to default model + model_name = "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic" + except Exception as e: + print(f"Warning: Failed to load {model_name}: {e}, falling back to default") + model_name = "adamo1139/Hermes-3-Llama-3.1-8B-FP8-Dynamic" + return get_client_for_model(model_name), model_name