File size: 2,028 Bytes
1f7ead8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
63
64

import requests
import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from backend.app.config import config

def explore():
    print("Exploring Endpoints for GPT2...")
    model = "gpt2"
    token = config.HUGGINGFACE_API_KEY
    headers = {"Authorization": f"Bearer {token}"}
    
    urls = [
        "https://api-inference.huggingface.co/models/gpt2",
        "https://router.huggingface.co/models/gpt2",
        "https://router.huggingface.co/gpt2",
        "https://router.huggingface.co/v1/models/gpt2",
        "https://router.huggingface.co/hf-inference/models/gpt2"
    ]
    
    for url in urls:
        print(f"Testing {url}...")
        try:
            resp = requests.post(url, headers=headers, json={"inputs": "Hello"})
            print(f"Code: {resp.status_code}")
            print(f"Text: {resp.text[:100]}")
        except Exception as e:
            print(f"Error: {e}")
            with open("verify.log", "a") as f:
                f.write(f"Error: {e}\n")
    
    # Capture print output hack
    pass

# Helper to write to log
def log(msg):
    print(msg)
    with open("verify.log", "a") as f:
        f.write(msg + "\n")

if __name__ == "__main__":
    with open("verify.log", "w") as f:
        f.write("Exploring...\n")
    
    model = "gpt2"
    token = config.HUGGINGFACE_API_KEY
    headers = {"Authorization": f"Bearer {token}"}
    
    urls = [
        "https://router.huggingface.co/hf-inference/models/gpt2",
        "https://router.huggingface.co/hf-inference/v1/models/gpt2",
        "https://router.huggingface.co/v1/models/gpt2/chat/completions", # OpenAI style?
    ]
    
    for url in urls:
        log(f"Testing {url}...")
        try:
            resp = requests.post(url, headers=headers, json={"inputs": "Hello"})
            log(f"Code: {resp.status_code}")
            log(f"Text: {resp.text}")
        except Exception as e:
            log(f"Error: {e}")