| import sys | |
| import os | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) | |
| from huggingface_hub import InferenceClient | |
| from backend.app.config import config | |
| def verify_url_client(): | |
| print("Verifying Client with Full URL...") | |
| # Construct the Direct Inference URL manually | |
| # Note: 'messages' API might not work on this raw endpoint if it expects 'inputs' string. | |
| # Text Generation endpoint usually expects 'inputs'. | |
| model_url = f"https://api-inference.huggingface.co/models/{config.LLM_MODEL}" | |
| print(f"Target: {model_url}") | |
| try: | |
| client = InferenceClient(model=model_url, token=config.HUGGINGFACE_API_KEY) | |
| res = client.text_generation("Hello", max_new_tokens=10) | |
| print("Success!") | |
| print(res) | |
| except Exception as e: | |
| print(f"Failed: {e}") | |
| if __name__ == "__main__": | |
| verify_url_client() | |