import os import json from openai import OpenAI # 1. Environment variables exactly as required API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1") MODEL_NAME = os.getenv("MODEL_NAME", "gpt-3.5-turbo") HF_TOKEN = os.getenv("HF_TOKEN") LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME") # Optional per checklist # 2. OpenAI client configured via variables client = OpenAI( base_url=API_BASE_URL, api_key=HF_TOKEN ) def run_datacenter_agent(input_data): # 3. MUST BE THE VERY FIRST PRINT print("START") try: # Every single action must start with "STEP: " print("STEP: Agent initialized. Parsing datacenter metrics...") print(f"STEP: Input metrics received: {json.dumps(input_data)}") print(f"STEP: Connecting to LLM ({MODEL_NAME}) for cooling optimization analysis...") # Replace this prompt with your actual Hackathon prompt/logic response = client.chat.completions.create( model=MODEL_NAME, messages=[ {"role": "system", "content": "You are a Datacenter Cooling AI. Analyze the metrics and suggest optimal fan speeds and temperature adjustments. Return ONLY concise adjustments."}, {"role": "user", "content": str(input_data)} ] ) agent_result = response.choices[0].message.content print(f"STEP: LLM Analysis complete. Proposed adjustments: {agent_result}") print("STEP: Applying cooling adjustments to simulated environment...") # (Insert any math or final logic here) except Exception as e: print(f"STEP: ERROR ENCOUNTERED - {str(e)}") finally: # 4. MUST BE THE VERY LAST PRINT print("END") if __name__ == "__main__": # The evaluator will execute this file directly. # This dummy data is just so the script runs without crashing if executed manually. dummy_input = { "server_load_cpu": 85, "server_load_gpu": 92, "ambient_temp_celsius": 34.5, "humidity_percent": 45 } run_datacenter_agent(dummy_input)