Spaces:
Sleeping
Sleeping
OpenEnv Contributor commited on
Commit ·
61cca39
1
Parent(s): c24afa3
fix: make HF_TOKEN optional at startup, validate at runtime for Space compatibility
Browse files41 unmodified lines42434445464748495051525354555657123 unmodified lines18118218318418518641 unmodified lines# Using Hugging Face Inference API for Qwen2.5-3B-InstructAPI_BASE_URL = os.getenv("API_BASE_URL", "https://api-inference.huggingface.co/v1")MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-3B-Instruct")HF_TOKEN = os.getenv("HF_TOKEN")# Validate required token per hackathon requirementsif HF_TOKEN is None:raise ValueError("HF_TOKEN environment variable is required")# Initialize OpenAI client with Hugging Face Inference APIclient = OpenAI(base_url=API_BASE_URL,api_key=HF_TOKEN)# Memory pressure settings (Mechanic #6)123 unmodified linesReturns the raw response content."""# Adaptive temperature: increase slightly on retries to get different outputs# Lower baseline temp (0.5) for 3B model to be more deterministicadaptive_temp = min(0.9, temperature + (retry_count * 0.15))41 unmodified lines424344454647484950515253123 unmodified lines17717817918018118218318418518618718818919019119219341 unmodified lines# Using Hugging Face Inference API for Qwen2.5-3B-InstructAPI_BASE_URL = os.getenv("API_BASE_URL", "https://api-inference.huggingface.co/v1")MODEL_NAME = os.getenv("MODEL_NAME", "Qwen/Qwen2.5-3B-Instruct")HF_TOKEN = os.getenv("HF_TOKEN", "")# Initialize OpenAI client (HF_TOKEN will be validated at runtime for actual API calls)client = OpenAI(base_url=API_BASE_URL,api_key=HF_TOKEN or "placeholder" # Allow Space to start, validate at runtime)# Memory pressure settings (Mechanic #6)123 unmodified linesReturns the raw response content."""# Validate HF_TOKEN at runtime (required per hackathon guidelines)if not HF_TOKEN:error_msg = "HF_TOKEN environment variable is required for inference"sys.stderr.write(f"[ERROR] {error_msg}\n")sys.stderr.flush()return json.dumps({"thought": error_msg,"tool": "aws.soc.get_alerts","args": {}})# Adaptive temperature: increase slightly on retries to get different outputs# Lower baseline temp (0.5) for 3B model to be more deterministicadaptive_temp = min(0.9, temperature + (retry_count * 0.15))
inference.py+14-7