CoolFace
Apppublic

Rohannk/datacenter-openenv

sourceHugging Facemitupdated 6mo agoView on Hugging Face
1likes
inference.py59 linesDownload Raw Back to root
1import os2import json3from openai import OpenAI4 5# 1. Environment variables exactly as required6API_BASE_URL = os.getenv("API_BASE_URL", "https://api.openai.com/v1") 7MODEL_NAME = os.getenv("MODEL_NAME", "gpt-3.5-turbo")8HF_TOKEN = os.getenv("HF_TOKEN")9LOCAL_IMAGE_NAME = os.getenv("LOCAL_IMAGE_NAME") # Optional per checklist10 11# 2. OpenAI client configured via variables12client = OpenAI(13    base_url=API_BASE_URL,14    api_key=HF_TOKEN15)16 17def run_datacenter_agent(input_data):18    # 3. MUST BE THE VERY FIRST PRINT19    print("START")20    21    try:22        # Every single action must start with "STEP: "23        print("STEP: Agent initialized. Parsing datacenter metrics...")24        print(f"STEP: Input metrics received: {json.dumps(input_data)}")25        26        print(f"STEP: Connecting to LLM ({MODEL_NAME}) for cooling optimization analysis...")27        28        # Replace this prompt with your actual Hackathon prompt/logic29        response = client.chat.completions.create(30            model=MODEL_NAME,31            messages=[32                {"role": "system", "content": "You are a Datacenter Cooling AI. Analyze the metrics and suggest optimal fan speeds and temperature adjustments. Return ONLY concise adjustments."},33                {"role": "user", "content": str(input_data)}34            ]35        )36        37        agent_result = response.choices[0].message.content38        print(f"STEP: LLM Analysis complete. Proposed adjustments: {agent_result}")39        40        print("STEP: Applying cooling adjustments to simulated environment...")41        # (Insert any math or final logic here)42        43    except Exception as e:44        print(f"STEP: ERROR ENCOUNTERED - {str(e)}")45        46    finally:47        # 4. MUST BE THE VERY LAST PRINT48        print("END")49 50if __name__ == "__main__":51    # The evaluator will execute this file directly. 52    # This dummy data is just so the script runs without crashing if executed manually.53    dummy_input = {54        "server_load_cpu": 85,55        "server_load_gpu": 92,56        "ambient_temp_celsius": 34.5,57        "humidity_percent": 4558    }59    run_datacenter_agent(dummy_input)