Spaces:
Sleeping
Sleeping
File size: 911 Bytes
b832e97 | 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 | import json
import os
from pathlib import Path
import requests
BASE_URL = os.getenv("INSTRUCTION_API_URL", "http://localhost:7860").rstrip("/")
headers = {}
if os.getenv("API_KEY"):
headers["X-API-Key"] = os.environ["API_KEY"]
payload = json.loads(Path(__file__).with_name("example_request.json").read_text(encoding="utf-8"))
for endpoint in ["/health", "/model"]:
response = requests.get(f"{BASE_URL}{endpoint}", timeout=30)
print(endpoint, response.status_code)
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
response.raise_for_status()
response = requests.post(f"{BASE_URL}/generate", json=payload, headers=headers, timeout=360)
print("/generate", response.status_code)
print(json.dumps(response.json(), indent=2, ensure_ascii=False))
response.raise_for_status()
assert 1 <= len(response.json()["output"]["instructions"]) <= 5
print("Instruction API test passed.")
|