From c7fa024dc5fdb6b9d4691ebc2377995f85d67822 Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Tue, 19 Aug 2025 12:11:25 -0600 Subject: [PATCH] better handling for env var --- .github/workflows/test_04.abstract_base.yml | 13 +++++++++++++ .../meta_llama_foundation_model.py | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test_04.abstract_base.yml b/.github/workflows/test_04.abstract_base.yml index bc1103c10..728f80bf0 100644 --- a/.github/workflows/test_04.abstract_base.yml +++ b/.github/workflows/test_04.abstract_base.yml @@ -47,6 +47,19 @@ jobs: shell: bash run: pip install -r ${{ github.workspace }}/requirements.txt + - name: 'ensure HF_TOKEN' + shell: bash + run: | + echo "HF_TOKEN length: ${#HF_TOKEN}" + if [ -z "$HF_TOKEN" ]; then + echo "ERROR: HF_TOKEN is empty or not set" + exit 1 + else + echo "HF_TOKEN is set (first 10 chars): ${HF_TOKEN:0:10}..." + fi + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + - name: 'run text generation tests - ${{ inputs.model_display_name }} - range ${{ inputs.range_name }} batch ${{ matrix.batch }}' shell: bash env: diff --git a/src/text_generation/adapters/foundation_models/meta_llama_foundation_model.py b/src/text_generation/adapters/foundation_models/meta_llama_foundation_model.py index d1066f046..1da2ad816 100644 --- a/src/text_generation/adapters/foundation_models/meta_llama_foundation_model.py +++ b/src/text_generation/adapters/foundation_models/meta_llama_foundation_model.py @@ -7,7 +7,15 @@ from src.text_generation.common.model_id import ModelId from huggingface_hub import login if "HF_TOKEN" in os.environ: - login(token=os.environ["HF_TOKEN"]) + hf_token = os.environ.get("HF_TOKEN", "").strip() + if not hf_token: + raise ValueError("HF_TOKEN environment variable is empty or not found") + + try: + login(token=hf_token) + print("Successfully authenticated with Hugging Face") + except Exception as e: + raise ValueError(f"Failed to authenticate with Hugging Face: {e}") else: raise ValueError("HF_TOKEN environment variable not found")