Spaces:
Sleeping
Sleeping
File size: 2,260 Bytes
3702f2a |
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 65 66 67 68 |
import requests
import json
BASE_URL = "http://localhost:8000"
API_KEY = "C0TNRcI8EuhmXpRTNiNsGbUHWBG6KFQt" # Replace with a valid API key
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}" # Use Bearer token authentication
}
def test_chat_completions_non_stream():
url = f"{BASE_URL}/v1/chat/completions"
payload = {
"model": "meta-llama-405b-turbo",
"messages": [
{"role": "user", "content": "Hello, how are you?"},
],
}
print("Chat Completions Non Streaming Response:")
response = requests.post(url, headers=headers, json=payload)
print(json.dumps(response.json(), indent=2))
print("\n")
def test_chat_completions_stream():
url = f"{BASE_URL}/v1/chat/completions"
payload = {
"model": "meta-llama-405b-turbo",
"messages": [
{"role": "user", "content": "Hello, how are you?"},
],
"stream": True,
}
print("Chat Completions Streaming Response:")
response = requests.post(url, headers=headers, json=payload, stream=True)
for chunk in response.iter_lines():
if chunk:
print(chunk.decode("utf-8").replace("data: ", "").strip(), end="\n", flush=True)
print("\n")
def test_rate_limit_status():
url = f"{BASE_URL}/rate_limit/status" # Updated endpoint
response = requests.get(url, headers=headers)
print("Rate Limit Status Response:")
print(json.dumps(response.json(), indent=2))
print("\n")
def test_subscription_status():
url = f"{BASE_URL}/subscription/status" # Updated endpoint
response = requests.get(url, headers=headers)
print("Subscription Status Response:")
print(json.dumps(response.json(), indent=2))
print("\n")
def test_available_models():
url = f"{BASE_URL}/models" # Updated endpoint
response = requests.get(url, headers=headers)
print("Available Models Response:")
print(json.dumps(response.json(), indent=2))
print("\n")
if __name__ == "__main__":
test_chat_completions_non_stream()
test_chat_completions_stream()
test_rate_limit_status()
test_subscription_status()
test_available_models() |