Download test_handler.py from Mir-2002/codet5p-google-style-docstrings: direct link, hf CLI and curl.
- Browser
- Download file 939 Bytes
-
https://huggingface.co/Mir-2002/codet5p-google-style-docstrings/resolve/main/test_handler.py
- Command line
-
hf download hf://Mir-2002/codet5p-google-style-docstrings/test_handler.py
-
curl -L -o test_handler.py https://huggingface.co/Mir-2002/codet5p-google-style-docstrings/resolve/main/test_handler.py
939 Bytes
| import json | |
| from handler import EndpointHandler | |
| # Instantiate the handler with a dummy model_dir (replace with actual path if needed) | |
| # Since we are testing the handler logic and not loading a real model here, | |
| # we can initialize it with a placeholder. If your __init__ requires a valid path, | |
| # you might need to adjust this or mock the AutoTokenizer and AutoModelForSeq2SeqLM calls. | |
| # For a basic test of the __call__ method's structure, this might suffice. | |
| # If model loading is essential for your test, you'll need to handle that. | |
| handler = EndpointHandler(model_dir=".") | |
| # Example function without a docstring | |
| def multiply(a, b): | |
| return a * b | |
| # Prepare the data in the expected format for the handler | |
| test_data = {"inputs": ["def multiply(a, b):\n return a * b"]} | |
| # Call the handler | |
| try: | |
| response = handler(test_data) | |
| print(json.dumps(response, indent=2)) | |
| except Exception as e: | |
| print(f"An error occurred: {e}") | |