| |
| """ |
| Debug script to test HuggingFace Inference API directly |
| """ |
|
|
| import os |
| import sys |
| from huggingface_hub import InferenceClient |
| import traceback |
|
|
| def test_model(model_name, prompt="Hello, how are you?"): |
| """Test a specific model with the HuggingFace Inference API""" |
| print(f"\nπ Testing model: {model_name}") |
| print("=" * 50) |
| |
| try: |
| |
| client = InferenceClient(model=model_name) |
| print(f"β
Client initialized successfully") |
| |
| |
| print(f"π Testing prompt: '{prompt}'") |
| |
| |
| try: |
| print("\n㪠Method 1: Full parameters") |
| response = client.text_generation( |
| prompt=prompt, |
| max_new_tokens=50, |
| temperature=0.7, |
| top_p=0.95, |
| return_full_text=False, |
| stop=["Human:", "System:"] |
| ) |
| print(f"β
Success: {response}") |
| return True |
| |
| except Exception as e: |
| print(f"β Method 1 failed: {e}") |
| print(f"Error type: {type(e).__name__}") |
| |
| |
| try: |
| print("\n㪠Method 2: Minimal parameters") |
| response = client.text_generation( |
| prompt=prompt, |
| max_new_tokens=50, |
| temperature=0.7, |
| return_full_text=False |
| ) |
| print(f"β
Success: {response}") |
| return True |
| |
| except Exception as e: |
| print(f"β Method 2 failed: {e}") |
| print(f"Error type: {type(e).__name__}") |
| |
| |
| try: |
| print("\n㪠Method 3: Basic parameters") |
| response = client.text_generation( |
| prompt=prompt, |
| max_new_tokens=30 |
| ) |
| print(f"β
Success: {response}") |
| return True |
| |
| except Exception as e: |
| print(f"β Method 3 failed: {e}") |
| print(f"Error type: {type(e).__name__}") |
| print(f"Full traceback:") |
| traceback.print_exc() |
| |
| return False |
| |
| except Exception as e: |
| print(f"β Failed to initialize client: {e}") |
| print(f"Error type: {type(e).__name__}") |
| traceback.print_exc() |
| return False |
|
|
| def test_model_info(model_name): |
| """Test getting model information""" |
| try: |
| print(f"\nπ Getting model info for: {model_name}") |
| client = InferenceClient() |
| |
| print("β
Model appears to be accessible") |
| return True |
| except Exception as e: |
| print(f"β Model info failed: {e}") |
| return False |
|
|
| if __name__ == "__main__": |
| |
| hf_token = os.environ.get("HF_TOKEN") |
| if hf_token: |
| print(f"π Using HF_TOKEN: {hf_token[:10]}...") |
| else: |
| print("β οΈ No HF_TOKEN found, using anonymous access") |
| |
| |
| models_to_test = [ |
| "unsloth/DeepSeek-R1-0528-Qwen3-8B-GGUF", |
| "microsoft/DialoGPT-medium", |
| "meta-llama/Llama-2-7b-chat-hf", |
| "HuggingFaceH4/zephyr-7b-beta" |
| ] |
| |
| results = {} |
| |
| for model in models_to_test: |
| print(f"\n{'='*60}") |
| test_result = test_model(model) |
| results[model] = test_result |
| |
| |
| info_result = test_model_info(model) |
| |
| print(f"\nResult for {model}: {'β
WORKING' if test_result else 'β FAILED'}") |
| |
| print(f"\n{'='*60}") |
| print("SUMMARY:") |
| print("="*60) |
| for model, result in results.items(): |
| status = "β
WORKING" if result else "β FAILED" |
| print(f"{model}: {status}") |
|
|