Spaces:
Sleeping
Sleeping
π§ Fix: Missing Environment Variables Error
Problem
Your inference.py is failing because it can't find these environment variables:
API_BASE_URL- URL to your LLM APIMODEL_NAME- Model identifierHF_TOKEN- Hugging Face authentication token
Solution
Step 1: Create/Edit the .env file
A .env file has been created in your project root. Edit it with your actual credentials:
# Open .env in your editor and fill in:
API_BASE_URL=https://api.together.xyz/v1 # Your LLM API endpoint
MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct # Model you want to use
HF_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxx # Your HF token from https://huggingface.co/settings/tokens
Step 2: Verify Your Setup
Run the verification script to check if everything is configured:
python verify_env.py
Expected output:
β
.env file found
β
API_BASE_URL: https://api.together.xyz/v1
β
MODEL_NAME: meta-llama/...
β
HF_TOKEN: hf_xxxx...xxxxx
β
All dependencies installed
β
All checks passed! Ready to run inference.py
Step 3: Run Inference
Once verification passes, run your inference:
python inference.py
Environment Variable Options
API_BASE_URL (choose one):
Option 1: Together AI (Recommended for hackathons)
API_BASE_URL=https://api.together.xyz/v1
- Free tier available
- Sign up at: https://api.together.xyz
Option 2: Hugging Face Inference
API_BASE_URL=https://api-inference.huggingface.co/v1
- Use your HF token for authentication
- Limited free tier
Option 3: Local vLLM Server (Advanced)
API_BASE_URL=http://localhost:8000/v1
- Requires running vLLM locally
- Best for development
MODEL_NAME (examples):
meta-llama/Llama-3.1-8B-Instructβ Recommendedmeta-llama/Llama-3.2-70B-Instruct(more powerful)mistralai/Mistral-7B-Instruct-v0.3NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO
HF_TOKEN:
- Go to https://huggingface.co/settings/tokens
- Click "New token"
- Select "Read" permission
- Copy the token and paste in
.env
Common Issues
β "curl: (6) Could not resolve host"
- Check your
API_BASE_URLis correct and accessible - Test:
curl {API_BASE_URL}/models
β "401 Unauthorized" or "invalid_api_key"
- Your
HF_TOKENis wrong or expired - Generate a new token at https://huggingface.co/settings/tokens
β "Model not found"
- Check your
MODEL_NAMEmatches the provider's available models - Visit the provider's documentation
How It Works
After the changes made to inference.py:
- The script automatically loads variables from
.envfile (if exists) - Then it checks for required environment variables
- If any are missing, it shows a helpful error message
- If all are set, it proceeds with inference
This means you can:
- Use
.envfile (checked automatically) - Export variables manually:
export API_BASE_URL=... - Mix both approaches (manual exports override
.env)
Quick Commands (PowerShell)
# Edit .env file
code .env
# Verify environment
python verify_env.py
# Run inference (after .env is filled in)
python inference.py
Next Steps for Phase 2
- β
Fill in
.envwith your credentials - β
Run
python verify_env.pyto confirm setup - β
Run
python inference.pyto complete phase 2 - β
Check
inference_results.txtfor logs an results