|
|
| 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")
|
|
|
|
|
| pass
|
|
|
|
|
| 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",
|
| ]
|
|
|
| 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}")
|
|
|