File size: 1,726 Bytes
8c686ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Standalone inference script for Hugging Face Qwen 2.5 7B."""

import os
import sys

def main():
    # You can set your token via env var: export HF_TOKEN="hf_..."
    hf_token = os.environ.get("HF_TOKEN") or os.environ.get("LLM_API_KEY")
    if not hf_token:
        print("Error: Please set the HF_TOKEN environment variable.")
        sys.exit(1)

    try:
        from huggingface_hub import InferenceClient
    except ImportError:
        print("Error: huggingface_hub is not installed. Run `uv pip install huggingface_hub`")
        sys.exit(1)

    model_id = "Qwen/Qwen2.5-7B-Instruct"
    print(f"Initializing InferenceClient for {model_id}...")
    
    client = InferenceClient(model=model_id, token=hf_token)

    prompt = """
OBSERVATION:
The alien universe has 4 sensors: pressure, turbulence, thermal_radiation, magnetic_flux.
t=0: pressure=0.5, turbulence=0.2

Please provide a JSON DSL theory that explains this data.
"""

    messages = [
        {"role": "system", "content": "You are a scientific discovery agent. Output ONLY valid JSON containing the Theory DSL."},
        {"role": "user", "content": prompt}
    ]

    print("Querying model... (This may take a moment on Serverless API)")
    try:
        response = client.chat_completion(
            messages=messages,
            max_tokens=512,
            temperature=0.2
        )
        content = response.choices[0].message.content
        print("\n--- Model Output ---")
        print(content)
        print("--------------------")
    except Exception as e:
        print(f"\nInference failed: {e}")
        print("Note: The model might be loading into memory on HF servers, try again in 1 minute.")

if __name__ == "__main__":
    main()