personal-coder-ai / test_hf_api.py
Loomis Green
Switch to Dolphin Llama 3.2 1B (Uncensored)
c84a20e
import requests
import time
# The URL of your Hugging Face Space
API_URL = "https://loomisgitarrist-personal-coder-ai.hf.space"
def test_api():
print(f"Testing API at: {API_URL}")
# 0. Reset Memory (Ensure clean state)
print("0. Resetting Memory...")
try:
reset_response = requests.get(f"{API_URL}/reset", timeout=10)
if reset_response.status_code == 200:
print("βœ… Memory Reset Successful")
else:
print(f"⚠️ Memory Reset Failed: {reset_response.status_code}")
except Exception as e:
print(f"⚠️ Memory Reset Error: {e}")
# 1. Check UI
print("\n1. Checking UI availability...")
try:
ui_response = requests.get(API_URL, timeout=10)
if ui_response.status_code == 200 and "<html" in ui_response.text.lower():
print("βœ… UI is Live and serving HTML!")
else:
print(f"❌ UI check failed: Status {ui_response.status_code}")
except Exception as e:
print(f"❌ UI check error: {e}")
# 2. Check API & Memory
endpoint = f"{API_URL}/ask"
print(f"\n2. Testing API & Memory at: {endpoint}")
# Step A: Establish Context
prompt1 = "My name is Captain Loomis."
print(f"Step A: Sending prompt: '{prompt1}'...")
try:
response1 = requests.get(endpoint, params={"prompt": prompt1}, timeout=30)
if response1.status_code == 200:
print(f"βœ… Response 1: {response1.json()['generated_text']}")
else:
print(f"❌ Error 1: {response1.status_code} - {response1.text}")
return
except Exception as e:
print(f"❌ Error: {e}")
return
# Step B: Test Memory
prompt2 = "What is my name?"
print(f"\nStep B: Sending prompt: '{prompt2}' (Checking memory)...")
try:
response2 = requests.get(endpoint, params={"prompt": prompt2}, timeout=30)
if response2.status_code == 200:
answer = response2.json()['generated_text']
print(f"βœ… Response 2: {answer}")
if "Loomis" in answer:
print("\nπŸŽ‰ SUCCESS: The AI remembered your name!")
else:
print("\n⚠️ WARNING: The AI might have forgotten. Memory check inconclusive.")
else:
print(f"❌ Error 2: {response2.status_code} - {response2.text}")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
test_api()