plutoV2_miniProject_3rd-yr / mp1 /test_hf_token.py
3v324v23's picture
Add application file
66ad25b
raw
history blame contribute delete
711 Bytes
import os
from pathlib import Path
import pytest
import requests
from dotenv import load_dotenv
load_dotenv(Path(__file__).resolve().with_name(".env"))
pytestmark = pytest.mark.live_api
def test_hf():
token = os.getenv("HUGGINGFACE_TOKEN")
if not token:
pytest.skip("HUGGINGFACE_TOKEN not configured")
model_id = "meta-llama/Llama-3.1-8B-Instruct"
response = requests.post(
f"https://api-inference.huggingface.co/models/{model_id}",
headers={"Authorization": f"Bearer {token}"},
json={
"inputs": "Hello",
"parameters": {"max_new_tokens": 10},
},
timeout=30,
)
assert response.status_code == 200, response.text